The Exceptional Beauty of Doom 3’s Source Code

http://kotaku.com/5975610/the-exceptional-beauty-of-doom-3s-source-code?tag=kotaku-longreads

Very interesting article for programmers

John Carmack himself replied to the article :open_mouth:

And effectively said that he himself doesn’t consider Doom’s source code that exemplary.

NEEEEEEEEEEEEEERRRRRRRRRRRRRRRRRRRD !!!

Said the pot to the kettle.

The author takes license with OOH I’VE CODED 10 YEARS! and void foo() { is better than sticking { on it’s own line! He does meander into self gratification, but to be expected by a programmer talking exclusively about code!

I’ve programmed for 30 years. That’s probably longer or the same as Carmack. Does that mean anything? Not really… it means yes I’ve understood tolerance for programmer style and no, if you’re not coding well after 2 years you’ll probably not advance much. But experience will help you the rest of the way.

The argument about screen space doesn’t wash, it’s a boring and useless comment. He also chides Carmack for commenting too much? Try coming back the code in a few years or working in a team environment instead of being the sole programmer, and you will change your mind about condensing code too much (or too little) and the worth of a few good comments above the function.

Ultimately, it was interesting to read a fellow programmer’s thoughts on the source, not so interesting being dictated to about style.

p.s

I don’t consider myself a great programmer, just a creative and experienced one. There are 14 year old kids who run rings around me :slight_smile:

good read. i disagree about the vertical spaces, because IMO, that’s easier to read more cleanly defined “chunks.” It was cool to see Carmack comment in the article too!

yep, I love my chunks and I prefer a larger monitor than skimping on them. I only over-comment because I know I won’t remember what things are doing in a week and because I have this nagging feeling that someone will at some point read my code and it will make no sense. Of course when I had to share a project so a team could finish another 20 projects using my template, I asked if things made sense and the feedback was good, I never got a question on how or what something did, so there’s that. It’s also something I do when I’m thinking about the next step, I just go in and clean up things until I’m ready to move forward.

I too did’nt agree with the vertical space thing and i do “chunks” too . In the days of code folding capable IDE’s vertical space is plenty…

Seperate chunks and vertical spacing FTW!

This Carmack guy doesn’t know what he’s talking about :smile:

Carmack has his own category when it comes to programming and he is brighter than 95% of the world’s programmers. What works for him will most certainly not give good results for everyone :slight_smile:

Jimi hendrix famously played his guitars upside down. Does that mean everyone else should? Frankly, the number of times I’ve seen people struggling to learn code and fail because they don’t appreciate indenting and { is on the same line is staggering. It should stop getting pushed in people’s faces, its retarded behaviour akin to trying force open source onto everyone. Some tolerance will go a long way.

There is a point when nitpicking your syntax just becomes a waste of time.If it works and is efficient then you should just leave it alone.

Is the top one the good one or the bottom???

The author said the top one is better because of lesser vertical spacing. Reason, the following code might reflect what have been written before, so with less vertical spacing you can have a much larger overview of the whole code within the limited size of your computer screen hence it’s less confusing than the bottom example.

I don’t spend time thinking about coding-styles. I just let reshaper do the formatting afterwards. :wink:

If his code is a beautiful and majestic unicorn, my ugly ass US code must be like a deformed angler fish with face skin disease by comparison.

Seriously, my code is so offensively ugly, I feel like I should warn people NSFW and put a link to it whenever posting.

I’m not sure Carmack even considered how the code looks on screens of limited size, the few times I’ve seen footage of him talking in front of his workstation he was using a huge display with a huge resolution. It’s more likely just a stylistic preference than an actual concern for screen space.

Personally I find grouping relevant pieces of code in paragraphs and dropping braces onto new lines is easier to read than an unbroken wall of text. Grouping helps me see what lines are related to each other and when the code moves on to something else, e.g. when working with mesh generation I would group lines related to vertices together and have a blank line before code related to triangles, or going deeper I might group code related to vertex position together then code related to normals then code related to UVs. Having braces on new lines helps instantly see where a code block begins and where it ends which is especially helpful when working with lots of nested loops and conditionals.

Sorry but I was referring to the author of the article, Shawn McGrath. Not the author of the code.

Eh , my personal preference is to keep classes as short as possible , and call other classes when need be .

Of course this isn’t always possible , but

( the article author ) .
WTF . Even if you call in some outside help, what can he do !? I guess when your the ONLY programmer on your team( and you like to not be able to isolate problems ) thats cool . Then again I’m not an engine programmer …

Sure, but it’s not just about aesthetics, there’s plenty of functional design in there as well. Making things as const as possible, keeping things to a single and clear purpose, and self-documenting code are, as far as I’m aware, not things that tools can post-fix for you. And even if they can, is that actually a good idea?