Thread: I encourage everyone to have a glance over the Quake II source code

  1. #1
    Registered User
    Join Date
    Mar 2016
    Posts
    110

    I encourage everyone to have a glance over the Quake II source code

    Better yet, any source code that was released by ID software.

    You can find it all, here:

    https://github.com/id-Software/Quake-2

    It is so incredibly clean, elegant and pushes everything out of the C programming language including some Godlike pointer hacking and bit field manipulation. Function pointers and callbacks are made to look smooth.

    This is the work of the programming God John Carmack and his team Brian Hook and George Cash.

    The opinions are not new, this article outlines the beauty of Doom III's source code:
    The Exceptional Beauty of Doom 3's Source Code

    These guys were magicians and I aspire to be like them one day.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Sounds like a nightmare to me.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    My props to John Carmack and his team. And I like the fanboy in you, but this raises a question: If John is God, then what do you call Dennis Ritchie? Meta-God??

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,398
    I've looked over this code before. It's... eh... decent, I guess. There are plenty of tricks and hacks that make the code fast enough to pull off a really awesome video game -- and I don't dispute whatsoever that Quake II was an awesome game -- but it's hardly a shining example of clean, well-architected code.

    It got the job done and made Carmack and his coworkers a lot of money. That's all well and good for Carmack, but you're not Carmack. You should set your sights a little higher if you're looking for examples of well-designed code.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by brewbuck View Post
    but it's hardly a shining example of clean, well-architected code
    What code is?

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Yarin View Post
    What code is?
    Windows 2000
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,398
    Quote Originally Posted by Yarin View Post
    What code is?
    The source code of Clang.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  8. #8
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Angola
    Posts
    8,445
    Quote Originally Posted by brewbuck View Post
    The source code of Clang.
    That was funny. Now, an application that isn't obviously a C programming tool.

    I think you are being too hard on Mr. Carmack and the OP. From constraints in the development time to the mediocre skill level of a large portion of professional developers, it's always a reason to rejoice when we can find generally smart and clean production code that also respects best practices in such a complex language like C or C++.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  9. #9
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by Elkvis View Post
    I forgot how good this was. They really comment well.
    Code:
    // HACK ON TOP OF HACK ALERT
    A paragon of code quality if I don't say so myself.

  10. #10
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,398
    Quote Originally Posted by Mario F. View Post
    That was funny. Now, an application that isn't obviously a C programming tool.

    I think you are being too hard on Mr. Carmack and the OP. From constraints in the development time to the mediocre skill level of a large portion of professional developers, it's always a reason to rejoice when we can find generally smart and clean production code that also respects best practices in such a complex language like C or C++.
    I'm just not moved to tears by the use of a function pointer...

    My biggest problem with this code is the complete lack of tests. I mean, not a single test to be found anywhere. It also has "break" and "continue" statements all over the place. If it was code I was reviewing at work, I'd reject it for either of those reasons.

    Again, I'm not saying the code sucks, or Carmack is stupid, or anything like that. I just don't see anything super impressive here.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  11. #11
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by brewbuck View Post
    My biggest problem with this code is the complete lack of tests. I mean, not a single test to be found anywhere.
    It's possible that the tests were written separate from the main code base, or stripped out for production. Also, you have to consider the fact that this code was written circa 1997, when structured testing was not nearly as common, and most game testing was done by playing the game.

    Quote Originally Posted by brewbuck View Post
    It also has "break" and "continue" statements all over the place.
    I've never really understood why people think those two features are so bad. I've read all the explanations, but I just don't see the points made as being particularly negative.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  12. #12
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by Elkvis View Post
    I've never really understood why people think those two features are so bad. I've read all the explanations, but I just don't see the points made as being particularly negative.
    Discontinue break
    Break your continue abuse
    Or it's spaghetti

  13. #13
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Quote Originally Posted by brewbuck View Post
    The source code of Clang.
    Which means nothing, because Clang is nothing but a glorified debugger. Anyone who has tried to use Clang for "real" code, should know what I'm referring to, i.e. Clang producing ud2 instructions unnecessarily, without warning.

    Edit: RANT: anyone who tries to defend Clang here is automatically wrong. This has been an issue for over 3 years now, and has not been fixed.
    Last edited by Epy; 04-04-2016 at 02:53 PM.

  14. #14
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Angola
    Posts
    8,445
    Quote Originally Posted by Elkvis View Post
    I've never really understood why people think those two features are so bad. I've read all the explanations, but I just don't see the points made as being particularly negative.
    The issue is not with the keywords, which are useful. The criticism is all geared towards the logic. continue and break can be easily abused and usually reveal signs of a loop that is trying to do too many things or offering too many exit points. Whether this is bad or good depends entirely on the particular case of that loop, but the principle is the exact same for functions with multiple return statements; It's not a bad thing per se, unless it clearly violates the principles of structured programming.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  15. #15
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,398
    Quote Originally Posted by Epy View Post
    Which means nothing, because Clang is nothing but a glorified debugger. Anyone who has tried to use Clang for "real" code, should know what I'm referring to, i.e. Clang producing ud2 instructions unnecessarily, without warning.

    Edit: RANT: anyone who tries to defend Clang here is automatically wrong. This has been an issue for over 3 years now, and has not been fixed.
    Your pet frustration notwithstanding, clang is pretty much taking over everything now. Android and iOS are both compiled with it, and Microsoft is switching to it. Get over it, man.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual C++ .NET Quake 3 Source Port
    By bengreenwood in forum Game Programming
    Replies: 0
    Last Post: 03-16-2012, 08:02 PM
  2. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  3. Understanding something in Quake 2 Source Code
    By bengreenwood in forum C Programming
    Replies: 5
    Last Post: 08-05-2009, 02:22 PM
  4. Understanding a Line of Quake 2 Source Code
    By bengreenwood in forum C++ Programming
    Replies: 6
    Last Post: 08-04-2009, 03:15 PM
  5. Replies: 3
    Last Post: 05-08-2004, 10:58 AM