| |
|
|
||||
![]() |
||||||
| |
|
|||||
|
What
Your Mother Never Told You Game
programming, because of its history, has an image that no longer fits
with the reality of the job. The popular view of game programmers, at
least in nerdy circles, is of a bunch of code cowboys coding six impossible
things before breakfast, spending most of their time worrying about how
to squeeze those last few cycles out of that inner loop. Micro-optimization
and glorious hacks are still very important in some areas of the job,
but, as can be witnessed by the ill fate of some recent high-profile projects,
the biggest challenge is actually getting the damn game shipped. The successful
companies are those that have adapted, and have strategies for getting
the projects done. The Importance of Naming "Are
the identifiers in the code clear and fitting?" is a useful rule
of thumb for determining whether the code I'm writing is going to be maintainable.
Since the compiler ignores the names when it generates the final machine
code, it's common for naming to be seen as a cosmetic detail. However,
I believe the quality of the names is a good indicator of how well thought
out the code's design was. Fundamentally, you should be able to describe
to someone else precisely what your code does, or you might as well have
written it in binary machine code. If you can't describe what it does,
then neither you nor anyone else will be able to work with it in the future,
which leaves it useless. If you can describe it, then the best way to
keep that description for future need is to bake it into the code, by
using clear, meaningful identifiers. Fat Classes, Fat Functions Classes
packed with members and functions packed with variables both worry me,
for pretty much the same reason; nobody ever designs one of these crawling
horrors, they just happen. Usually things were added to them a little
bit at a time as short-term hacks to get something working, often under
pressure to get a feature or bug fixed for a deadline. Once in, they never
get removed, other changes to the code start to rely on them being there,
and ultimately people take a more relaxed view of hacking the code around
some more, since it's a mess already. When You've Got
a Shiny New Hammer, Every Problem When I learn
about a new feature, I naturally find lots of places in the code I'm writing
where it could come in handy. The problem is, having little experience
with the new feature, I'll inevitably end up using it where it will cause
problems further down the line. Trying to debug an object whose inheritance
tree looks like a cat's cradle is not fun, exceptions can be equally obscure
unless used with care, and working out how templates work on different
type parameters can be nearly impossible. Another consideration is whether
the next person to work with the code will understand the feature you're
using. When you definitely need them, inheritance et al. are lifesavers,
but they come with costs too, and can be used to obscure the code far
more easily than to make it clearer. A good coding standard will help,
but thinking, "Can I use a simpler way?" rather than, "Can
I use <feature> here?" is most of the battle. ________________________________________________________
|
||||||||||||||||
|
|