Index | FAQ | Search | Memberlist | Usergroups | Profile | Log in to check your private messages | Log in | Register

id Tech 4 and C++ Goto page 1, 2 Next

| Inside3d Forums Forum Index -> General Discussion

View previous topic :: View next topic
Author | Message
--- | ---
dreadlorde Joined: 24 Nov 2009 Posts: 86 |

Posted: Sun Jan 24, 2010 6:14 pm Post subject: id Tech 4 and C++ |

Was the reasoning for the switch from C to C++ for the engine ever explained? Wikipedia just says

wikipedia wrote:
After the new renderer was functional, however, the decision was made to switch from C to the C++ programming language, necessitating a complete restructuring and rewrite of the rest of the engine; today, while id Tech 4 contains code from id Tech 3, much of it has had to be rewritten.

I can't find any other sources for the reasoning, so do any of you know?

Back to top |

Teiman Joined: 03 Jun 2007 Posts: 309 |

Posted: Sun Jan 24, 2010 6:24 pm Post subject: |

I don't know the reasons that decisions, and I don't know of any source with more information. --- Anyway most games are made on C++. C is a bit arcane now. C++ is OOP that can result on simpler code (YMMV). Also any OOP able to make huge changes without affecting the stability of the code.
Makes sense to use C++, and not C, to make games.
First thing Valve did with the "QuakeWorld/early Quake2" source was migrate it to C++. And seems a good decision. (heres a "Success history" for you )
Even without C++, some things on quake are already very "OOP" like:
QuakeC is OOP, the map entities are OOP, bsp is kinda OOP(?), .... maybe the only think that is happy to be C is the netcode, manual memory management and the like.

Back to top |

FrikaC Site Admin Joined: 08 Oct 2004 Posts: 947 |

Posted: Mon Jan 25, 2010 5:21 pm Post subject: |

IIRC, Carmack said at one point the reason for switching to C++ was that whenever a licensee bought an idTech license (at the time, Quake 3 engine license) the first thing they'd do is convert the code from C to C++, so for the sake of licensees they'd make all their engines in C++ now.
Over any perceived language benefits, I suspect the real reason all the licensees switched to C++ is that because the language is de facto for college CS courses. It's incredibly difficult to find C programmers or reinterpret_cast college educated C++ programmers into writing good C. In turn, the reason all the CS courses are C++ is because of enterprise level software engineering.

Back to top |

mh Joined: 12 Jan 2008 Posts: 909 |

Posted: Mon Jan 25, 2010 6:37 pm Post subject: |

My understanding at the time was that it's just the game code that's C++, and that at least the renderer is still C. Unfortunately I don't have any reference to back that up at the moment though. Regarding theoretical advantages of C++ over C, I think it's still a little shady. Free variable declaration anywhere you want is genuinely liberating (although a fully conformant C99 would give you that too), and if you're doing any COM programming or using 3rd party libs that primarily have a C++ interface it makes life easier. The improved type safety also helps catch a lot of errors before they happen.
OO constructs can more logically model certain things and it can make sense to used them in those contexts, but I've also seen plenty of cases where OO was used but it shouldn't have been (D3DXVECTOR as an argument to ID3DXMatrixStack::RotateAxisLocal was one specific annoying example) and which only serves to make things more awkward.
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines

Back to top |

dreadlorde Joined: 24 Nov 2009 Posts: 86 |

Posted: Mon Jan 25, 2010 7:15 pm Post subject: |

Teiman wrote:
Anyway most games are made on C++. C is a bit arcane now. C++ is OOP that can result on simpler code (YMMV). Also any OOP able to make huge changes without affecting the stability of the code. Makes sense to use C++, and not C, to make games.

I used to think the same thing, but after reading this last year I've decided to go against the OOP trend. C++ also compiles horribly slow on my machine, which is another reason for me not to like it.

Back to top |

frag.machine Joined: 25 Nov 2006 Posts: 728 |

