Java, C++... can't we all just get along!?

Started by
26 comments, last by dmf_king 20 years, 2 months ago
*vomits on thread*

oh look the stain blends right in with everyone''s comments...you cant even tell the difference...



dmf_king: sorry you had to be witness to this. to answer your question, for you i can almost guarantee there will be no significant limitations...basically the real difference is in the freedom the language gives you to interact with the hardware and lower levels...since java runs on a virtual machine you by definition cant do things like address memory directly. this can be great, it makes for a very stable and quick platform to develop on, but in very rare cases you have to bend over backward to do something that would have been pretty trivial with some pointer arithmetic. personally i think everyone should know both, they are both great languages.

everyone gets in such a tizzy about these conversations, i dont know why...especially now that many c++ developers are realizing that the C# paradigm isnt so bad...and, by extension, that java isnt where it was in 1998. JIT compilers have made a world of difference. ignorance, i suppose.



and to those talking about multiple inheritance...usually thats called a "hack"...using multiple interfaces is usually all you need, especially since you can cut out the conflicting data (vs the methods/functions) that was the reason anybody said anything bad about multiple inheritance in the first place. only very very rarely would you ever have to use them and a)you can figure out another way and b)you pay a price for a proper OOP implementation. *runs for cover*
Advertisement
quote:Original post by Raghar
More readable guess what.

Readability is subjective. Java has cleaner syntax. I can write confusing programs in either language.

quote:Multiple entry points and better debugers than C ones. gives you the second.

Better debuggers? Again that is subjective. You''d be hard pressed to beat VS.net''s.

quote:Class encapsulation that is guaranteed with tools that use Java structure to their advantage gives you third.

How is this any different from C++ classes?
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
quote:Original post by Zahlman
You just basically said the same thing four times.
I see the joke was lost

quote:Original post by Russell
In other words, counting everything out that is different between C++ and Java, C++ and Java are the same. Master of the obvious here...
I see you didn''t quite understand the point . Try harder, you can do it!

quote:Original post by Anonymous Poster
If you meant templates, then let me tell you Java has far easier memory management, dynamic garbage collection, elegant dead reference detection system, memory leak prevention mechanism and more


I don''t really think it''s fair to compare templates to memory management. Why not compare templates to generics?

Java''s new generics system is both better and worse than C++''s template system.

In Java one can specify that a generic type parameter must be a subclass of a particular class (or implement a particular interface). This is handy if you want to define a generic class or method that operates on Collections, say.

Although C++ would still detect an attempt to use .begin() on a float, Java detects the error closer to where it actually occurs.

