Good habits for game development

Started by
34 comments, last by Serapth 11 years, 2 months ago

Something from writing/fixing others code :

If there is some parameter flags that cause variations of behavior of a subroutine - clearly comment this at the parameter definition and down in the code where trhe different modes take action. (Im not talking about simple subroutines but ones hundreds and thousands of lines long that it may not be productive to have a variant copy customized for each 'mode'.)

Especially if the scope of the differences cause odd side-effects or have important limitations.

Document those (if not anything else) becase of the amount of the time/effort it takes to trace thru the code again to figure out what it does and once you find it (as when fixing other peoples poorly documemnted/commented code) it can save the effort or repeating the detailed logic tracing.

Anything with weird/atypical/convoluted behavior should get priority for comments if there is little time for any done systematically (its just a fact in the real world that you dont always have the resources to do a full commenting/documentation).

----

And when I make many such comments I make them very plainly stand out so that its hard to miss (indicating that the codes behavior is something to be wary of)

--------------------------------------------[size="1"]Ratings are Opinion, not Fact
Advertisement

Some general things, most of them independent of coding style:

- Have realistic and well defined goals that are clearly communicated to members on your team

- Scope it down: your game idea is probably too damn big. Polish takes time, things get cut, features don't exist in a bubble (unless the project fails that is).

- Iteration time is everything: Fail early and fail often, prototype mechanics, and be prepared to cut something you invested a considerable amount of time in

- Knowledge is power: profile your code, run tools that check for leaks, crank up compiler warnings, and use static analysis tools if possible

- Interfaces are king: A well designed one is the root of a clear, maintainable, and productive workflow for others. A poor one will cut into iteration time.

- Understand that hard problems will inevitably contain immensely complex code: elegant systems rarely survive contact with real users

- Embrace time estimates and embrace making time estimates that might be completely wrong. Do this over and over and over again.

- "Self Documenting Code" is probably only documented to you

- It's (usually) not done until it's data driven

<shameless blog plug>
A Floating Point
</shameless blog plug>

[quote name='wodinoneeye' timestamp='1358779996' post='5023907']


If there is some parameter flags that cause variations of behavior of a subroutine - clearly comment this at the parameter definition and down in the code where trhe different modes take action. (Im not talking about simple subroutines but ones hundreds and thousands of lines long that it may not be productive to have a cariant copy customized for each 'mode'.)
[/quote]

I'm going to agree here, on the caveat that youl should avoid writing this kind of code as often as possible in the first place. Sometimes it's unavoidable, but it's a code smell that should be minimized. A function should ideally do one thing. It's not really one of those lofty architecture astronaut ideals 99% of the time either.

Incredibly helpful thread!

Here's my tip... define your goals ahead of time, both for yourself and for the project. If you're doing it to learn then take every chance to learn. Try out new approaches to various coding problems even if you're already comfortable of some other way of doing something. Having more tools at your disposal for the future is what learning is all about.

On the other hand, if your primary goal is to create an awesome game and to hell with everything beyond it, then do the opposite of the above. If you know a way to solve a problem, don't worry about whether or not its the best way or even necessarily a good way, provided it works and it does the job you wish it to do.

In reality, most projects are going to be somewhere between those two extremes. Learn how to balance the benefits of taking time out of your project to learn something new versus just powering through with what you have understanding that there might be better ways of doing things out there but knowingly declining them for now.

I'm working on a game! It's called "Spellbook Tactics". I'd love it if you checked it out, offered some feedback, etc. I am very excited about my progress thus far and confident about future progress as well!

http://infinityelephant.wordpress.com

For games, especially if you are designing, you are much less an engineer and much more a sculptor, constantly pushing and pulling things around, removing unneeded bits and adding extra bits. Plan for things to change,

  1. Get a playable version as fast as possible. Even if it all gets thrown away.
    • Prototyping is a design step, a pre-production step.
    • Its going to help in planning and identifying what really needs to be implemented.
  2. Design up front just enough to get a good idea of what you really need.
  3. Implement the minimal amount.
  4. Schedule the minimal amount.
  5. Art and sound and nice assets can wait. Make things work first.

And the last thing is my personal law for programming. It might sound stupid but it helps in about a million ways.

  • Never write a function longer than 50 lines (including white space and comments). Decompose. make it fit on a single page.

Even when you are the single developer of a project write code as if it is intended for other people to use. You will be the other people when you look back at your code in 6 months time.

Side note:

For C++, I'd recommend reading C++ Coding Standards by Sutter and Alexandrescu. The table of contents
by itself is helpful, but the full book contains discussion like
reasoning and exceptions to the general rules. The only problem is that
it predates C++11.

I like this quote on the amazon link: "Short is better than long: Huge coding standards tend to be
ignored; short ones get read and used. Long Items tend to be skimmed;
short ones get read and used."

And then you release a 240 page counting book as a coding standards that's a brilliant way of contradicting yourself :)

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

And in general, what I should consider for become a better game developer and make better games?

Finish what you start ... when you start a game, finish it.

This leads to a natural corollary, Don't start things that are too big for you to finish.

To add to the "too big for you to finish, " I hope your big project reuses code structure from previous projects to increase familiarity and speed to finish.

"Oh, God, I'm nervous. Two of my three hearts are having attacks." -Zoidberg
Site: http://www.strangeturtle.com

the free online repository site I'm using has a built-in issue tracker

Which free online repository site are you using?

Didn't want to sound like I was advertising, nor stir up a Git vs. Hg firestorm, so I didn't name names, but I suppose there's no harm in saying Bitbucket. Github probably has similar features, but the deciding factor for me was Bitbucket's unlimited free account for those with a .edu email address. As a broke grad student, I couldn't turn that down.

Just to add to this for the benefit of other people reading this thread, I use unfuddle,com for source control on my personal projects. It allows totally free svn repositories to anyone but with the free account you can't have multiple users on projects. I don't know if they provide source control using software besides subversion.

The git wiki has a page listing free git hosting sites. Unfuddle does appear on the list.

Stick to a singleton if you need something like a global.

Sorry, but if you've been using singleton's "instead of" globals then you have still been using globals during the past 8 years. A singleton isn't better than a global just because it's wrapped up in a fancy class, and using a singleton because "you need something like a global" is a terrible reason to use the pattern. You should use a singleton if you need a singleton; that is:

  • If there must only ever be one instance created. Note that this is different from only wanting or needing one instance -- if you only want or only need one instance then don't bother with additional code to enforce it and instead only create one -- the singleton is appropriate when it would be an error for there to be more than one instance.
  • If you need global access.

Unless you need both of those requirements the singleton is not the right pattern for your situation, and it's exceedingly rare to genuinely require that there must only be a single instance.

There is one other bullet:

- deferred allocation.

I also dont think single instance classes are all that rare. Of course you could design around the requirement.

It is also worth pointing out a few pro's about singletons. First off, the most nasty evil horrible stuff about singletons is mostly only applicable to C++. Singletons in Java or C# are nowhere near the landmine they are in C++.

Second, they are easy to grok. That's why you see them in use in a number of very successful game libraries. They may not make for the purest design, but they make for one that is generally easily comprehended. This is why you see singletons used in Moai, Cocos2D, Ogre3D, PlayStation Mobile, etc... etc... etc...

This topic is closed to new replies.

Advertisement