i

Started by
84 comments, last by GameDev.net 22 years, 4 months ago
Just to add my $0.02. The GC doesn''t replace the destructor. That''s because all it frees up is memory. Where as in a destructor, you perform all the cleaning up (i.e.close a handle to a file, redraw sprite background, etc).

The Java method that is ''destructor'' like is the finalize method of a class that gets called whenever the object is about to be GC''ed. The problem with this method is that you don''t know when your object is gonna get GC''ed.

This has caused me untold headaches. And I thought garbage collection was supposed to help the programmer.....
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
Advertisement
quote:Original post by Anonymous Poster (Henry)
If one really want to take things to extreme one can always argue that C++ can always be made to perform as fast or faster than Java since you can implement a Java runtime environment running exactely the Java program that you want to test against in C++.

I''ve used that argument before . My reply was a little harsh (I reread it), I''m not trying to say whether C/C++ or Java is better, I was just trying to put some added perspective one it .

[Resist Windows XP''s Invasive Production Activation Technology!]
I don''t think your comments were very harsch. However, all arguments are based on certain assumptions or generalizations. Even the argument about writing a Java environment in C++ is invalid if one is allowed to assume that the platform that the language comparison is made on is one of those processors that can execute Java bytecode directly in hardware. It is probably also false in reality since I doubt most people could write a full java runtime environment (including class libraries) faster than the people at Sun and IBM can improve their JVMs.

Henry
The speed arguement is really lost cause. If you want speed, even today, you still need assembly; assembly written by a guru who groks the machines. Most of the time you don''t need that kind of speed. Rasterizing is an example where you do - and all that code/micro-code is provided for you no matter platform you choose. I have a small library of FFT algorithms, some third-party ones, one I wrote, and one from Intel. The Intel FFT is over an order of magnitude faster. This capibility is what is lost in Java. It doesn''t matter how good those optimizing compilers become - because the mere act of watching the results precludes them from ever approaching that level of optimization. It''s rather like the heisenberg uncertainty principle, and we are concerned about nano-seconds.

For JIT to gain an advantage, they need to be able to out-optimize a human being on the inner loops. This simply is NOT possible. The JIT must maintain the intergrity of the byte-code, it must make certain that whatever the byte-code does now, is still done when the optimizations are over. A person is not quite as restricted - they are free to make dramatic changes to the orientation of the data, and the flow of the program to increase performance. If one day JIT compilers can do this, we will be at the dawn of an age Isaac Asimov wrote about.


So, if we set aside the trivial speed differences, what objective advantages does Java offer that C++ and a platform SDK do not offer?


Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee

"What I see is a system that _could do anything - but currently does nothing !" - Anonymous CEO
- 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
"So, if we set aside the trivial speed differences, what objective advantages does Java offer that C++ and a platform SDK do not offer?"

I still consider Garbage Collection a major advantage, good programmers can probably easily outperform the modern garbage collector, but the fact remains that there also alot of not so good programmers and good programmers who would rather be spending their time adding features than doing memory management.
Also under development i really appreciate bounds checking on containers.(Of course, it would be nice to be able to disable it for a release version).
Java garbage collection is somewhat of a hack, no cleanup is actually done until System.gc() is called or the program exits.

If you look in the taskmanager at a Java app that doesn''t manually call System.gc() you can see it eating about a 100K per second of memory. It will do that until no memory is available, and then a OutOfMemoryException is raised. That''s pretty crappy IMO.



-------homepage - email
I only know C++, and after learning it I forgot all other languages (except of course C). Its nice to deal with only one language.

Therefore I can''t really compare and contrast, but it seems that game development literature focuses on C and C++ more than anything else. Most Direct-X tutorials from MS use C/C++.

So if your goal is game design, it seems most logical to start with C and then advance to C++.
Value of good ideas: 10 cents per dozen.Implementation of the good ideas: Priceless.Machines, Anarchy and Destruction - A 3D action sim with a hint of strategy
First of, I do not think JAVA is easy to use. It has a steep learning curve. If I''m learning to program, and all I know is about algorithms, I can easily translate that pseudocode to C. However, if I''m learning using JAVA, I''ll have to understand two dozens of classes I didn''t know existed, and follow inheritance trees just to get the one I need.

Some poster mentioned JAVA "forcing OOP". Hehe. The fact that your program is a class means nothing. Think about all those one class, 300 methods programs around... is that object orientation?