C++''s templates have features that are absent from Java (and, as it happens, C#). In C++, templates can have value parameters as well as type parameters. This allows the compiler to generate more efficient code for types such as matrix<4, 4>, in terms of both speed and space.

If Java supported this, it would allow some bounds-checking to be performed at compile-time: mat.get(5,9) would obviously be invalid if Java knew the size of the matrix at compile-time.

In addition, C++ allows for specialisation of templates. This allows for further optimisation. In the running example, the implementation of matrix<4,4> could be optimised to automatically use CPU extensions for multiplying 4x4 matrices, if any are available.

Java can specialise in as much as it could define a Matrix44<T> class that extends the Matrix<T> class. However, the advantage of C++ specialisation is that adding matrix<4,4> automatically applies that specialisation to all 4-by-4 matrices, whereas in Java one would need to replace references to Matrix with references to Matrix44 wherever a 4-by-4 matrix was being used.

Another significant advantage in C++ is that, unlike Java, it allows for generic parameter types to be value types. This would allow for efficient storage of value types in Vectors or Hashtables, amongst other things.

The reason Java doesn''t allow this is also the reason for one of the advantages it has over C++: Java''s generics are designed so that, unlike in C++, only one copy of a generic method or the methods of a generic class needs to be compiled.

That makes it easy to distribute generics in libraries without having to worry about what will happen if somebody tries to use your generic with a type you haven''t compiled in.

In summary:

C++: Value parameters, specialisation, type parameters may be value types
Java: Type parameter constraints, single-compilation

Type constraints could be added to C++ without issue.

The single-compilation feature is mutually incompatible with C++''s implementation of value parameters and the orthogonal type parameters.

You can redefine how value parameters and type parameters work -- value parameters act like ordinary parameters, and type parameters are always reference types (value types are boxed as necessary: requires the introduction of boxed types into C++). That would allow the single-compilation rule to be observed but would negate the efficiency benefits that C++ templates have over Java generics.

It seems to me that Java generics are more likely to be widely used than C++ templates because updates to Java generics can be distributed in binary libraries such that any program that used the old version of the generic will have no trouble using the new version. In C++, on the other hand, not only do you have to go out of your way to put your template code into seperate libraries, but a consumer of your library will only be able to use the template functions that you''ve compiled in, which defeats the purpose of templates.

CoV
CoV
quote:Original post by JohanOfverstedt
For Java, the user of your app must have the JAVA RUNTIME. Most home users don''t. And if your app is a small one (A couple megs or less) then it''s a major pain in the butt. Should the users have to download many megabytes just to use your little app.

And, by default, java programs don''t have an exe file to start them which is what most Windows users are used to.

DISCLAIMER: If any of the above statements are incorrect, feel free to give me a good hard slap

My game: Swift blocks

[edited by - JohanOfverstedt on January 25, 2004 4:58:06 PM]


*SLAP*

Most Windows users are used to an icon on the desktop or an item in the Start menu.

CoV
CoV
quote:Original post by DerAnged
cocoa on mac gcc on linux mingW or VC++ on windows C++ isnt cross platform eh? (c++ is faster to)(yet asm is faster than cpp)

Um, I think you mean Carbon, not Cocoa for C++ Mac programming. Since Cocoa is made with Objective-C. Basically, if you want a cross-platform title, and want to use the same libraries, with a nice API, Java would be an easier development cycle than if you used C++. If you are caring more about optimization, then you should have C or C++ as the two languages that enter the front of your mind. It all depends on what the application you are making needs to do. Although in most cases, the programmer will use their own tastes to determine what language will be used when they can.
Disclaimer any unprecisity is caused by my dislexy and lack of time to read it carefully.
~_^

Actually animosity of older developers started several years ago, when there was as hyped crowd as is ther now with C#. Numbers flown everywhere and it was annoying. As a result myth called Java slow emerged. To put long story shorter. Java improved and younger Java programmers that didn''t participated in that discusions from long ago, became very irritated by some phrases from the past. Now there is hyped crowd in C# you listen several words like language independence of .NET, ECMA certification, delegates, possibility of using pointers from C# and so on. These are the same proclamations that were few year ago with Java. Such features wont come without price, however. So if you have time you could do a comparison of such features and a price that comes with them. Mayrel did a nice comparison of templates and generics. And even if comparisson between using and not using pointers could be difficult, result would be that not using pointers in JIT enviroment is in most cases better.

Another difference between Java and C++ is documentation. Look at it and imagine that someone would go to that language without several years of experience with it. Add in multipass compiler and you can see why would people abandon C++ even if they have several years of experience with it.

Another isue is that when people are older they are afraid/lazy to learn new things. Imagine some programmer that used C++ 5 or 8 years and he is faced with possiblity of learning a new language. He wont be happy. (to put it mildly) Amount of useless rants could easily be decreased by "you''ll learn in or you''d be fired" told half seriously, but some people aren''t happy to use this tactic. (it''s useles by the way, but forces that programmer to think and slowly accept that fact. Just be sure that he knows, you weren''t entirely serious.)

I knew at least 5 different programming languages, and I''m using at least two, or three at same time. I''m not sure if I should acount ASM as a language. You are using it differently and you are learning instruction set for each processor anyway. I don''t count PHP HTML or database queries as language. It has hardly anything to do with a programming. I would advise anyone to learn more than one language, then you''d not use what is effective. Yes you''d have one or more that you''d like and you''d use, but it''s would be without problem as long as you could port from them.

This topic is closed to new replies.

Advertisement