Best practice question

Nibbie
Posts: 3
Joined: 2010.10
Post: #1
I am programming a text based RPG in python 2.6.
I was wondering about what the best practice would be to hold my player/character stats.
Should I use a dictionary within the class or class variables.
I have everything currently implemented as class variables but is this going to create a problem later? What would the best practice for this situation be and why?
What are the more experienced devs opinions on this type of implementation.
Sorry for the noobishness of this post, I am very new to programming.

Thanks!Smile
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
The best practice is to use whatever's easiest until it's not easiest any more, then change. Your program's not set in stone.
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2010.10
Post: #3
(Oct 1, 2010 08:38 PM)OneSadCookie Wrote:  The best practice is to use whatever's easiest until it's not easiest any more, then change. Your program's not set in stone.

Yes, but it is precisely the “not easy anymore” part that I'm worried about. Are there any pitfalls that you know of to using one method over another? At this point it is 6 of one and 1/2 a dozen of the other. Both are pretty easy. But is there a smarter choice? I'm finding that asking myself; "Can I do a thing?" Is not as momentous
as;"Should I do it?"
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
There's no point in worrying about the future. You can't design for requirements you haven't discovered yet. Your program's not set in stone, there's no need to change it now. Later will be just fine.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #5
I think the point that OneSadCookie is trying to make is that it's a very common problem to over-engineer problems. If you sit around trying to think of every complication that might come up or every feature that you might want to add in the future, you spend all your time thinking and none of it coding. Worse still, there will always be problems that you didn't see coming until you actually have coded something or that killer feature that you spent so much time planning around may be lame or just never get completed.

Don't be afraid to throw code away or rewrite it when it didn't work the way you wanted. You can find and solve problems faster this way than if you sat around trying to think of everything first. This is also the best way to gain the experience that you are asking for. Reading other people's code helps with this too, as you don't have to spend a lot of time coding to see what works well and what doesn't.

A good rule of thumb for programming is always KISS (keep it simple, stupid). If an using an XML file is sufficient, don't use a database. If using 10 lines of code and a plain text file is fine, don't use an XML file.

Going back to your original question, both options sound pretty much the same really and I'm not enough of a Python guy to say that there are any obvious pitfalls or annoyances. Just go whichever is easiest or most familiar until you find a reason to think otherwise. Maybe one way will allow you to save to a file using a single library function. Though you won't really know until you get far enough to try.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2010.10
Post: #6
Sweet, thanks everyone!
Quote this message in a reply
Post Reply