Why is Java more popular than C++

Pages: 123456
This topic reminds me of Xbox 360 vs PS3 topics on gaming forums lolol.
closed account (S6k9GNh0)
This topic reminds me of almost every thread rapidcoder has ever been in.

I obviously come to cplusplus.com to learn about Java.
Last edited on
I have 2 buddies working in the scientific R&D environment. Some of the simulations/calculations performed by there systems can literally take weeks (or even months sometimes) to complete.

The hardware they work on is also very, very extreme - 64 thousand cores upwards... To take advantage of this hardware they have developed a multi-threaded framework in both windows and unix.

The windows version is used for small scale component/model development where debugging is more superior. The exact same code is then compiled in nix against the nix version of the framwework.

This framework will remain the "property" of the company they work for, for a little while longer due to some type of time based NDA's in place to allow company to recoupe funding by being sole user of technology thus dominating their market/field.

Thereafter this technology is going to be released to general public and also submitted for academic advancement. I was in fact guinea pig tested by seeing if I could grasp and perform certain basic concepts/designs using framework.

To my surprise I found it quite easy and very intuitive to utilize the framework to solve tasks that would otherwise have taken much more effort to solve using the usuall single threaded design.

I found it surprising that I picked it up so fast since I don't come from a scientific background - I come from a financial programming background. IMHO this multi-threaded framework puts java's support for threads to shame.

In the technical opinion of my buddies, this level of multi-threaded development (performance wise at least) cannot be attained by a non native language, ie I was given a brief breakdown of the nature of the templates that ensures that the optimised conncurrency control is not embedded in some mechanism far from the users code.

Some of the threading abstractions are achieved using templates within classes - from my knowledge this cannot be easily done in java, and if it was somehow done, there would be a major performance hit incurred.

Sharing of objects between processes also became very easy and completely safe - I was virtually accessing and using these objects as if they were local to current process ... such things were made possible due to the template and operator overloading mechanism within c++ - something that does not exist in java.


So it seems as if the concept that c++ is not good for this or that is only true until some expert gets anoyed with the performance and drawbacks offered by other languages and creates that concept in c++.
Comparing a framework with a language - indeed, very smart. :D
Additionally, you've written a huge post, but not a single point where the described framework is better than facilities built into java. So this is merely an opinion.


I was virtually accessing and using these objects as if they were local to current process ... such things were made possible due to the template and operator overloading mechanism within c++ - something that does not exist in java.


Syntax is irrelevant to multicore scalability. Operator overloading is only a syntactic sugar. And I can get operator overloading in java by using some other JVM language - e.g. Scala which has superior operator overloading and superior metaprogramming facilities (as of version 2.10).

BTW: Transparent use of remote objects as local is a very old story. Probably it was even Java that popularized that concept (EJB) around year 2000. Currently most frameworks go away from this abstraction, because in reality it isn't as sexy as it seemed at the beginning. But C++ frameworks are always a few years behind others*, so it is pretty understandable you find it cool now. :D

* Another example: everyone around just noticed programming with threads and locks is passe, yet C++ has just added support for them in C++1x. :P
Last edited on
I will try to be objective(I personnaly hate Java).
Java has indeed some good points that C++ have not:
-Compilation and portability don't give headhaches like C++ does sometimes.
-Reflexivity wich is really a pain to emulates in C++.
-Source and header in the same file, very annoying in C++.

But one thing I can't understand is why Java is considered more high-level and easy than C++.
-Memory management? Smart pointers in C++.
-Ressource handling? A pain in Java (improved with the new try with ressource but still) but very easy in C++ with RAII.
-Generic code and meta-programming? Generic in Java are nothing compared to templates.
-Multithreading? tbb library of intel is very easy to use.
-Operator overloading? The great master of Java decided we are too dumb to use it.
-...

I could continue on others subject, really I don't see why it's easier to code in Java than in C++.
I think the simple fact of having a garbage collector is sufficient to say that Java is a higher-level language. Sure, C++ has RAII but it's not the same - you still need to think about many things, like object ownership, circular references etc.
-Compilation and portability don't give headhaches like C++ does sometimes.
When you allow for more complex code, do you not expect more complex mistakes to result in more complex errors? You should have simply said "Java is simpler" (which is a plus)

-Reflexivity wich is really a pain to emulates in C++.
Java's reflection is my favorite, but it lacks built-in language support beyond .class - I mean, why not .method and .field?