JAVA''s portability. Good for small programs but, if what the majority of people here are saying becomes true, we will soon be writing games with it. I seriously doubt that they will work without modifications on all platforms. Heck, not even all browsers can display all applets correctly...

You can write EVERYTHING using C++ (one poster mentioned some things cannot, because you have to use Assembler. Now tell me, how can I use Assembler in a JAVA program? You can do this in C). The day I can start writing device drivers with it I''ll switch. Not before.

About that "library" someone mentioned that enables one to use DirectX and OpenGl in a Java program. Is that written in JAVA?

Gaiomard Dragon
-===(UDIC)===-
Gaiomard Dragon-===(UDIC)===-
Just thought I''d share my opinion in this matter. I do all of my personal programming in C++ (games, applications, etc.) but program in Java at my job as a programmer, and am quite experienced with both languages.

I recently read an interview with A. Stepanov, the mastermind behind STL, the C++ standard template library. Those of you who use STL will most likely appreciate it as much as I. He presents some interesting thoughts on the principles of programming, and even makes a few comments on Java. For those of you interested in reading the article, you can find it at http://www.stlport.com/resources/StepanovUSA.html.

The first quotes I provide are in relation to OOP, one of the topics that I frequently see when it comes to C++ vs. Java. The following are some questions posed to A. Stepanov and his responses that I think you all will find interesting:

"Question:
I think STL and Generic Programming mark a definite departure from the common C++ programming style, which I find is almost completely derived from SmallTalk. Do you agree?

Answer:
Yes. STL is not object oriented. I think that object orientedness is almost as much of a hoax as Artificial Intelligence. I have yet to see an interesting piece of code that comes from these OO people. In a sense, I am unfair to AI: I learned a lot of stuff from the MIT AI Lab crowd, they have done some really fundamental work: Bill Gosper''s Hakmem is one of the best things for a programmer to read. AI might not have had a serious foundation, but it produced Gosper and Stallman (Emacs), Moses (Macsyma) and Sussman (Scheme, together with Guy Steele). I find OOP technically unsound. It attempts to decompose the world in terms of interfaces that vary on a single type. To deal with the real problems you need multisorted algebras - families of interfaces that span multiple types. I find OOP philosophically unsound. It claims that everything is an object. Even if it is true it is not very interesting - saying that everything is an object is saying nothing at all. I find OOP methodologically wrong. It starts with classes. It is as if mathematicians would start with axioms. You do not start with axioms - you start with proofs. Only when you have found a bunch of related proofs, can you come up with axioms. You end with axioms. The same thing is true in programming: you have to start with interesting algorithms. Only when you understand them well, can you come up with an interface that will let them work.


Question:
Can I summarize your thinking as "find the [generic] data structure inside an algorithm" instead of "find the [virtual] algorithms inside an object"?

Answer:
Yes. Always start with algorithms.


Question:
This mean a radical change of mind from both imperative and OO thinking. What are the benefits, and the drawbacks, of this paradigm compared to the "standard" OO programming of SmallTalk or, say, Java?

Answer:
My approach works, theirs does not work. Try to implement a simple thing in the object oriented way, say, max. I do not know how it can be done. Using generic programming I can write:
template
inline StrictWeakOrdered& max(StrictWeakOrdered& x,
StrictWeakOrdered& y) {
return x < y ? y : x;
}

and
template
inline const StrictWeakOrdered& max(const StrictWeakOrdered& x,
const StrictWeakOrdered& y) {
return x < y ? y : x;
}


(you do need both & and const &). And then I define what strict weak ordered means. Try doing it in Java. You can''t write a generic max() in Java that takes two arguments of some type and has a return value of that same type. Inheritance and interfaces don''t help. And if they cannot implement max or swap or linear search, what chances do they have to implement really complex stuff? These are my litmus tests: if a language allows me to implement max and swap and linear search generically - then it has some potential.


Question:
Java is a very new language, still it lacks templates, so it prevents using Generic Programming. Everything must be a class. What do you think of Java?

Answer:
I spent several months programming in Java. Contrary to its authors prediction, it did not grow on me. I did not find any new insights - for the first time in my life programming in a new language did not bring me new insights. It keeps all the stuff that I never use in C++ - inheritance, virtuals - OO gook - and removes the stuff that I find useful. It might be successful - after all, MS DOS was - and it might be a profitable thing for all your readers to learn Java, but it has no intellectual value whatsoever. Look at their implementation of hash tables. Look at the sorting routines that come with their "cool" sorting applet. Try to use AWT. The best way to judge a language is to look at the code written by its proponents. "Radix enim omnium malorum est cupiditas" - and Java is clearly an example of a money oriented programming (MOP). As the chief proponent of Java at SGI told me: "Alex, you have to go where the money is." But I do not particularly want to go where the money is - it usually does not smell nice there. "

