The woes of a software engineer (Warning: Technical rant thread)

I rarely rant about other programmers’ code; partly because I know for one I am not a stellar programmer, and for two, I couldn’t write code on computer graphics or advance algorithms like path-finding, so I know my place within the tier of the arcane arts of programming and don’t comment much on others’ code.

What I am good at (or maybe just skilled at) is infrastructure; the organisation of code. I like neat code; I think I know what neat code looks like, so I am always in the job of making other people’s code modular and generic.

Enough of the introduction. So right now I am looking at a piece of code that could petrify Medusa, make Cyclops wince, bring down the wrath of Zeus and sour the love of Athena. I don’t even know where to begin. I just keep going “ARRGH” every 5 minutes when I look at the spaghetti code that is on my plate (how do you manage to get that type of code in C++!?)

A sprite consists of an animation; an animation consists of many frames. I layered this way for my sanity, and passed it to the level 99 CG programmer to do his magic. He’s way better than me; I ought to treat him with respect, but I almost got a panic attack when I saw his code. Make it whenever I saw his code

(Disclaimer: His code works, in a sense that you get pretty results on the screen).

So I have to refactor it such that is generic. And here are my woes…

  1. In changing the position of an entity, he changed the position of the animation, not the sprite. I forgot which rule of object oriented programming he broke, but all I know is that this is broken.

  2. When drawing the content of a frame, he offset each vertice in glVertice3f instead of using a translate. Cough blood It just broke something, I don’t know what it is exactly now.

  3. The sudden inclusion of several dozen public variables into all the classes…

  4. and he just directly bypass encapsulation to access them!! In the main update loop, he would access a public property of a frame and change it so that the visuals would work…

  5. Variable names that quicken my pulse. pivotX vs. pviotOrgX and no comments to indicate what is the difference.

He had taken a modular structure and make it so tightly coupled that I am at loss - either I refactor the entire monster by hacking at it for a week or I write replacement classes so that I can do some smaller unit tests, which would amount to a week anyway. Face palm

On the good side, if I manage to untangle his code and get it to work, I would learn some valuable CG programming techniques…

ETA: I think my internal circuit are fried too. May a moderator please invoke his almighty administrator power and move it to MPSIMS? I’m sorry, I am really sorry. But bad code really broke my concentration on all other things too.

It’s not like C++ makes it hard to write shitty code. (Says the Perl programmer.)

Find some more interesting chunks and post them at The Daily WTF so others can share in your pain.

C# face palm I meant to say C#.

See how addled my brain is!?

Bad programmers can write C in any language.

I feel your pain !

at least the guy knows his stuff, i had to deal for years with someone who:

[ul]
[li]Wrote code that did not work[/li][li]had no respect/knowledge at all about OOP, Encapsulation, etc[/li][li]Loved spagethi code and used almost exclusively **global **variables:smack:[/li][li]had no interest at all in making code neat (one letter variable names! i see them in my dreams)[/li][li]Didnt know about “INNER JOIN” in sql so just used WHERE clauses to join multiple tables in her absolutely ugly querys[/li][li]querys that, by the way, accesed 25+ tables, using one letter aliases for each of them…, so you had A joins B joins C Joins…,…, Joins A1 (i kid you not!)[/li][/ul]

whew, it feels good to rant about it, i’l think about starting a pit thread to do a full catharsis.

Having done some openGL programming in the past, I suspect you may want to talk to him about some of the decisions he made. Most graphics programmers are all about raw speed, and so end up hacking together a lot of little tricks that incrementally improve the rendering loop by a millisecond here, a millisecond there… directly accessing a variable rather than invoking the overhead of a virtual function call is one of those tricks, I bet.

You should probably have a heart to heart with him to understand why he did those things. Refactoring for correctness, in this case, risks killing the performance of what the original programmer was trying to do. Maybe it doesn’t matter for what you’re writing, but it’s worth checking. And it may be worth refactoring anyway to see if his little pearls of cleverness really matter. Programmers are awful at figuring out where the performance bottlenecks in their code actually are.

There is not now, and there never will be, a programming language that makes it even slightly difficult to write bad code (original author forgotten).

Everything that can be said about bad programming is contained in The Story of Mel

You should have a talk with him anyway, to let him know what a pain in the ass his code is for anyone else. In fact, if at all possible, give it right back to him and make him do it correctly – if your boss knows how much they’re spending to have you fix his code, they’ll probably back you up.

He’s not going to change his style until he knows it’s a problem for others, and the problems he creates for others start becoming problems for him.