performance of different languages
by Yacine Salmi · in General Discussion · 05/30/2001 (11:06 am) · 8 replies
I'm just curious.
It seems to me that most game engines are coded in c or c++ with some assembly here and there for optimization. I personnaly really like c, but I find it lacking when I'm trying to develop a large project. So I'm turning to c++, mostly for the OOP. I know I can achieve some form of OOP with c, and I also know that Quake 3 is done in c. I'm not actually interested in the differences between c and c++.
I want to know is why only c and c++ seem to be used. I like perl. Actually, I love perl. And I would love to do a large game in perl. But perl has a lot of overhead when it it runs for the first time. But there must be a way of actually doing a full compile and getting an executable, you know, like with Java.
Each time I think of Java, all I can think of is the slow interpreted programs we had to write in first year comp.sci. courses, and of slow java applets. However, since we can compile Java, could it actually be used to make a high performance 3D engine? why? why not?
I'm kinda all over the place with this post, but I just want to know why c/c++ seem to be the standard languages used. Are there no other languages which are as fast?
thanks.
It seems to me that most game engines are coded in c or c++ with some assembly here and there for optimization. I personnaly really like c, but I find it lacking when I'm trying to develop a large project. So I'm turning to c++, mostly for the OOP. I know I can achieve some form of OOP with c, and I also know that Quake 3 is done in c. I'm not actually interested in the differences between c and c++.
I want to know is why only c and c++ seem to be used. I like perl. Actually, I love perl. And I would love to do a large game in perl. But perl has a lot of overhead when it it runs for the first time. But there must be a way of actually doing a full compile and getting an executable, you know, like with Java.
Each time I think of Java, all I can think of is the slow interpreted programs we had to write in first year comp.sci. courses, and of slow java applets. However, since we can compile Java, could it actually be used to make a high performance 3D engine? why? why not?
I'm kinda all over the place with this post, but I just want to know why c/c++ seem to be the standard languages used. Are there no other languages which are as fast?
thanks.
#2
www.javagaming.org
It is Sun Microsystems official game programming page.
-Tim aka Spock
05/30/2001 (12:10 pm)
According to Sun Engineers, Java correctly written is just as fast as C++ if you use their newest hotspot client. (jdk1.3) I think a game written in Java would be a lot easier than C++ but you couldn't target low end systems due to the fact that it runs terrible on them. Also you can't go into fullscreen mode yet with Java (unless you use directX) but you will be able to with the next release of Java 3d (j3D 1.3). They also have JDK 1.4 coming out sometime soon too. If you want more info about programming games in Java you should check out www.javagaming.org
It is Sun Microsystems official game programming page.
-Tim aka Spock
#3
I am STILL unconvinced of Java's ability to run in a high performance matter. BUt, all I have really seen is the web stuff (JSP and servelets, etc), so...
I tinkered with a game in Java once, ripped off a "TY Java in 21 days" project, they had some sample missile command code :)
05/30/2001 (1:02 pm)
Hehe, according to Sun, Java toasts bread :)I am STILL unconvinced of Java's ability to run in a high performance matter. BUt, all I have really seen is the web stuff (JSP and servelets, etc), so...
I tinkered with a game in Java once, ripped off a "TY Java in 21 days" project, they had some sample missile command code :)
#4
Just FYI:
Smalltalk
Why was it developed
Smalltalk was developed in 1980 from Simula which is a modelling language. The initial concepts helped develop the idea of a graphical user interface and object oriented programming
Smalltalk Syntax
One of the main features of Smalltalk is the simplicity of the syntax. Statements are always of the form receiver message or receiver message: parameter. There are no exceptions to this structure. Even an easily recognizable statement such as 1+ 2 follows this rule. 1 is the receiver + is the message and 2 is the parameter.
Developing Smalltalk Applications
Smalltalk comes with a set of standard tools. The main one of these is the Class Hierarchy Browser. This browser is like a super editor which presents the source code in a specific manner. A hierarchy is shown for Classes and each method is shown for a selected class. Finally the method source is shown for a select method.
The Smalltalk Environment
When Smalltalk was developed, it was not just a language but a full development environment. This environment contained a memory manager, a compiler, a windowing framework and numerous other classes to support it.
Smalltalk MT vs C++
Why would I want to use Smalltalk MT instead of C++ for development?
1. Simplicity!
The C++ environment is difficult to set up because there are so many pieces to the environment.
First there are header file (.h files) that provide definitions and macros. In order to compile a project, the environment must be set up to find the correct header file (and it must be the correct version).
Second there are library files (.lib files) which provide address to resolve linking. In order to link a project, the environment must be set up to find the correct library file (and there are often several versions of the library).
Smalltalk MT uses pool dictionaries that are held within the environment (no external files) so no need for external header files.
Smalltalk MT uses the DLL directly so no requirement for external library files.
2. Design
The C++ environment is file based meaning that the environment can only provide a file based view of a project.
Smalltalk MT is project based. All elements of the project are displayed in a class hierarchy browser allowing you to freely navigate between any parts.
This has a major impact on how easy things are to change. Since the whole program does not need to compile before running, you can do early unit testing and prototyping. Development becomes an evolutionary process changing with knowledge of the problem.
3. Variable Typing
C and it's derivatives (C++, Java, C#) all require variables to be typed. This means that you must decide in advance what kind of thing can reside there. Imagine this in the real world if you had to decide the one thing that could go in your mail slot in advance! In Smalltalk MT you simply create a variable and you can put anything in it. This help design by allowing you to concentrate on what variables you need to accomplish the task, instead of having to build application before the design.
05/30/2001 (1:05 pm)
You might want to take a look at SmallTalk MT from www.genify.com. It is a pure object oriented language that is easy to learn compared to C++. This version targets the windows PC with heavy optimizations that make it comparable with C/C++ speeds. You can work in both scripted and compiled forms to go from rapid prototyping to fast and efficient compiled binaries. www.genify.com is currently integrating all of the DX8 API directly into the IDE for the XBOX and Windows so creating a game on these platforms becomes highly efficient and relatively easy using the DX8 SDK. Just FYI:
Smalltalk
Why was it developed
Smalltalk was developed in 1980 from Simula which is a modelling language. The initial concepts helped develop the idea of a graphical user interface and object oriented programming
Smalltalk Syntax
One of the main features of Smalltalk is the simplicity of the syntax. Statements are always of the form receiver message or receiver message: parameter. There are no exceptions to this structure. Even an easily recognizable statement such as 1+ 2 follows this rule. 1 is the receiver + is the message and 2 is the parameter.
Developing Smalltalk Applications
Smalltalk comes with a set of standard tools. The main one of these is the Class Hierarchy Browser. This browser is like a super editor which presents the source code in a specific manner. A hierarchy is shown for Classes and each method is shown for a selected class. Finally the method source is shown for a select method.
The Smalltalk Environment
When Smalltalk was developed, it was not just a language but a full development environment. This environment contained a memory manager, a compiler, a windowing framework and numerous other classes to support it.
Smalltalk MT vs C++
Why would I want to use Smalltalk MT instead of C++ for development?
1. Simplicity!
The C++ environment is difficult to set up because there are so many pieces to the environment.
First there are header file (.h files) that provide definitions and macros. In order to compile a project, the environment must be set up to find the correct header file (and it must be the correct version).
Second there are library files (.lib files) which provide address to resolve linking. In order to link a project, the environment must be set up to find the correct library file (and there are often several versions of the library).
Smalltalk MT uses pool dictionaries that are held within the environment (no external files) so no need for external header files.
Smalltalk MT uses the DLL directly so no requirement for external library files.
2. Design
The C++ environment is file based meaning that the environment can only provide a file based view of a project.
Smalltalk MT is project based. All elements of the project are displayed in a class hierarchy browser allowing you to freely navigate between any parts.
This has a major impact on how easy things are to change. Since the whole program does not need to compile before running, you can do early unit testing and prototyping. Development becomes an evolutionary process changing with knowledge of the problem.
3. Variable Typing
C and it's derivatives (C++, Java, C#) all require variables to be typed. This means that you must decide in advance what kind of thing can reside there. Imagine this in the real world if you had to decide the one thing that could go in your mail slot in advance! In Smalltalk MT you simply create a variable and you can put anything in it. This help design by allowing you to concentrate on what variables you need to accomplish the task, instead of having to build application before the design.
#5
It seems that you prefer to use c++ over anything else, including c. However, Wouldn't it be hard to get the same performance from a c++ program as in c.
From what I understand, while it would take more work, it is possible to do an OOP program in c which would run faster than in c++. Wouldn't that anger the speed freak in you? Just curious =)
Anyways, you make a lot of good points. c++ does look like the right tool for game development
Shawn,
I'm also interested in developing on/for Linux. Actually, right now, I do all my work on Linux. I might learn windows programming a little later, but for now it's going to be Linux.
Smalltalk seems like a really interesting language, and if it gets the same performance as a c/c++ program, it's worth looking at. Do you know, if there is or will be any support for OpenGL? Is it supported on any other platforms than windows?
Yacine
05/30/2001 (1:43 pm)
Brian,It seems that you prefer to use c++ over anything else, including c. However, Wouldn't it be hard to get the same performance from a c++ program as in c.
From what I understand, while it would take more work, it is possible to do an OOP program in c which would run faster than in c++. Wouldn't that anger the speed freak in you? Just curious =)
Anyways, you make a lot of good points. c++ does look like the right tool for game development
Shawn,
I'm also interested in developing on/for Linux. Actually, right now, I do all my work on Linux. I might learn windows programming a little later, but for now it's going to be Linux.
Smalltalk seems like a really interesting language, and if it gets the same performance as a c/c++ program, it's worth looking at. Do you know, if there is or will be any support for OpenGL? Is it supported on any other platforms than windows?
Yacine
#6
05/30/2001 (2:29 pm)
This edition targets the Windows Platform specifically so its very fast but not suited for Linux just yet. You can load any standard _cdecl C API or .DLL by just telling the compiler where it is located and compiling it into the image.. very easy to do. So you can load the OpenGL32.DLL like any other one that uses the standard C calling conventions.
#7
As for speed differences, thats an interesting point. I've often wondered the same thing myself, but never actually put it to a test. I'm not sure if there would be that much of a speed difference, I mean, C++ is C after all, and can do everything C can. It would be interesting to know once and for all though, anyone done any tests like this before?
05/30/2001 (7:27 pm)
I've attempted to do some OOP stuff in C before, I dont know if theres some "standard" way of doing it, but I used structs containing function pointers. This was about the closest I could think of getting to a class. Its far from desireable though since you dont get to enjoy all the fun of inheritance, overloading, constructors and destructors...As for speed differences, thats an interesting point. I've often wondered the same thing myself, but never actually put it to a test. I'm not sure if there would be that much of a speed difference, I mean, C++ is C after all, and can do everything C can. It would be interesting to know once and for all though, anyone done any tests like this before?
#8
I still prefer C++ if only for the little things like operator overloading, template classes and multiple inheritance. All of which are lacking in JAVA (unless you count interfaces as multiple inheritance) though I believe Smalltalk (? haven't used it) has at least two of those three. There's nothing particularly wrong with Object Pascal/Delphi either.
The real issue is unfortunately support though, and nothing matches C++ there (not even C anymore I'd say). V12 is a prime example and in fact I do not know of any mainstream engine in developement that uses anything else. IMO if you're serious about game developement for the PC then C++ is probably as much(if not more) a standard as Windows (without making any judgements about the degree or merit of that standardisation ;) ).
05/30/2001 (8:47 pm)
I can't back this up but my gut feeling is that the speed difference between C and C++ was signigicant once but probably isn't now. I have no idea about C++ vs compiled JAVA but the garbage collector probably still uses significant resources for the time being (or have they introduced more control over the GC recently?), which is a shame cos I like GCs. I still prefer C++ if only for the little things like operator overloading, template classes and multiple inheritance. All of which are lacking in JAVA (unless you count interfaces as multiple inheritance) though I believe Smalltalk (? haven't used it) has at least two of those three. There's nothing particularly wrong with Object Pascal/Delphi either.
The real issue is unfortunately support though, and nothing matches C++ there (not even C anymore I'd say). V12 is a prime example and in fact I do not know of any mainstream engine in developement that uses anything else. IMO if you're serious about game developement for the PC then C++ is probably as much(if not more) a standard as Windows (without making any judgements about the degree or merit of that standardisation ;) ).
Torque 3D Owner Brian Smith
Kidding.
In sooth, I would be inclined to think that C/C++ compilers are the among the oldest available, and products like Visual C++ and CodeWarrior have been around long enough with plenty of smartypants engineers continuously optimizing them.
Another thing is that a language like C or C++ is much easier to create machine code for because of the level of control delegated to the programmer. "Higher level" languages leave a lot more decision making up to the compiler, which realistically can only be so smart. (This is where custom ASM code comes in.) Other "alternate" languages feature esoteric language features or constructs that simply have no way of being optimized well - at least in the context of a real-time graphics application.
In a similar vein of control is inherent code clarity, logical mechanisms (grammar issues), underlying technology and native protocols. For example, a lot of newbie VB programmers don't even know the difference between early and late binding of objects, much less the fact that one is significantly faster than the other.
These days though, I suppose you can waste a few cycles and use an "inferior" compiler for another language - it might even save you some development time. However, the hardcore speedfreak in me considers such thoughts of cycle wasting a programming sin. :-)