Slashdot Mirror


Doom 3 Source Code: Beautiful

jones_supa writes "Shawn McGrath, the creator of the PS3 psychedelic puzzle-racing game Dyad, takes another look at Doom 3 source code. Instead of the technical reviews of Fabien Sanglard, Shawn zooms in with emphasis purely on coding style. He gives his insights in lexical analysis, const and rigid parameters, amount of comments, spacing, templates and method names. There is also some thoughts about coming to C++ with C background and without it. Even John Carmack himself popped in to give a comment."

16 of 399 comments (clear)

  1. Beautiful code but by discord5 · · Score: 5, Funny
    • It might be beautiful code, but 90% of it just renders a black screen in a horribly inefficient way.
    • For best effect the source code should be read in the dark with a flashlight in your hand.
    • // TODO : add the code for the lightswitch in this class

    I'll be here all week.

    1. Re:Beautiful code but by IcyNeko · · Score: 5, Funny

      John Carmack: The Kanye West of Video Game Programming.

      "Imma let you finish your Dragonborn DLC in a minute, but DOOM 3 has the cleanest source code of all time. OF ALL TIME!"

    2. Re:Beautiful code but by Stormwatch · · Score: 5, Funny

      // TODO : rehire Romero, Petersen, Hall, McGee, Prince.

      There, fixed. The engine may be fantastic, but Doom 3 is a horrible game that can't hold a candle to the previous titles. Or at least it can't hold a candle and a gun at the same time.

    3. Re:Beautiful code but by Anonymous Coward · · Score: 5, Insightful

      I did. No issues. Hint: The dark parts are supposed to be dark.

    4. Re:Beautiful code but by Ash+Vince · · Score: 5, Interesting

      Daikatana and Alice were far from perfect, but they're still more enjoyable than Doom 3.

      I think you hit the nail on the head there, but possibly not in the way you mean.

      Doom3 was an absolute masterpiece of atmospheric gaming, but it was just too much. It set your nerves on edge in a way that meant playing for more than an hour or so was just too stressful. I love the levels, the monsters, the story (ok, its basic but what do you want from a FPS) but I just find playing it burns me out too quickly. It is just too good at making you feel uncomfortable and claustrophobic without any respite.

      I was just thinking back to Doom as I type this and from memory the big difference is that Doom had more variety with some levels set outside or in huge cavernous high ceilinged spaces. This variety is what made it great as it certainly had plenty of claustrophobia inducing levels too.

      --
      I dont read /. to RTFA, I read /. to offend people in ignorance.
  2. His Comment by phantomfive · · Score: 5, Informative
    Here is what John Carmack wrote:

    In some ways, I still think the Quake 3 code is cleaner, as a final evolution of my C style, rather than the first iteration of my C++ style, but it may be more of a factor of the smaller total line count, or the fact that I haven’t really looked at it in a decade. I do think "good C++" is better than "good C" from a readability standpoint, all other things being equal.

    I sort of meandered into C++ with Doom 3 – I was an experienced C programmer with OOP background from NeXT’s Objective-C, so I just started writing C++ without any proper study of usage and idiom. In retrospect, I very much wish I had read Effective C++ and some other material. A couple of the other programmers had prior C++ experience, but they mostly followed the stylistic choices I set.

    I mistrusted templates for many years, and still use them with restraint, but I eventually decided I liked strong typing more than I disliked weird code in headers. The debate on STL is still ongoing here at Id, and gets a little spirited. Back when Doom 3 was started, using STL was almost certainly not a good call, but reasonable arguments can be made for it today, even in games.

    I am a full const nazi nowadays, and I chide any programmer that doesn’t const every variable and parameter that can be.

    The major evolution that is still going on for me is towards a more functional programming style, which involves unlearning a lot of old habits, and backing away from some OOP directions.

    One might suggest that every good programmer, if they spend enough time improving, eventually moves toward a more functional programming style.

    --
    "First they came for the slanderers and i said nothing."
    1. Re:His Comment by girlintraining · · Score: 5, Insightful

      One might suggest that every good programmer, if they spend enough time improving, eventually moves toward a more functional programming style.

      Good programmers don't move towards any one style, they become familiar with all of them and use them when and where appropriate. Just like computer geeks. You find Linux one day, install it, then fall under the spell of believing this year will be the Year of the Linux Desktop. But after awhile, you reach the second plateau of understanding -- Linux is good for some things, but not everything. The third plateau is no longer caring which tool you use, as long as its the best tool for the job.

      --
      #fuckbeta #iamslashdot #dicemustdie
    2. Re:His Comment by meerling · · Score: 5, Funny

      Especially with the rising symptoms of Dementia and Alzheimers. :)

    3. Re:His Comment by Rhacman · · Score: 5, Insightful

      As I get older, I gain more experience and hence believe that my opinions carry more weight. Since me and my close knit group of similarly aged friends agree with me it stands to reason that what I have come to believe now is in fact correct and that others who disagree with me are simply immature.

      --
      Account -> Discussions -> Disable Sigs
    4. Re:His Comment by MobyDisk · · Score: 5, Funny

      Mom, I told you nobody mods you up until you register.

  3. Re:Not the best analysis by gbjbaanb · · Score: 5, Informative

    the concept of the bracket placement there is to emphasise indentation over bracketing. Once you "get" the view of it, it becomes a nice thing to look at, similar to python code.

    I don't use it nowadays (too many coding standards that are written for the bracketing-style) but I appreciated it when I did. There's nothing wrong with the style, so I hope that you pass any code you review written in this style and focus on the important parts like readability of the code, good naming, commenting and the like rather than subjective opinions.

  4. Comment-free programming by swillden · · Score: 5, Interesting

    I really liked this bit, because it's something I've been really focusing on for the last year or so, and I think it has significantly improved my code:

    Comments should be avoided whenever possible. Comments duplicate work when both writing and reading code. If you need to comment something to make it understandable it should probably be rewritten.

    Comments can be useful, IMO, but primarily only for generating documentation (think Javadoc or doxygen, etc.). Other exceptions include bits of code that perform highly-optimized mathematical calculations, in which case I think the best solution is to write a proper document and then add a comment linking to the document, and bits of code that do something which apparently could be done differently but for some other reason must not -- assuming that explanation doesn't belong in the doc-generating comments.

    Other than that, I find it makes my code a lot better if every time I find myself wanting to write a comment to explain some bit of code's purpose or operation, I instead refactor until the comment is no longer necessary. Often it's as simple as taking a chunk of code from one method/function and pulling it out into another with a well-chosen name, or else introducing a variable to hold an intermediate value in a calculation, with a well-chosen name. Sometimes the fact that a bit of code is hard to explain is a strong indicator that the design is wrong, that stuff is mashed together that shouldn't be.

    The bottom line is that I've found eliminating comments does more for improving the readability of my code than anything else, and I've gotten similar feedback from colleagues whose code I critique by pointing out that they can eliminate their comments if they refactor a bit.

    --
    Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  5. Most of His Admiration Is Not Technical by Greyfox · · Score: 5, Insightful
    Most of his admiration appears to be issues of code formatting and lack of comments, not the technical design of the code. He started to lose me even before his rants on the ugliness of STL and boost libraries. Do the objects play well together? Is it easy to assemble them to accomplish tasks in sensible ways and with as little set-up as possible on the part of the user of the library? These were not questions I saw answered.

    And a note on the relative evil of comments; bad or not, well placed comments have saved me an awful lot of time when taking on maintenance of code bases in the past. Most of the time they can't present a design document to you, or if they do it covers the design at the start of the project, a decade and a half earlier. Code is a method of communication between two programmers, but if the code doesn't suffice to illuminate the design the original programmer had in mind, I'd really appreciate a comment explaining his thoughts. Especially if the particular section of code is complex, and especially if I'm the guy writing it and end up being the guy maintaining it a couple years later.

    --

    I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

  6. Re:Solaris Code by phantomfive · · Score: 5, Interesting

    Write a review of Solaris code, and it'll probably get posted on Slashdot, too. I for one would be interested in reading that.

    --
    "First they came for the slanderers and i said nothing."
  7. Re:Else ifs - yuck by Anonymous Coward · · Score: 5, Informative

    Often as in you've measured it, or often as in "I'm making shit up"?

    A good compiler will never implement a case statement as a load of if-else's, unless the case values are sparse, or you're not optimizing.

    Meanwhile, transforming a set of if-else statements into a lookup table is seldom possible unless the if-elses all compare the same integer variable to a constant. In that case, it can in theory, but almost certainly won't in practice.

    Other things being equal, a switch statement with contiguous constant cases will almost always compile to faster code than the equivalent set of if-elses. And it will be far faster. Every if/else induces a branch, and mis-prediction will be severe on most of those branches, causing 10-20+ cycles of stall on modern processors. The jump table mispredicts almost always, but only once. If one arm is taken 99% of the time you can speed things up by using an if/else and then a switch, but that's a rare case.

    I appreciate the fact you're responding to the idiocy of the above post, but your points are as wrong as his.

  8. Re:Not the best analysis by Rhacman · · Score: 5, Insightful

    This is one of those topics of an almost religious fanatacism but I tend to agree. I want my braces to match in the same column and have an easier time looking at code with vertical spaces between blocks of related operations. Functions should still be short enough that they fit on a modern screen (with rare exceptions).

    The whole concept of self-documenting code irks me too. Too often programmers use it as an excuse for not writing comments at all. Of course the code should be written clearly enough to the point where you don't need the comments to understand how the code will execute, but I don't think you should count on that as showing what and why that block of related operations is doing what it does. Comments can certainly be overused and underused and while commenting every single line is absurd in most cases, not commenting under the umbrella of "self-documenting" code can be detrimental as well.

    --
    Account -> Discussions -> Disable Sigs