🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Future of C++

Started by
65 comments, last by savagerx 22 years, 9 months ago
quote:
If control is the only reason you are favouring C++ over Java, then why not switch to straight out ASM?

This is exactly my point, a decent C/C++ compiler will let you do something like this (the syntax can vary widely):

  __int64 __declspec( naked )  RDTSC()	{	_asm		{		//Prolog		push   ebp		mov    ebp, esp		sub    esp, __LOCAL_SIZE		//Get CPU Ticks		_emit  0x0f				// RDTSC		_emit  0x31		//Epilog		mov    esp, ebp		pop    ebp		ret		}	}  


C and C++ compilers let you program in asm (level 2), and even emit opcodes (level 1).

Now, if you wanted to time something to the nanosecond, how would do it in Java?

And control isn''t the only reason :p Macros, templates, and MI are big ones for me. And how about "const"?

Magmai Kai Holmlor
- Not For Rent
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
quote:
Now, if you wanted to time something to the nanosecond, how would do it in Java?


              //// Java//class test{  public native long RDTSC ();}//// C++//#include <jni.h>// Header for class test#ifndef _Included_test#define _Included_test#ifdef __cplusplusextern "C" {#endif/* * Class:     test * Method:    RDTSC * Signature: ()J */JNIEXPORT jlong JNICALL Java_test_RDTSC  (JNIEnv *, jclass){ // Place your ASM here}#ifdef __cplusplus}#endif#endif  



quote:
And control isn't the only reason :p Macros, templates, and MI are big ones for me. And how about "const"?


Macros: no java doesn't have macros, but the compiler will do some nice stuff for you:

        class MacroTest{  public static final boolean DEBUG = true;    public void runTest ()  {    if (DEBUG)    {      System.out.println("In Debug mode");    }    else    {      System.out.println("In Release mode");    }    System.out.println("Done");  }}  


In the above example, javac.exe will remove everything but printing "In Debug mode" and "Done". You still have to obay the language syntax though.

Templates: yeah, no templates, but most of that can be accomplished by polymorphism.

Multiple Inheritence: Java does have interfaces (pure virtual class with no defined methods), and you can extend as many of those as you want. Even when I'm coding C++ I try to avaoid MI and only subclass one "class" and then subclass only "interface" classes, helps avoid a bunch of MI problems.

const: yeah, that one's a bitch.

So c'mon Magmai, I bet if you really gave Java a shot you'd like it

"If consquences dictate our course of action, it doesn't matter what's right, it's only wrong if you get caught."
- Tool



Edit: formatting

Edited by - wayfarerx on October 4, 2001 3:54:43 PM
"There is no reason good should not triumph at least as often as evil. The triumph of anything is a matter of organization. If there are such things as angels, I hope that they're organized along the lines of the mafia." -Kurt Vonnegut
quote: Original post by Landsknecht
I dont like Java. The dang language was originally designed to run kitchen appliances! I drives me nuts to see so many colleges teaching Java as the main language in their Computer Science courses...

But a couple of points...
There are pointers in Java. Every instance of a class is a pointer to that class. Pointers are built into the language and kinda hidden from view.

For instance if you do this:
MyClass duh;
You get an empty pointer to MyClass. You don''t see this much. You usually see this:
MyClass duh = new MyClass();

Another thing, Java is interpreted - think along the lines of BASIC!

As far as cross compatability - I have nearly NEVER DL''d a Java application that worked without needing to be tweaked. In order to make a Java app work better/faster, people tend to use machine specific instruction sets. There goes cross platform.

In my opinion, Java is truly not much use and it irks the HELL out of me to be forced to learn it for my school programs.

Landsknecht
"For gold or glory, but never for free!"



My .02 cents as a newbie.

Actually, I feel that teaching of Java for Computer Science courses is a little better than it is at some schools. There are still schools that use Pascal as their teaching language and don''t even touch C/C++. Most of the schools that teach java use it as an intro to programming and then they move to C++. At least the OO handling of both are closer to each other than Pascal to C++.


BeS
It''s Da BOMB Baby!!!
. o O ~
A little nonsense now and then,
is relished by the wisest men
~ O o .
-- Willy Wonka
BeSIt's Da BOMB Baby!!!. o O ~ A little nonsense now and then,is relished by the wisest men~ O o .-- Willy Wonka
quote: Original post by Maximus

Funny, it ran just fine on the spare Celery300a w/ 64meg ram and a TnT1 that Ive got in the corner.

And only its scripting language was Java, not the engine itself.


Must have had a bad copy then as it wouldn''t work on my mates PC either which was saem cept with a TNT2 and 32MB more RAM.
I''m sorry, I can''t help but chime in here.

I''m using Java at work to do the same job as another language, Omnimark 5, and its speed is quite close. Considering the size of the samples I am using and the amount of output I get, its rippin fast.

I was also able to write a program that built GUI components, ie menus, toolbars, from XML files. The method called by the button/menu was also specified in the XML. No tables of function pointers, all reflection classes. This only took me a couple of days. Try that in C++.

Using Flash instead of Java in every case is just plain stupid.

There''s "const", its just called "final".

Correct me if I''m wrong, but templates are used for generic programming. In Java, since everything is inherited from Object, everythings done through polymorphism. No fuss, no muss.

quote:
There''s no substitute for C++.


Unless you are getting information from a database, then you''d use SQL.
Or if you are parsing a text file for patterns, then you''d use Perl or Awk.
Or running applications inside a web browser, then you''d use Java.

Any programmer worth his/her salt should be able to pick up any language for the given problem. Languages are just tools. If you only have a hammer, you treat everything like a nail. You can have a favourite hammer, just be prepared to use a screwdriver every once in a while.

If you think that you will only need one language for your entire programming career, you''d better find another career. Programming has one of the benefits of being able to learn new things every day. If you see this as a problem, you will get left behind. The skillset in this field changes constantly and quickly. Resisting change may prove to work against you.

As for the original questions:
(1)whether will JAVA take over C++ to becoming
the next main General Purpose Language?

Not everywhere. Telecom - no. Database apps - no. Graphics - no. Web Technology - good chance.

(2)how does that affect the type of language used
to make games?

Marginally.

(3)IF that''s the case, does it implies that we
may have to drop C++ and pick up JAVA?

Great News: You dont have to drop anything! If you pick up Java, it will only add to your knowledge base. The C++ will not get squeezed out. Java was designed to be familiar to C++, so it should be easy to pick up.
Templates and polymorphism are very much different.

Polymorphism implies a table of virtual function lookup table somewhere, be it in your code, VM, or OS space. That means when calling a function, there is additional time involved.

I don''t think you can implement polymorphism without a virtual lookup table.


Templates are resolved at compile time so there is no additional overhead when calling a function( other than the usual setting up a stackframe for a function call).

They are used for different purposes. Polymorphism should be used when there is direct modelling relationship. Templates can be used to customize behaviour at compile time. (See Policy class from Andrei Alexandrascu C++ Modern Design)

It is Java who are forcing programmers to be a hammer everytime in this respect by deriving everything from Object and using inheritance only.
No snide comments towards my post above with the link? Sigh, did no one bother to cut and paste it and check it? To clarify, it goes towards a Java Specification Request (134, Java Game Profile) that wants to allow (cut-and-paste)

1. 3D Modeling and Rendering for Games
2. 3D Physics Modeling for Games
3. 3D Character Animation for Games
4. 2D Rendering and Video Buffer Flipping for Games
5. Game Marshalling and Networked Communication
6. Streaming Media for Games
7. Sound for Games
8. Game Controllers
9. Hardware Access for Games

in a fast, efficient way so it is viable in speed hungry commercial games. Excactly what many posters said would never, ever be possible in Java. To give the link again, it is at http://jcp.org/jsr/detail/134.jsp
quote: Original post by WayfarerX
  class MacroTest{  public static final boolean DEBUG = true;    public void runTest ()  {    if (DEBUG)    {      System.out.println("In Debug mode");    }    else    {      System.out.println("In Release mode");    }    System.out.println("Done");  }}  


In the above example, javac.exe will remove everything but printing "In Debug mode" and "Done". You still have to obay the language syntax though.



Any C++ compiler worth it''s salt would do exactly the same thing. The reason for macros is not simple things like this, it''s for more compilcated things and for making the life of the programmer easier. For example, most of ATL is written with macros (ATL is a great way to use COM components without all the trouble of writing IDL files, amoung other things). Also, in the games I write, I have code for a quake-like console which relies quite heavily on macros for making my console function definitions easy. I have something like the following:

  // in my console.h file#define FUNCTION( name )                                        \    void __func__ ## name( int argc, char **argv );             \    CConFunc __con__ ## name( #name, __func__ ## name );        \    void __func__ ## name( int argc, char **argv )// in any other file where I want to define a console functionFUNCTION( con_func ){    // code to handle the "con_func" console function}  


The constructor for CConFunc adds itself to a global list of functions, and my console code just goes through that and searches for each function when they''re called. Very simple, and I don''t need to write lots of code for each new function!

quote:
There''s "const", its just called "final".


"const" and "final" are very different things, and personally, I''ve always wondered why Java didn''t support the const keyword. As an example, say I have a Java class like this:

  class MyJavaClass{    final Point pt = new Point(10, 10);    public void foo()    {        pt = new Point( 15, 10 ); // this is not legal, but...        pt.x = 15;                // ... this is!    }}  


The const keyword is used mainly by the compiler as an optimization hint. If it knows you''ll never change the value, it can do a lot of funky stuff to speed things up (for example, it can pass a reference instead of copying the whole structure)

Don''t get me wrong, I love Java, and in fact, I use it quite a bit - it''s great for quickly prototyping up a new idea I''ve just had or writing quick-and-dirty tools for whatever. I wouldn''t like to create anything too large-scale with it. Obviously, it''s possible - people are doing it all the time, but it''s just not my cup of tea...

codeka.com - Just click it.
www.runescape.com
appears as though java does OK here
In terms of structure and OO implementation, Java is a far BETTER language than C/C++. The only thing it lacks is speed. With C/C++ it is so often that you compile a program successfully but it just keep crashing during the actual execution. In Java, if u can compile it, it is less likely to run into unknown problems that takes hours to fix. I actually believe that Java is the best multi-purose programming language there is, even though I have not use it for long myself :-)

But if u are talking about games programming, then C/C++ is better coz it is worth spending twice the time debugging for that extra speed.

This topic is closed to new replies.

Advertisement