-Source and header in the same file, very annoying in C++.
Well personally, some rather large implementations can be a pain to have entirely in one file.

-Memory management? Smart pointers in C++.
Low-level languages let you control the memory and even do bad with it if you want. High-level languages manage it for you. Remember high-level != better language. Java is a higher level language than C++.

-Ressource handling? A pain in Java (improved with the new try with ressource but still) but very easy in C++ with RAII.
I don't often manage resources, but when I do, I prefer try-with-resources. I agree, it's annoying.

-Generic code and meta-programming? Generic in Java are nothing compared to templates.
Agreed. Erasure is even worse.

-Multithreading? tbb library of intel is very easy to use.
Compared to the rest of Java the multithreading support is very low level and they STILL do not give any guarantees, which is a strange thing for a high-level memory-managing language to do.

-Operator overloading? The great master of Java decided we are too dumb to use it.
I would love operator overloading to be in vanilla Java.

I could continue on others subject, really I don't see why it's easier to code in Java than in C++.
Hm, maybe the massive standard library with all the popular stuff in it that you have to deal with the C way in C++ or find some libraries yourself? People are really lazy, you know, and Java provides a lot of stuff up front that in C++ you have to go out and find yourself, and then get binaries of, and most people are too impatient to do all that.

Memory management? Smart pointers in C++


Smart pointers are both much slower than Java's GC and less safe. There are some algorithms, especially in functional programming, that without GC become either extremely hard, extremely slow, or (usually) both.


-Ressource handling? A pain in Java (improved with the new try with ressource but still) but very easy in C++ with RAII.


I haven't noticed. Resources are usually either local (trivial to manage), or global (also very easy to manage).


Generic code and meta-programming? Generic in Java are nothing compared to templates.


Java generics are a part of the type system. C++ templates are macros (text substitution). Comparing these two is pointless, even if they serve sometimes a similar purpose.

E.g. you can't directly express this in C++:
 
public <T extends SomeType> void function(T item);



Operator overloading? The great master of Java decided we are too dumb to use it.


Use Scala, Groovy, Ceylon or Kotlin then.


People are really lazy, you know, and Java provides a lot of stuff up front that in C++ you have to go out and find yourself, and then get binaries of, and most people are too impatient to do all that.


Avoiding unneeded work is a good feature of a programmer. We have a 100k LOC Java code base with a 1k LOC optional native component in C. Whenever there is a problem with portability it is because of the native part. Sometimes even minor number in OS version can stop it from compiling.
Last edited on
rapidcoder wrote:
E.g. you can't directly express this in C++: public <T extends SomeType> void function(T item);


If that means what I think it does, then actually, yes you can.
1
2
template <typename T>
void afunction(T t,typename std::enable_if<std::is_base_of<SomeType, T>::value>::type* = 0);


Perhaps it's verbose, but I see that as a limited issue at best, given how flexible std::enable_if is.

-Albatross
closed account (o1vk4iN6)
rapidcoder wrote:
Smart pointers are both much slower than Java's GC and less safe. There are some algorithms, especially in functional programming, that without GC become either extremely hard, extremely slow, or (usually) both.


Care to name some ?

Java generics are a part of the type system. C++ templates are macros (text substitution). Comparing these two is pointless, even if they serve sometimes a similar purpose.

E.g. you can't directly express this in C++:

public <T extends SomeType> void function(T item);


Why not just do:

void function( SomeType item );

?
You would need to do an explicit conversion in Java though right ?

Although I would see why you would want the type there, if not you can always do:

1
2
3
4
5
template<class T>
void function( T item )
{
    static_assert( std::is_base_of< SomeType, T >::value, "..." );
}



-Source and header in the same file, very annoying in C++.


You could put everything into the header file if you really wanted to, except for some exceptions. I for one keep my header files as minimal as possible (also have a separate file for inlined functions).
rapidcoder wrote:
Java generics are a part of the type system. C++ templates are macros (text substitution). Comparing these two is pointless, even if they serve sometimes a similar purpose.

E.g. you can't directly express this in C++:
public <T extends SomeType> void function(T item);
I laughed so hard. The example is bad for multiple reasons:
-You just stated that comparing them is pointless
-You compared them anyway with bias against C++
-Java generics solve different problems in different ways than C++ templates yet this example specifically tries to emphasize that a Java solution cannot be used to solve a Java problem, in C++.
> Java generics are a part of the type system. ... C++ templates are macros (text substitution).
> E.g. you can't directly express this in C++:
> public <T extends SomeType> void function(T item);

