Why HL2 is made in c++?

C++ is used for execution speed and efficiency.
Let me elaborate:

Speed - C++ is compiled to native code where as C# is compiled to an intermediate language which is then interpreted by the CLR (common language runtime). This imposes a performance overhead since when classes are first loaded they have to be compiled.

Efficiency - .Net is a very handy language to program in since is discourages the use of pointers, and handles garbage collection for you automatically. Herein lies an effiency problem since you do not know when the garbage collector is going to run. In C++ you, the programmer, control this, hence you can avoid GCing at a bad time.


Finally, like most people have said, games programmers program in C++. Always have done, and will continue to do so for a considerable amount of time.
I'm not a games programmer myself, so code a lot in C# but use C++ when I need that low level control and pace.

Quake 2 was re-written in managed C++ a few months ago though, and seems to perform pretty well - after so hard-core tweaking though.
So maybe time will tell...
 
Re: Re: Why HL2 is made in c++?

Originally posted by Grif
Are you kidding me man. How many great, nooo even good, how many good games have you seen writen in Delphi and been published and had any kind of sales?! Come to think of it i know none. Jeee..... Delphi, lol

So what you're saying is that you have no experience whatsoever with Delphi? Because in terms of performance Delphi equals Visual C++. Of course this depends on how good the programmer is, but writing optimized code is as difficult in Delphi as it is in C++.
 
Question : Is C# compatible with the C++ .libs ?

Reason I ask is that a experienced programmer/s would have a considerable library of .lib files that contain readily re-usable code, which could reduce development time and allow more freedom to code the new routines.

Also there is a lot of material available on the internet that could be readily adopted to suit a purpose, so rather than have to code a routine yourself you can utilise a library file already available. Many such files are available and cut down on the chore of programming routine tasks.
 
All Java must be tipped down the sink!

Amiga VP code!

Don't kill me...

Seriously though, C++ is the *only* way to go if you want a good, complex game that doesn't run at 1 FPS on a P4 2Ghz.

Yeah, I exaggerate.

Seeya.
 
Thanks for the comments...

sounds if i really want to a game programmer (full time), i need to have c++ strong!

Thanks.. i will force myself into c++ for games, and c# for business apps :)

Thanks again. Ok, now i finally understand why hl2 is in c++ .. satisfied with the outcome.. haha!
 
Hi chuawenching,

While this issue has been discussed quite thoroughly, I thought I would just toss in my knowledge as a full-time programmer, and possibly "re-iterate" what's already been said here.

What most people have said is correct, however there are a few things you shouldn't believe. Some people said C++ was "easier" than C#. This is completely false. C# is a much more "high-level" programming language than C++. The most important thing to realize is C# is what's called "Managed Code" or a "Managed Programming Language". The reason they say C# is managed is because it's based on a hierarchy of interpretation, error-handling, and clean-up sub-routines. Where-as, C++ requires the programmer to handle all of this.

I really hope I don't lose you here, but as an example, "pointers" don't really exist in C#. At least, they aren't "needed" like in C++. (For all you programmers out there, I know pointers DO exist in C#, but you have declare the code as "unsafe" in order to use them. Hence, it's not really recommended or necessary.) Another great feature of "Managed Code" (we are referring to C# under .NET) is the ability to write class hierarchy, (OOP, Or Object Oriented Programming) without cleaning up after yourself when finished with instantiation. Also, C# is a TRUE object oriented programming language. This can be a debated subject.. but C++ has OOP capabilities and can definitely be used in a "strict" OOP mindset... but isn't a 100% "true" OOP language like C#. But that kind of flexibility is what makes C++ great.

Also, please keep in mind that a "compiled" C# program isn't a binary like a compiled C++ program is. C# programs are compiled in to "Intermediate Language" interpreted by the CLR (Common Language Runtime) in .NET. Basically, what this means is your C# program is CONSTANTLY being interpreted by that "hierarchy" of sub-routines we discussed above. Do you know what the CLR is written in? You guessed it.. C++. This translates to a pretty severe performance hit when you are talking "games". Now don't get me wrong, games have and ARE currently being written in C#, but they wont perform like they would if they were written in C++. Most of the time, they can be written so well, it doesn't really matter. But with C# programs it is a requirements to have the .NET runtime installed on your computer in order to run these C# programs. Without the .NET runtime, there is no way to "interpret" the IL. (You basically get DLL hook errors if you try.)

Another extremely important issue which isn't discussed often is the ability to access hardware. C++ has the extremely powerful ability to access hardware and give you the capability to write code for it. This is a little difficult in a C# program, is generally not possible or used in these situations. You see where i'm going with this? The ability to work with the hardware in Video Cards is probably not there for C#. The SDK's released by the graphics manufacturers are C++ oriented.

