1
Programming / Re: Newbie programming Q's
« on: June 19, 2012, 05:35:01 PM »...and that, ladies and gentlemen, is how a C programmer codes in C++.Code: [Select]oh god my eyes
If you were actually writing OO code, your weapons wouldn't just be distinguished by an enum, they'd be subclasses. If you find yourself writing massing switch statements, or massive if/else clauses, you're probably doing something 'wrong'. (semantics being what they are, you can take that to mean whatever you want)
Quote
without OO I would have to refer to a specific weapon w: "w->type", "w->size" and "w->color" instead of "type", "size" and "color"Er, to be honest, w->type is just as OO irrelevant as internally referencing variables...w->type() (with the inference of inheritence) would be the only way to actually imply OO-ness.
Also, reduce() is acting like a factory call for some reason? Hello over-complicated memory management -- you're just begging for memory leaks. Why can't a weapon reduce itself? And if you need both copies, clone() it first and then reduce one?
Also, why does your class type look like a variable name? And even when you have 1 line conditionals, it's still recommended to put {} around them. And to only have one return path from a function. And your spacing is horrible. And your code will cause an exception if size is negative. And...and...and...
Ship games. It's what's important. But sometimes do it with class.