Re: [stella] OT: Programming, CS theory

Subject: Re: [stella] OT: Programming, CS theory
From: Greg Miller <gmiller@xxxxxxxxxxxxxxxxx>
Date: Thu, 25 Oct 2001 17:55:37 -0500
Kennehan, Richard wrote:

I have a CS degree, and I have found a great deal of difference between what
works "in theory", and what works in practice:

THEORY: Recursion is great!
PRACTICE: Recursion wastes memory and assumes that the compiler's garbage
collector is 100% flawless, which is rarely the case

What does garbage collection have to do with it? Stack usage and readability are real problems with recursion, though.

THEORY: Avoid the use of global variables, only use local variables!
PRACTICE: Using locals results in having to pass parameters by reference,
and uses more stack space, and results in more variable declarations, thus
increasing possibilities of incorrectly declared variables.  In fact, most
game programming books tell you to use globals and avoid locals!

Experience has taught me that the theorists are right, here. Excessively long parameter lists are a side-effect of other design problems, and globals tend to hurt performance and maintainability. Make sure, though, that you understand the difference between global data and module data.

THEORY: Never use GOTO statements!
PRACTICE: Avoiding GOTOs sometimes results in nested IF statements that are
200 lines long, which are a pain to debug

That really depends on the language you're using. Gotos make sense when the language you're using lacks a specific means of representing the code structures you need.

THEORY: Inheritance is great, make one change, and it cascades down to its
child members!
PRACTICE: Sometimes the child becomes so specialized its better off on its
own, and trying to "divorce" a child from its parents most often results in
the entire child object having to be re-created from scratch...and in actual
developmental practice, Inheritance is only marginally better than

Overuse of inheritance is a common beginner mistake, something those academic textbooks are beginning to do a solid job of emphasizing.

THEORY: You can combine several statements together, like for(++i;i<lseek(fp)) {i+=lseek(fp+i)};
PRACTICE: This makes it impossible for other programmers to decipher your
work, and causes the compiler to generate code which is not easily
digestible by the CPU's execution units. Most game programming books tell
you to program in a RISC-like manner to maximize the CPU instruction
execution pipelines

Combining statements rarely has any impact on a reasonable compiler, and it's usually not the CS people proposing these hideous constructs.

   There is no peaceful solution to organized terrorist networks.

- Archives (includes files) at Unsub & more at

Current Thread