Posted: Mon Jan 25, 2010 9:30 pm Post subject: |

dreadlorde wrote:

Teiman wrote:
Anyway most games are made on C++. C is a bit arcane now. C++ is OOP that can result on simpler code (YMMV). Also any OOP able to make huge changes without affecting the stability of the code. Makes sense to use C++, and not C, to make games.

I used to think the same thing, but after reading this last year I've decided to go against the OOP trend. C++ also compiles horribly slow on my machine, which is another reason for me not to like it.

I suggest you read it again e rethink your position. The article doesn't say "OOP << procedural"; instead, it enumerates some weak points (in author opinion) where OOP lacks to procedural such as compiling time and execution (again, it's the author opinion which I personally don't share - who really cares if a C++ program takes 10 seconds instead 5 seconds to compile ?). As a Java and C programmer, I'd say OO deserves its position as a better programming paradigm, specially if we are talking about big, corporative systems.
_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/

Back to top |

mh Joined: 12 Jan 2008 Posts: 909 |

Posted: Mon Jan 25, 2010 10:14 pm Post subject: |

Not necessarily always better. If an algorithm or other piece of logic is best and most clearly expressed procedurally then I say "code it procedurally" - going OO with it can only lead to obfuscation (the reverse is also true). Writing the code first time round is only half the battle remember; you have to maintain it going forward, and the person who takes over your job when you've left (or who fills in for you when you're on leave) will also have to maintain it.
Regarding compile times, DirectQ is C++ (purely to make DirectX calls easier) and I would guess it takes on average 5 to 10 times longer to compile than Win/GL/DarkPlaces/etc (or at least it certainly feels like it does). When you're measuring compile times in seconds that's peanuts; for really large projects you've probably just lost a few hours productivity (you may not have the luxury of nightly builds if you need to get a critical bugfix done now).
For the record, DirectQ does use classes in certain parts of it's code: the menus are all OO (there's even some multiple inheritance in there), cvars and commands are OO, the progs interpreter is OO, lightmaps are OO (although in hindsight they didn't really need to be), memory is OO. The renderer and base client and server code are purely procedural however and I don't see a convincing argument for going OO with them.
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines

Back to top |

frag.machine Joined: 25 Nov 2006 Posts: 728 |

Posted: Tue Jan 26, 2010 1:39 pm Post subject: |

mh wrote:
Not necessarily always better. If an algorithm or other piece of logic is best and most clearly expressed procedurally then I say "code it procedurally" - going OO with it can only lead to obfuscation (the reverse is also true).

Somebody once said that the best tool is the one you know better. I think the same applies here; if one feels easier to code/express an algorithm in procedural ways, it's fine as long the job is done with a minimal quality and in a reasonable time. That said, my personal experience points the OO paradigm as a more successful way to work with relatively big ( >= 10 programmers) teams keeping quality and time.
_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/

Back to top |

FrikaC Site Admin Joined: 08 Oct 2004 Posts: 947 |

Posted: Tue Jan 26, 2010 3:38 pm Post subject: |

Quote:
My understanding at the time was that it's just the game code that's C++, and that at least the renderer is still C.

It's all C++.

Back to top |

dreadlorde Joined: 24 Nov 2009 Posts: 86 |

Posted: Wed Jan 27, 2010 12:45 am Post subject: |

frag.machine wrote:
Somebody once said that the best tool is the one you know better.

If I need to solder something, but don't know how to use a soldering iron, should I use my hammer?
I'm not trying to start a programming language fight, I'm just interested in why people see OOP; C++ specifically, as 'better' than procedural programming. The things I don't like about C++ are it's infinitely complex preprocessor and inheritance.
_________________

Ken Thompson wrote:
One of my most productive days was throwing away 1000 lines of code.

Get off my lawn!

Back to top |

frag.machine Joined: 25 Nov 2006 Posts: 728 |

Posted: Wed Jan 27, 2010 1:03 am Post subject: |

dreadlorde wrote:

frag.machine wrote:
Somebody once said that the best tool is the one you know better.

If I need to solder something, but don't know how to use a soldering iron, should I use my hammer?

No, but if you already had an old and rusty soldering iron that you're used to and I offer a brand new one with a radically different design, chances are you'll stick to ye olde soldering iron. That's what I was trying to show. And believe me, there's nothing wrong about sticking with something you trust and know well, as long you are open-minded to at least try the new things - and when I say "try", I mean REALLY try, not giving up in the first obstacle.

dreadlorde wrote:
I'm not trying to start a programming language fight, I'm just interested in why people see OOP; C++ specifically, as 'better' than procedural programming. The things I don't like about C++ are it's infinitely complex preprocessor and inheritance.

Can't say much about C++ since almost all my experience in OOP is under Java, that uses a simple inheritance model, borrowed from Object Pascal/Delphi. But 9 out of 10 programmers have a big trauma from C++ inheritance model, so I believe it does deserve this bad reputation.
_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/

Back to top |

Baker Joined: 14 Mar 2006 Posts: 1538 |

Posted: Wed Jan 27, 2010 1:11 am Post subject: |

C++ and OOP is great at creating a giant tower of babel with infinite complexity when it could be simple. ... generally. Simplicity is the true expression of genius. _________________ Tomorrow Never Dies. I feel this Tomorrow knocking on the door ...

Back to top |

Spike Joined: 05 Nov 2004 Posts: 944 Location: UK |

Posted: Wed Jan 27, 2010 2:43 am Post subject: |

The thing about C++ is that you don't have to use it all, indeed, the best C++ programs are generally the ones that stick to a specific subset. C++ does not mandate OOP. Java is a superior language for strict OOP programming. But its strictness hinders its uptake (as does its system apis).
For me, C++ is synonomous with spagetti. It is not fun to go through a program using inheritance, overloads, etc etc, trying to find how the heck some variable somewhere else is getting set unexpectedly.
Programming is 90% reading.
Gamecode as C++ makes sense, no matter how much I hate other people's C++ code (assuming it even compiles). Making the engine C++ (but not specifically OOP) also makes sense if the gamecode is.
I realise these are my own opinions, but its also my opinion that this I have a reasonably wide spread viewpoint.
_________________
What's a signature?

Back to top |

mh Joined: 12 Jan 2008 Posts: 909 |

Posted: Wed Jan 27, 2010 10:10 am Post subject: |

Spike wrote:
The thing about C++ is that you don't have to use it all, indeed, the best C++ programs are generally the ones that stick to a specific subset. C++ does not mandate OOP. Java is a superior language for strict OOP programming. But its strictness hinders its uptake (as does its system apis).

That's basically it in a nutshell. The same can be said of C# and VB.NET (although C# - dunno about VB.NET - at least allows pointers, unsafe code and native API interop so it's a bit more useful in overall terms).
Even the dreaded C++ inheritance model is not really that bad if it's used with common sense, restraint, and only where needed. Where it turns into the 9th Circle of Hell is when you get people constructing huge towering artefacts with multiple inheritance, templates and layer upon layer of abstraction just to accomplish a simple task. Where C++ as a whole fails is that it's shockingly easy to do this.
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines

Back to top |

Teiman Joined: 03 Jun 2007 Posts: 309 |

Posted: Wed Jan 27, 2010 2:12 pm Post subject: |

OOP is different toolset, that let you solve problems in a different way, not totally compatible with the procedural way. So wen you choose OOP theres a trade-off. Choosing C, lets you use *all* of what the "procedural way" has to offer. Choosing C++ lets you use part of that, and activate a whole new continent of skills and tools.
I am a different programmer wen I write C than C++. Oh, and I am a much [s]better[/s]powerfull programmer wen I write in a OOP powered language.

Back to top |

Display posts from previous:

| Inside3d Forums Forum Index -> General Discussion | All times are GMT Goto page 1, 2 Next
Page 1 of 2

Jump to:

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2004 phpBB Group