>> I laughed so hard. The example is bad for multiple reasons.

The example is bad for multiple reasons. The first reason is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <type_traits>

struct some_type { /* ... */ } ;

#include <iostream>

template < typename T > inline
typename std::enable_if< std::is_base_of< some_type, T >::value, void >::type
function( const T& )
{
    std::cout <<
        "THE ONLY FIRST ORDER DEFICIENCY IN JAVA IS ITS PROCLIVITY TO UNERRINGLY ATTRACT "
        "UNINFORMED, OPINIONATED AND INTELLECTUALLY DISHONEST BLABBERMOUTHS.\n" ;
}



>> You compared them anyway with bias against C++

Not mere bias; ignorant, mule-headed bias.

Baffles me why anyone without an understanding of the rudiments of C++ - 'C++ templates are macros (text substitution)' - would want to come to a C++ forum and pontificate at length, and without end, on the merits of the language.
Java technology allows you to work and play in a secure computing environment.
Java allows you to online games, chat with people around the world, calculate your mortgage interest, and view images in 3D, just to name a few.
Ingridfem wrote:
Java technology allows you to work and play in a secure computing environment.
Java allows you to online games, chat with people around the world, calculate your mortgage interest, and view images in 3D, just to name a few.


Yeah... as do pretty much all other programming languages with at least an ounce of worth. Its not a matter of what a language can/cannot do, as all languages can essentially do things all other languages can, but rather, it is an issue of which language does it "best". People have a different view of what "best" means, which is why we have shit storms civil debates like these.
Comparing a framework with a language - indeed, very smart. :D


No - I wasn't doing that - that would be silly - indeed very smart of you coming to that conclusion :D

One of the components of this argument started out that java is more popular than c++ because c++ makes certain things harder. I argued that this example (the framework) made multi-threaded development in c++ very easy. The common belief is that java has much better support for MT dev than c++ does.

When this framework gets released, then anyone who uses it is most likely going to find MT dev in c++ much more easy and powerful than someone using java.

In addition I tried to also point out that this MT framework harnesses alot of its power from the fact that it runs in native code - so even if the java devs later got hold of this c++ framework and tried creating similar concepts in java they'd most likely hit a brick wall at some point early trying to come close to the bench marks of the c++ version.

We'd probably find the java authors trying incorporate some of those concepts in a newer version of java or some "special" type of java edition.

And I still believe they will battle to reach the performances seen by the c++ version, especially on these monster machines used in some scientific research arenas.

And one also then need to consider the fact the this c++ framework was developed without the need to change the underlying c++ language itself. Unlike the java devs who have to wait eagerly for the java authors to release something to cater for a new concept they saw in some c++ framework.
But C++ frameworks are always a few years behind others*, so it is pretty understandable you find it cool now. :D



There are examples of c++ frameworks predating the existence of java where garbage collection was done.

So it may not be so true that c++ framworks are sooo far behind.
(maybe the java authors got the idea from such frameworks :D)

Hearing about such frameworks in exisitence so far back makes one wonder what private development framworks are going to bring to the table when they get released publicly.


Sure threading and locks are old and is now officially supported in new c++ and was also available in older c++ - the point is - there is much, much more to concurrency programming than just threads and locks.
C++ templates are macros (text substitution).


in c++ macros (#define ...) is text substitution - there are many examples using templates that cannot be done using macros.

macros are also a very nice feature in c/c++ - i've seen quite a few c# programmers create a whole lot of ugly code to mimic the behaviour that was afforded in the c++ application.

macros is another feature that java doesn't have.
E.g. you can't directly express this in C++


And vice verse - there would be many things you can directly express with c++ macros that you cannot do with generics.

Why else would c++/cli include both - why did they not just drop templates and only implement generics.

correction:
And vice verse - there would be many things you can directly express with c++ templates that you cannot do with generics.
Last edited on
Why else would c++/cli include both
Why bring yet another language into it. :0)

Here is my take on this:

C++ is not Java
Java is not C++
If Java meets your needs, use Java
If C++ meets your needs, use C++

C++ is not Java
Java is not C++
If Java meets your needs, use Java
If C++ meets your needs, use C++


No arguments from me or basically from the c++ community in general. The java community however promotes that java should be used for everything (or java is best for everything).

Typically you would hear a c++ dev saying that c++ won't be the best for designing a web service or ...

Can't seem recall a java dev saying something like that.
Pages: 123456