The only bad thing about C++ is C

Pages: 12345
On the first point, the Java Reflection library has a Method class, a Class class, etc...
On the second point I agree, but it's against "the Java way" or some stupid Javobject-oriented programming rule.
thanks for joining discussion

C++ comes not to replace C but to improve C make is more better (& that's why ++ )
using C inside C++ is just like adding those problems back to C++ which are suppose to eliminate by C++.
of course C is one of the most important mile stone in programming language history.
but it has its own limitation too.
around 30 years ago simpler C had replace assembly level language , in future may be C & C++ will be replace by C# & JAVA.
C++ will remains most important mile stone in object oriented programming language forever.
even C# & JAVA are improved from C++.
i am sure even if we avoid C in C++ , still C++ remains as efficient & faster as C , but it also become as safe as C# & JAVA.



I'd say that Java is what you get when you take C away from C++, but lets leave that aside. We're having enough problems with C++ alone.

Gaminic wrote:
The whole problem with C++ [in my eyes] is that abstraction leads to improper use.
http://cplusplus.com/reference/stl/vector/erase/ scroll down to "Complexity". This is not hidden. If somebody ignores it, it's their problem.

- No function pointers leads to crummy syntax for functions that take functions (in C++ there should be function references).


There *are* function pointers in Java 7. They are called method handles. And they are better than function pointers in C or C++, because their calls can be inlined. But this is off-topic.



- No non-member functions makes sine, a transcendent function that is implemented as one instruction, part of some stupid "Math" class, which is not cool.

Add import static java.lang.Math.* and your code would look just as in C++ - no stupid class prepended to your math calls.

These problems are like complaining about "foo" + "bar" thing in C++. They are not real problems. Real issues in Java is e.g. lack of value types (which C# got right) and performance decrease caused by (auto)boxing. And in C++ a real issue is lack of automatic memory management which makes functional programming near to impossible or things like lack of enforcing type bounds in templates which make compiler errors sometimes extremely long and confusing.
Oh yes, method handles (took them long enough, yeesh) can be inlined in all cases. Because Java is an interpreted language. If C++ was an interpreted language, then function pointers could also be inlined. Comparison in reflective capabilities will always favor the interpreted languages.

Add import static java.lang.Math.* and your code would look just as in C++ - no stupid class prepended to your math calls.

That does not address the main issue at hand - Java does not allow a function to exist on its own. It must be in a class, even if that does not make one whit of sense. This make Java a very hard language for newbies, who have a tenuous grasp of what a function is, let alone a class or package. It also adds an extra layer of boilerplate to every program.

And really it's pathetic. If I want OO and garbage collection and reflection, I'll write in Ruby.

EDIT:I just compiled this program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "stdio.h"

int addints(int a,int b){return a+b;}

int foldints(int(*f)(int,int),int a,int n, int *x){
	int i;
	for(i=0;i<n;i++)a=f(a,x[i]);
	return a;
}

int main(){
	int a[10]={1,2,3,4,5,6,7,8,9,10};
	int sum=foldints(addints,0,10,a);
	printf("%d",sum);
}


And guess what? Inlined!
Last edited on
I think that there are two type of C++ users :

-> those who use C++ to program C with classes. So, they use pure C with classes and sometime functions overload and default argument

-> thos who use pure C++ with almost each C++ features : pure STL container (no "C-array", no C char array ended by '\0', ...), references ...

I am one of the first group.
Last edited on
I don't like automatic memory management or garbage collection; it makes the world a very scary place...imagine!
Last edited on
closed account (1yR4jE8b)
I am one of the first group.


Then please stop. It's because of people like you that the world is full of horrific, unmaintainable, and frankly....bad, "C++".

And guess what? Inlined!


There is almost no use in that inlining, because Ruby is still about 100x slower than C++ and Java. Well, even JavaScript is much faster now.


This make Java a very hard language for newbies, who have a tenuous grasp of what a function is, let alone a class or package.


My experience says Java is much simpler language for newbies than C or C++ is. Packages are easy compared to header files, forward declarations, definition vs declaration thing in C or C++. I've been teaching Java for some time and I haven't met a student who had any problems understanding he must put everything in a class, yet. Most serious newbie problems are not related to the language, though. If someone doesn't grok assignment or recursion, he won't be able to program neither C, C++ nor Java.

Back to the topic: I think if you excluded the "C" part and left only the "++" part, you would end up with something similar to Java, but less safe, less expressive and slower. This would be taking out the main advantage of C++ - that you can easily descend to the bare metal level (well, almost).


Then please stop. It's because of people like you that the world is full of horrific, unmaintainable, and frankly....bad, "C++".


Probably most of C++ applications that are viewed as "lightweight, fast and portable" are written this way (e.g. Firefox or Chrome or most C++ benchmarks that are faster than Java). Applications that are written "the modern way", e.g. with templates, STL, Boost are often slow and bloated (see KDE).
I agree that Java is simpler than C++ but I don't like it. There are lots of small things about Java that irritate me; things like using system.out.println() to print text. C# has much cleaner syntax, and I prefer .NET to Java's libraries.
There is almost no use in that inlining, because Ruby is still about 100x slower than C++ and Java. Well, even JavaScript is much faster now.

Um, that was C code, not Ruby, as you should have realized if you read it. Your point is moot. As I see it there are two cases:
Case 1. You care about efficiency - You're doing games, or computing some mathematical problem, or working on some very slow computer inside a toaster or space probe, or making a OS.
In this case, you would use C or C++ or Fortran - some compiled language. The main flaw in C++ in this area is the slowness of STL compared to hand-written stuff. But sometimes you care a bit less about run speed just to increase development speed a bit. These languages are somewhat strict and have a lot of syntax, but they have mature, industrial-strength toolchains to compile and run directly on the metal (well, except for microcode, but let's ignore that for now).

Case 2. You don't care about efficiency - You're making a web applet, a simple desktop application, or a very basic game.
In this case, you would use a scripting language like Perl, Ruby, or Python. These languages are slower than C et al., but they make up for it by being easy to use and having no boilerplate, as this example which works in all three shows:
print "Hello, World!";

Java falls into the middle, which is empty.
Last edited on

Java falls into the middle, which is empty.


Huge popularity of Java tells me you are wrong (hmm, the most popular general purpose language?). There are not only 2 classes of applications - needing high performance and not. This is not discrete - this is continuous. There is a whole range of applications starting from the most performance critical ones to the ones where 100x slower than C is still fast enough. Java strikes a great balance between performance, which is in most cases on par with C or only marginally lower and programmer productivity, which is maybe also not the best you can get from other languages, but still much closer to LISP and scripting languages than to C or C++.

BTW: your inlining example is poor, because the inlined function is in the same source code, and it is obviously monomorphic - Java can inline accross dynamically loaded module boundaries and bimorphic or megamorphic, dynamic calls - things for which you would have to use a hashtable of function pointers in C, which would be very *slow*).

Last edited on
I used to think java was useless, then I took an arrow in the knee.
Huge popularity of Java tells me


Huge popularity of Call of Duty tells me...oh wait, it sucks; yet people still buy it...
Popularity doesn't mean anything really.
Why does Call of Duty suck? Sure it's not the greatest game out there, but it's still fun.

While we're talking about popularity, I've noticed that the game Minecraft has made Java much popular among the "non-techie" crowd, and now there's lots of self-proclaimed "java programmers" marching around with Minecraft mods they got off the internet, and thinking Java is the greatest programming language around.
@firedraco


It's not the franchise that sucks, it's the demographic that plays it.
This thread... well at least it went better than I thought...
I think this thread left the track, it is about C in C++ ,now it seems becoming C++ vs Java
I suppose I don't really like it because pretty much all the modern shooters are the same thing; they all copy off of each other now. And we also have Activision pumping out a new one every year that is almost exactly the same thing...almost like the sports games. Although at least there EA/2k seem to actually be trying to change up the system occasionally.
Pages: 12345