Another thing to realize is the ability to use API's like OpenGL and DirectX to base your graphics engine on. I'm not sure if this particular support is available now, and hope somebody can elaborate, but the last I heard, there were no "managed" DirectX API libraries under .NET. I heard Microsoft was attempting to work on them.. not sure if this ever happened. .NET has been considered a "failure" by the industry. (Thus far) Even if these libraries existed, they will have no-where the functionality that the C++ libraries have, and the kind of flexibility you would have using it.

It's important to understand that C++ is a standard in the industry. It is the de-facto standard when it comes to Programming Games. It's also important to remember that games require a huge amount of processing power to accomplish the many tasks they have layed upon them. In fact, the games you see today aren't "strictly" written in C++, but also Assembly. Assembly is THE low-level programming language you use to write sub-routines which have direct access to your hardware. (Your CPU registers) This in turn results in extremely fast sub-routines. Many game manufacturers write Assembly sub-routines for commonly used modules or math calculations for their 3D engine. For example, COS and SIN functions and other functions dealing with Vectors and Matrices. All of this can be accomplished with C++ and Assembly. With this language you have more flexibility, thus more power and control. But with it comes more work, more code, more clean-up, and more bugs.

But you can see why it's so widely used in games. Or any other software for that matter. Including Microsoft Windows.
 
Couldnt have done it better sPaG, great read. ;)
 
Thanks guys. :cheers:
I was hoping I didn't get too "technical". But as many of you know, it's hard not to when discussing this particular subject. Reading through this thread, there are a lot of smart folks, with programming experience. Good to see!

-sPaG
 
Originally posted by sPaG
Also, please keep in mind that a "compiled" C# program isn't a binary like a compiled C++ program is. C# programs are compiled in to "Intermediate Language" interpreted by the CLR (Common Language Runtime) in .NET. Basically, what this means is your C# program is CONSTANTLY being interpreted by that "hierarchy" of sub-routines we discussed above. Do you know what the CLR is written in? You guessed it.. C++. This translates to a pretty severe performance hit when you are talking "games". Now don't get me wrong, games have and ARE currently being written in C#, but they wont perform like they would if they were written in C++.
True, but using the ngen.exe tool you can compile the assembly to run in native code. However, this requires running ngen on the exact computer that plans to run the code, which is not practical for large-scale software distribution.

As hardware speeds become faster this intermediate-performance hit may become insignificant.

I'm not sure if this particular support is available now, and hope somebody can elaborate, but the last I heard, there were no "managed" DirectX API libraries under .NET. I heard Microsoft was attempting to work on them.. not sure if this ever happened. .NET has been considered a "failure" by the industry. (Thus far) Even if these libraries existed, they will have no-where the functionality that the C++ libraries have, and the kind of flexibility you would have using it.

The latest DirectX 9.0b SDK contains libraries for managed/.NET code. I'm not sure how well they perform, but I'll be testing them out later this year.

Here's a link to Microsoft's MSDN site where they discuss it:
http://msdn.microsoft.com/msdnmag/issues/03/07/DirectX90/default.aspx
 
Thanks for the update GrenadeMagnet! I haven't followed DirectX in managed code. (I don't believe in it) But could make for some interesting games. But like you mentioned, even with managed DirectX libraries under .NET, it poses problems for large-scale software distributions. In time, this may not be an issue as Microsoft is force-feeding us the .NET framework in their OS releases.

While the performance hit of interpreted Intermediate Language by the CLR may not be "drastic" or even noticeable for normal windows software applications, it's highly noticeable in performance games. I have seen comparisons of this between two 3D rendering software packages.. one in managed, and the other in C++. I must say, I am impressed how fast Microsoft's managed code is executed, there definitely is a performance hit, and this is unacceptable in an industry where gamers want nothing more than high end graphics with good framerates.
 
Originally posted by chuawenching
I'll post my version of MATLAB HL2 here when i finish
--> you kidding?

Wow is mathlab right?


Um, yes i was kidding.
In my estimation it would take 492 years to write the code, and require 4.5 supercomputers to run it. And then it would crash, set the harddisk on fire, and then people would realise that the MATLAB version of HL2 simply consisted of stupid coloured blocks that move around in a swirly fashion. Then real head crabs and zombies would be created out of the USB9.0 ports, causing the destruction of the earth. But who cares we have 492 years before that huh? And by then people will be flying around in space cars with two heads, a donkey and a can of white lightning (no, it will never die... you cap wearing scum).

And when you ask if mathlab is right... i just get confused...

It's MATLAB and it's great. It...errr... solves things....






....but not important things.





It's shit.






(I hate my degree)
 
Back
Top