
Doom3 is the proof that “keep it simple” works - GeekandProud
http://www.gamedev.net/page/resources/_/technical/game-programming/doom3-is-the-proof-that-keep-it-simple-works-r4009
======
w23j
This comment by Carmack seems to imply that the restrained use of advanced C++
features was more by accident then by design:

 _I had C and Objective-C background, and I sort of "slid into C++" by just
looking at the code that the C++ guys were writing. In hindsight, I wish I had
budgeted the time to thoroughly research and explore the language before just
starting to use it.

You may still be able to tell that the renderer code was largely developed in
C, then sort of skinned into C++._

(Source:
[http://fabiensanglard.net/doom3/interviews.php](http://fabiensanglard.net/doom3/interviews.php))

~~~
xamuel
That doesn't necessarily imply that he's saying he should've used more
advanced features. It could just as well mean he should've understood better
the features he did use.

~~~
scott_s
Agreed - but the post implies all of the choices made were _mindful_ choices.
Carmack indicates that is not necessarily so.

------
chunkstuntman
Fabian Sanglard's exploration[1] of Doom3 is much more in depth than this
article, though the author does quote Sanglard's analysis albeit with a small
source link

[1]
[http://fabiensanglard.net/doom3_bfg/index.php](http://fabiensanglard.net/doom3_bfg/index.php)

~~~
morley
For what it's worth, that code review is for Doom 3 BFG. This is the review of
vanilla Doom 3:

[http://fabiensanglard.net/doom3/index.php](http://fabiensanglard.net/doom3/index.php)

The vanilla code review goes into the app structure first, and (what little
I've read of) the BFG review compares that codebase against the vanilla one.

------
RubyPinch
These adverts pretending to be learning experiences, really bother me

"CppDepend Tutorial" would be a better title

~~~
err4nt
You must be the target audience then because I read a great article about
Doom3 and have no clue what youre talking about. I also dont know what
CppDepend is...

~~~
RubyPinch
> Let's go inside its source code using CppDepend and discover what makes it
> so special.

And the article is written by the creators of CppDepends

~~~
err4nt
But as somebody with zero experience, I wasn't aware when reading that this
was a tool and not a part of the language itself. I read articles like these
because I have an interest and a lack of knowledge, and I'm learning all kinds
of things today.

I've been a longtime fan of Carmack, and I wish I could read and understand
his work for myself!

~~~
coldtea
> _But as somebody with zero experience, I wasn 't aware when reading that
> this was a tool and not a part of the language itself._

That's the very problem he tries to address I believe...

------
topkekz
[http://kotaku.com/5975610/the-exceptional-beauty-of-
doom-3s-...](http://kotaku.com/5975610/the-exceptional-beauty-of-
doom-3s-source-code)

Reply from Carmack himself: [http://kotaku.com/thanks-a-few-comments-in-some-
ways-i-still...](http://kotaku.com/thanks-a-few-comments-in-some-ways-i-still-
think-the-454293019)

------
Toine
[https://github.com/dhewm/dhewm3/blob/master/neo/game/Target....](https://github.com/dhewm/dhewm3/blob/master/neo/game/Target.cpp#L964)

This is the "nicest looking code [you] have ever seen" ?

~~~
toxicFork
What's wrong with this?

~~~
golergka
Over 150 lines of code in a simple method?

C-style declaration of all the variables in the beginning? (Yes, I know what
Carmack said about how he written the project; this explains it, but doesn't
make it good C++ code.)

Unclear flow with just one comment, which doesn't really explain anything?

~~~
Demiurge
Why do you say it's a simple method, if it is 150 lines long? Are some lines
not necessary?

There is a logic to keeping logic together if it is isolated: [http://number-
none.com/blow/john_carmack_on_inlined_code.htm...](http://number-
none.com/blow/john_carmack_on_inlined_code.html)

Context is important, to anyone developing D3 code, this code might be obvious
and comments would be unnecessary. Considering 'geterdone' attitude of many
game projects, with high levels hackery, this is very nice code.

~~~
golergka
Thanks for the link, it's a very fascinating read! By the way, I discussed
this issue on Programmers stack exchange a while back, you might find this
interesting:
[http://programmers.stackexchange.com/questions/277098/method...](http://programmers.stackexchange.com/questions/277098/method-
extraction-vs-underlying-assumptions)

------
melling
Lots of structs is how [http://handmadehero.org](http://handmadehero.org) is
being built.

"As we can observe many structs are defined, for example more than 40% of
DoomDLL types are structs. They are systematically used to define the data
model. This practice is adopted by many projects, this approach has a big
drawback in case of multithreaded applications. Indeed, structs with public
fields are not immutable."

------
frik
> Doom3 is the proof that “keep it simple” works

This statement suits even better to id Tech 3 (Quake 3). John Carmack
mentioned: _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 [Doom 3]_ :
[http://kotaku.com/thanks-a-few-comments-in-some-ways-i-
still...](http://kotaku.com/thanks-a-few-comments-in-some-ways-i-still-think-
the-454293019) and he linked to his blog post about "Functional Programming in
C++" on the now defunct but former popular AltDevBlog:
[https://web.archive.org/web/20130126164111/http://www.altdev...](https://web.archive.org/web/20130126164111/http://www.altdevblogaday.com/2012/04/26/functional-
programming-in-c)

The engine of Doom 3 (id Tech 4) was good. The game itself was repetitive and
a bit boring. It was a few months late Aug 2004, and Far Cry 1 (March 2004)
already overshadowed it in terms of graphics and gameplay.

Licensing the id-Engine to other companies was very successful during the id
Tech 2 (Quake 1/2) and id Tech 3 (Quake 3) era. Back then the Unreal engine
was only used in Unreal and Unreal Tournament '99, with Deus Ex as an early
adopter.

But few games were released starting with id Tech 4 (Doom 3) and later id Tech
5 (Rage). Compromises during the development of id Tech 4+ meant it wasn't
suitable for many different purposes. Only small levels with a few light
sources were possible - the later "mega texture" addition partly solved that
issue but meant a huge hardware step during development and prevented Mods and
custom maps. In retrospect the Unreal 3+ and CryEngine 1+ offered comparable
results without sacrifice their universalizability.
[http://en.wikipedia.org/wiki/Far_Cry_(video_game)](http://en.wikipedia.org/wiki/Far_Cry_\(video_game\))
, [http://en.wikipedia.org/wiki/Doom_3](http://en.wikipedia.org/wiki/Doom_3) ,
[http://en.wikipedia.org/wiki/Id_Tech_4](http://en.wikipedia.org/wiki/Id_Tech_4)

The Call of Duty franchise is still using modified Quake 3 engine heavily
extended with Ritual's ÜberTools, now named IW engine and comes with many
modern features like texture streaming. Half Life 1+2 are based on a heavily
modified Quake 1 engine.
[http://en.wikipedia.org/wiki/Quake_engine](http://en.wikipedia.org/wiki/Quake_engine)
, [http://upload.wikimedia.org/wikipedia/commons/6/63/Quake_-
_f...](http://upload.wikimedia.org/wikipedia/commons/6/63/Quake_-
_family_tree.svg) , [http://en.wikipedia.org/wiki/File:Quake_-
_family_tree_2.svg](http://en.wikipedia.org/wiki/File:Quake_-
_family_tree_2.svg) ,
[http://en.wikipedia.org/wiki/Heavy_Metal:_F.A.K.K.%C2%B2](http://en.wikipedia.org/wiki/Heavy_Metal:_F.A.K.K.%C2%B2)

All of these id tech engine games can be edited with the GtkRadiant map editor
(Half Life, Call of Duty, Quake 3, Doom 3, etc.):
[http://en.wikipedia.org/wiki/GtkRadiant](http://en.wikipedia.org/wiki/GtkRadiant)

~~~
scott_s
I was surprised to learn that CoD still uses something based on the Quake 3
engine. Any idea how much the engine has changed?

~~~
Crito
Yeah, in particular I'd be interested to know if CoD still uses Quake 3's VM
model.

------
CyberDildonics
I wonder what John Camack's current thoughts are on C++ design. I rarely use
inheritance and usually have either inlined functions or functions that
operate on arrays or many objects at a time. I also use templates when they
deal with straight type substitution (including functions). I am though
starting to get familiar with extern templates to be able keep compile times
down.

------
CyberDildonics
If anyone wants to see the opposite of keep it simple, take a look at the
source for the build engine. It will blow your mind.

------
joosters
I wonder why they opted not to use references? It seems an odd choice to me,
did id software give an explanation?

~~~
sunir
The most common argument:

Pass by reference hides the implication of a side effect on the parameter. If
you expect the function to manipulate the parameter, passing by pointer is
clearer.

Pass by reference was also only added to efficiently support copy constructors
and more importantly operator overloading, both of which are syntactic sugar
that a C with Classes style would normally avoid.

Template programming also requires pass by reference but templates are sugar
on sugar so not the core reason why pass by reference is needed.

Ps. Disclaimer: I haven't checked if the Doom3 code uses these features.

~~~
joosters
Fair points, although all references should ideally be const unless there are
side effects. It's not perfect though, since you can't tell from just viewing
the calling code, you have to check the function prototype.

References also help avoid problems with pointer aliasing, and make it clear
that the called function definitely cannot delete the passed objects. So it's
more than just syntactic sugar.

(n.b. I'm not arguing that pointers are bad and should never be used, I still
just don't see a clear reason never to use references. The id Software coders
are smart, they must have had good reason to pick their choice)

~~~
gtremper
Also, references can't be nullptr, which eliminates needs for null checks and
makes clear that nullptr isn't a valid value. RVO also makes "returning"
values through non-const references not as necessary.

Though, the most important thing is consistency and readability over using
fancy new features, so they should stick to the style they were using for the
project.

------
onion2k
If you read this article and agreed with it, you should definitely read this
next:
[http://lesswrong.com/lw/dr/generalizing_from_one_example/](http://lesswrong.com/lw/dr/generalizing_from_one_example/)

~~~
Angostura
I think you meant "If you only read the headline and agreed with it".

------
bigbv2093
As someone who wants to learn modern c++, what are some good resources/books
to learn from ? I have python and java experience and I have been reading
Accelerated C++ since a while now.

~~~
frankzinger
Not a definitive list, but these are good:

    
    
      The C++ Programming Language, 4th edition
      Bjarne Stroustrup
    
      The C++ Standard Library, 2nd Edition
      Nicolai M. Josuttis
    
      Effective C++, More Effective C++, Effective Modern C++ 
      Scott Meyers
    
      http://en.cppreference.com

~~~
pmelendez
I would also add Effective STL too.

A Tour of C++ by B. Stroustrup is a good start point for a beginner too

~~~
slm_HN
Well, don't forget about exceptions, unless you decide to ban them like many
people do. So add:

Exceptional C++ by Herb Sutter

More Exceptional C++ by Herb Sutter

Exceptional C++ Style by Herb Sutter

And Templates:

C++ Templates: The Complete Guide by Josuttis & Vandevoorde

And of course you need some background in generic & metaprogramming, so add:

Modern C++ Design by Alexandrescu

Advanced C++ Metaprogramming by Gennaro

So you're looking at over ten books. What does this say about C++? Can you
think of another language that has a ten book prerequisite?

~~~
bstamour
All of that is hardly prerequisite for using modern C++ on a day-to-day basis.
You can get away with just reading "A Tour of C++" and the Effective C++
books.

If you want to start writing highly generic libraries with the intention of
submitting them to boost, then absolutely you should be reading everything in
your list and more. But how many C++ programmers are writing boost libraries?

~~~
frankzinger
Yeah and the Exceptional C++ series is not 'about exceptions' either. It looks
like he just googled 'c++ exceptions book', and the same for templates and
metaprogramming, probably.

------
EGreg
This is back in the good old days when C++ didn't have all the crap, and
everyone wanted to stay away from doing advanced stuff with STL and RTTI.
Linus famously said that Linux is written in C if only to keep away the C++
developers.

Having said that, I used to write tutorials using the old ways as well:
[http://flipcode.com/archives/Theory_Practice-
Issue_06_Event_...](http://flipcode.com/archives/Theory_Practice-
Issue_06_Event_Handling_Model.shtml)

Does anyone love the new C++, and if so, what are their experiences with being
on teams that use the full range of functionality? Do you need a language
lawyer?

~~~
pmelendez
I do enjoy programming in C++11 style. What I like the most is that once you
understand the quirks, you would see a lot of opportunities to improve
performance but only when necessary (Like using moving semantics if you have
to pass a big object through several function calls)

Also STL has improved a lot and I am very happy that I don't need to include a
huge dependency such as Boost or POCO just to have a hash table for instance.

~~~
Retra
This comment represents the my biggest frustration with current programming
tools & practices. You shouldn't have to include any libraries. Ever! And you
shouldn't have to rewrite some code that does something that's already
available and well-written. That, and, if you want to include some
functionality, there will be 13,000 versions of the same functionality for you
to review before you decide which one to learn and commit to. (And it is
easier to write it yourself sometimes.)

There's no reliable way for languages themselves to standardize and aggregate
the work that others do. You just hope the language designers are willing to
put up a new version, (and that it's a decent one) and they end up doing it
ever-so-slowly because it's not automated in any way. Hand-pick and re-roll.
There's no metric-based signaling or automated analysis or anything, it's just
whatever your experts opine.

~~~
maaku
"You shouldn't have to include any libraries"

"you shouldn't have to rewrite some code that does something that's already
available and well-written"

How are those not contradictions?

~~~
Retra
You tell the compiler what data type you're trying to use, and it finds a
high-performance implementation for you over the internet.

~~~
maaku
That sounds incredibly safe.

~~~
Retra
Have you tried it? Or are you just imagining an extremely terrible
implementation of the idea so you can write short quips about how bad it must
be?

~~~
maaku
For basically every piece of software I work on this would have horrible
security implications. Let me spell it out in black and white: every time
someone does a deployment, by default it will download code from the internet
and incorporate it into production code. All one would need do is subvert one
external code provider and they'd have the ability to inject code into
countless production systems at will. How much do you trust github or
bitbucket? Would you give them the keys to your business, and your customer
accounts?

------
albertzeyer
I felt the same after reading all of ids engines source code, such as Quake
1-3. Those were C only, however.

------
mahouse
What's the IDE he uses?

~~~
Narishma
Visual Studio, like most game developers.

------
stefantalpalaru
> Note: Please offer only positive, constructive comments - we are looking to
> promote a positive atmosphere where collaboration is valued above all else.

And keep your rose-colored glasses on at all times. You shall see no evil,
hear no evil, speak no evil and never grow out of childhood.

------
Nilzor
No one have issues with source code files 5100 lines long?
[https://github.com/dhewm/dhewm3/blob/master/neo/game/ai/AI.c...](https://github.com/dhewm/dhewm3/blob/master/neo/game/ai/AI.cpp)

~~~
Someone1234
You make it sound like it is a single 5100 line long method. It seems actually
very well organised in that file.

If you're using any kind of IDE then this wouldn't bug you as you can just
jump to the point in the file you need.

~~~
clarry
And if you're not using a fancy IDE, jumping around in one file can be much
easier than jumping around a dozen files.

------
dvh
Not to brag but
[https://github.com/dhewm/dhewm3/blob/master/neo/idlib/Heap.c...](https://github.com/dhewm/dhewm3/blob/master/neo/idlib/Heap.cpp#L154)
(from line 154 down) that seems like another point against using tabs.

~~~
nezza-_-
I always heard "Tabs for indenting, spaces for aligning."

~~~
jpgvm
These days just use expand tab, in an age of online code review tools etc it's
just better not to have to configure every system to interpret tabs to your
given number of spaces - just write the damn spaces into the file.

~~~
Crito
> _" it's just better not to have to configure every system to interpret tabs
> to your given number of spaces"_

The entire point of _" tabs to indent; spaces to align"_ is that you _don 't_
need to make sure everyone displays tabs the same way. If we are using that
scheme and I have mine set to 4 spaces but you have yours set to 8, everything
is fine. There is no problem there.

------
highCs
> The game was a commercial success for id Software; with more than 3.5
> million copies of the game were sold.

Wrong/Cheated. It was such a success that they had to sell the company - they
sold ID-Software...

~~~
talmand
Doom 3 - 2004

ZeniMax - 2009

It seemed to do well enough to slow the need to sale for five years or so.

Or maybe, just maybe, it was so successful of a company that another company
bought it to share in the success.

~~~
Scuds
They were building Rage at the time. I'm sure the budget for that game was
like 5x that of D3. Shit runs late, cost blooms. Lots of 90's era twenty
person shops had trouble dealing with increasing costs.

~~~
talmand
So, you are suggesting that id was sold to cover the costs of Rage?

