Conrad2k:
quote:
So you tell me my friend, how do you catch your exceptions. By instance, reference or pointer? What happens to the allocated memory in case exception occurs. Does it get freed automaticly? No, you need to take special care to avoid memory leaks.
By value. Use stl containers and classes that wrap newed memory, so the destructor is called.
quote:
How about if some method declares to throw an exception? Are you forced to catch it? Can method throw exceptions though they didn''t declare that they would?
If you don''t want to catch it, it will unwind the exception stack to main. They can throw undeclared exceptions, they turn into unexpected_exception.
The stl gives you string and vector classes. These eliminate much of the need for explicit memory allocation.
quote:
Talking about templates in general, the error messages a beginning template programmer gets are ridiculously complex and very unredable. You must know the VC++ and the limit of 255 chars?-) I mean, what use is an error message that is 255 characters long?
The template errors in visual studio.NET are much more comprehensible. I agree that c++ isn''t as easy to learn as java, and that template errors can be quite obscure if you haven''t seen them before.
quote:
Well it isn''t directly an issue with the language, but honestly, which code is more readable?
I find most use of istreams very readable:
complex c;double d;string s;istream& in;in>>s>>d>>c;
quote:
With Java there are no headers. There isn''t need for them. Actually, why bother to write method name in two places when you can define the method where it is declared?
Rather, in java, everything is a header. If you wanted to, you could program c++ in this way as well.
quote:
Yes, I''m not familiar with STL, I''ve never had time to learn it well. And hopefully I never have to.
I''m sorry you feel that way. The STL has allowed me to understand generic programming, and provides a ton of cool and useful functionality.
Here''s a quick example...let''s say you have a phone directory, and you want to print it out sorted by name, and by number. As input, you have an unsorted file of the form:
Name Number
Name Number
...
struct record{string name;int number;};istream& operator>>(istream& in,record& r){ return in>>r.name>>r.number;}ostream& operator<<(ostream& out,const record& r){ return out<<r.name<<" "<<r.number;}bool sortbyname(const record& l,const record& r){ return l.name<r.name;}bool sortbynumber(const record& l,const record& r){ return l.number<r.number;}void process(string infile,string outfile1,string outfile2){ ifstream in(infile); ofstream out1(outfile1); ofstream out2(outfile2); vector<record> records(istream_iterator<record>(in),istream_iterator<record>()); sort(records.begin(),records.end(),sortbyname); copy(records.begin(),records.end(),ostream_iterator<record>(out1,"\n")); sort(records.begin(),records.end(),sortbynumber); copy(records.begin(),records.end(),ostream_iterator<record>(out2,"\n"));}
There are a lot of other nifty algorithms in the STL, and they work on any container.
quote:
Well what kind of machine you code with? 200MHz Pentium with 32 MB of RAM? On 800Mhz P3 with 256 MB of RAM you''ll do just fine. At least I do.
I have a 1.2 ghz athlon. But i''m very picky about my interfaces.
quote:
But how do you explain then that every database vendor concentrates on Java and XML then?
Hmm, afaik there are 2 major database vendors, Oracle and Microsoft. One uses c#, and one uses java. Seems tied to me.
quote:
Refactoring is a lot harder to do on C++ that it is on Java, and this is a fact. Java has simple syntax enough to make refactoring procedures simple enough. In Java there is no need to keep two method signatures synced like there is with C++. And there is no preprocessor to complicate things.
Granted, refactoring is easier in java. Good c++ coding frowns on the use of the preprocessor.
quote:
No matter what you do, c++ will run slower than asm code. It is the same thing. I don''t care if Java is a bit slower than comparable C++ code, all it matters is that I get my work done efficiently.
Actually, this is not necessarily true. Theoretically, there is nothing stopping c++ from performing as fast as assembly. WIth Java, the JVM and JITTER is competing for processor time and cache space. The difference is that you get a huge productivity increase moving from asm to c++, which is worth the performance hit for most applications. However, there is no proven productivity increase for moving from c++ to java.
quote:
As a side note, do you know what QuakeASM is? It is a platform-independent bytecode language for Quake 3.
That''s pretty cool, but considering that the graphics engine is the core of the q3a code, you still have a lot of porting to do.
quote:
x = (int)(f - 0.5);
in Java. Is that really that unreadable? Not to me.
just some random code snippets from my last java project
owner.drawCube(g,(i)*x/owner.size,(j)*y/owner.size,(int)(x/owner.size*0.9),(int)(y/owner.size*0.9),owner.pieces[i][j],true);colors[i][1]=new Color((int)(r*0.9),(int)(g*0.9),(int)(b*0.9));wincolor=(int)(Math.random()*10);
versus the c++ implementation:
owner.drawCube(g,i*x/owner.size,j*y/owner.size,x/owner.size*0.9,y/owner.size*0.9,owner.pieces[i][j],true);colors[i][1]=new Color(r*0.9,g*0.9,b*0.9);wincolor=rand()%10;
Casts from float to int aren''t necessary.
quote:
Lack of type-safety yes, but how many commercial applications actually throw ClassCastExceptions?
If I need a specialized container for certain class, I''ll write one. But I do just fine with the containers java.lang package delivers
It''s a gratuitous lack of type-safety...just like printf/scanf. There''s no good reason to allow putting different objects in the same container.
quote:
From what point did you consider Swing as a part of the language? It would be same as saying that MFC is a part of C++.
Oh, picking and choosing are we? =) Well, JBuilder(Borland''s IDE) and JDeveloper(Oracle''s IDE) and Forte(Sun''s IDE) are all laggy on my comp, so whether or not they''re written in swing, they''re slow.
quote:
Well, to me there''s nothing cool about streaming in C++.
Nothing cool about it? I can sort a list of integers from a file into another file in 2 lines of c++:
multi_set<int> myset(istream_iterator<int>(ifstream("numbers.txt")),istream_iterator<int>());copy(myset.begin(),myset.end(),ostream_iterator<int>(ofstream("sorted.txt"),"\n"));
Try doing that in java!
quote:
But I''ve seen the operator overloading abused badly on C++. What does c = a~b; do where a and b are some form of vector classes?
I can write obfuscated java code as well, if i wanted to, by implementing interfaces and then doing contrary things with them; it doesn''t mean i should though. Operator overloads are useful enough that they are part of the language, despite the potential for misuse.
quote:
There''s seldom need for true multiple inheritance and if there is, you can always solve it with interfaces and delegation.
I could likewise claim that there''s seldom a need for inheritence and if there is, you can always solve it with a virtual function pointer table. Why artificially limit yourself?
quote:
With this you mean platform-independency or goal for being platform-independent?
both.
quote:
Have you ever tried to do a compiler or a parser for any given programming language? C++ or Java especially? It is amazing how much you begin to appreciate a small, simple and consistent syntax when doing so.
That''s why I mentioned LISP =)
quote:
Let''s say we have written same algorithm to our problem in both C++ and Java. Java version performs poorly compared to C++, but both are unacceptable slow. Then we hear that there''s alternative algorithm that will considerably improve the performance, but it is quite complicated to implement. Depending on the problem, a Java programmer can implement the new algorithm usually faster than a C++ programmer with equally skills.
I heavily doubt that. While I agree that Java aids GUI development, I see no reason why coding an algorithm will be faster. The two crucial things are the algorithms provided by the language and library(I believe the stl has the advantage here), and the data structures provided(java and c++ are equal here, since both have hash tables, trees, strings, and resizable arrays).
quote:
Thus, you might have a situation where using VisualBasic would be more wise than using C++! (don''t laugh, I''ve seen it happen!)
I totally agree...pick the best tool for the job. If the majority of the code is gui related, VB(or c# or java) is a great choice. I find that the many programming styles c++ supports tend to make it the best tool for most of what I do.
I have to agree with unshaven bastard on his last point:
quote:
So they can do nothing in c++, but lots of stuff in java,
which means c++ = crap and java best language ever.
This belief is especially supported when the java supporters don''t even know anything about the stl(which makes a HUGE difference in c++ productivity). It seems that most only know enough to denounce it. (ie, MI is no good, templates aren''t important, etc) It''s also curious that most of the criticisms are exactly the features java is missing. If you asked most c++ developers what they wanted changed, i doubt many would ask for the elimination of MI(just don''t use it if you don''t want it), or operator overloads(same reason). Most of c++ has been designed to be orthogonal - if you don''t use a feature, you don''t pay for it.