Now, I don''t agree with Mr. Stepanov on the fact that OOP is useless. I find it to be extremely useful at times, but not necessarily for the same reasons that OOP zealots claim. However, I do agree that "OOP" has become a buzzword, and that people are OOPizing things that shouldn''t be. One of the supposed "virtues" of OOP is encapsulation. This is true in many cases. However, you may be interested in reading an article by another C++ guru, Scott Meyers, author of Effective C++. You can find it here: http://www.cuj.com/articles/2000/0002/0002c/0002c.htm. He claims that encapsulation is better achieved in certain cases by using public C functions, and that "encapsulation is a means, not an end." I agree. My code is a combination of both OOP and procedural programming techniques.

The fact is, computers do not understand Java byte codes. They understand machine code. They understand procedures, addresses, registers, pointers, bytes, words, etc. "OOP" is just an abstraction. In fact, anything besides hand coding machine code is to some extent an abstraction of the language the computer understands. Some languages are highly abstracted from the computer architecture (like Java), while others are hardly abstracted at all (like assembly language). C and C++ fall somewhere in the middle. I like OOP just as much as the next guy, but people that say "learn Java if you want OOP and learn C++ if you don''t" need to understand some fundamental principles of computer science (for one, C++ is also object oriented, so your argument should say "learn Java if you want OOP, learn C if you don''t"--but this is besides the point). I find that people who know Java and no other programming language are pretty ignorant regarding the internal operation of a computer. A person that never has to use a pointer doesn''t understand how a computer accesses memory, and hence doesn''t understand the principles behind memory allocation and proper cleanup.

Operating systems aren''t written in Java. Device drivers aren''t written in Java. They''re written in programming languages that more closely match the design and interface of a real computer, not some imaginary virtual machine. The reason that C and C++ are so widespread, popular, and successful is because they provide the correct level of abstraction while maintaining a close, yet portable relationship to a real life microprocessor. C++ isn''t assembly language, yet it gives you power to do what you want it to do. Have you ever tried to read a single character from the console using Java? Under UNIX this is only possible by executing a shell script before running your Java programming. Under Win32, it''s impossible as far as I can tell. What do you think the Java virtual machine is written in? As a sidenote, I don''t think the next version of Windows will be programmed in C#.

Now, I''m not bashing OOP here. Like I said, I like OOP just as much as the next guy and use it all the time. However, the world doesn''t revolve around OOP. I prefer C++ over Java because it provides me with more power and control over what I OOPize and what I don''t, allowing me to maintain a desirable balance between encapsulation and efficiency.

Now, although A. Stepanov is not an OOP proponent, he stated the following about C++:

"Question:
What about Generic Programming? I only found some columns by A.Koenig in JOOP on "generic programming". Generic programming is definitively absent in most C++ programming books, including Coplien, Meyer, Stroustrup, Lippman and so on. I think STL could be described as "Programming C++ the way you would never thought possible". Do you agree?

Answer:
STL, at least for me, represents the only way programming is possible. It is, indeed, quite different from C++ programming as it was presented and still is presented in most textbooks. But, you see, I was not trying to program in C++, I was trying to find the right way to deal with software. I have been searching for a language in which I could express what I wanted to say for a long time. In other words, I know what I want to say. I can say it in C++, I can say it in Ada, I can say it in Scheme. I adapt myself to the language, but the essence of what I am trying to say is language independent. So far, C++ is the best language I''ve discovered to say what I want to say. It is not the ideal medium, but I can do more in it than in any other language I tried. It is actually my hope that someday there will be a language designed specifically with generic programming in mind."

Pay attention to the part where he says "C++ is the best language I''ve discovered to say what I want to say." I agree. I hope that everyone can find some time to take a look at the links above and read what real computer scientists think about these things.
First of all, they''re different. Java is mainly for web applications (Applets). C++ is mainly used for programs.

Second of all, I''ve noticed this a lot and...STOP calling it "JAVA". It''s not an Acronym for anything...It''s simply "Java" like Coffee. Get it? Good.

~SuperRoy
Sup guys?

This topic is closed to new replies.

Advertisement