To view parent comment, click here.
To read all comments associated with this story, please click here.
Macros are bad. Global variables are necessary. Pointers are useful (although not always necessary). Range checking is good in all but the most performance-critical code. I'll add that manual memory management is usually (but not always) unnecessary.
C++ does NOT have nice syntax and it's semantics are even worse. Java is nice, C# is a little nicer, but neither compiles very well to native code.
D ftw!
C++ does NOT have nice syntax and it's semantics are even worse. Java is nice, C# is a little nicer, but neither compiles very well to native code
While I agree C++'s syntax could be a lot better, I very much disagree with your assertion that C++'s semantics are bad. When used properly they are extremely powerful. For example, neither of them have an alternative for RAII (Resource Acquisition Is Initialization). Efficient & correct managing of resources is greatly eased by this pattern. Nor do they have a decent look-up mechanism for functions (there are plenty of things better left a function than a method). Or an alternative for templates (the STL containers are a blessing to work with). Saying its semantics are bad is nonsense: they are different. Different is not bad, as long as you use the right tool for the job.
Not necessarily. Macros provide for a way to transform text into other text, what's bad is the usage of macros that some people do.
With macros you could do this, in C++:
synchronized(object)
{
// Atomic operations here
}
Just like in java, and it would be totally legal C++, provided the macro synchronized expanded to something like this:
#define synchronized(o) for((o).Lock(); (o).isLocked(); (o).unLock())
Where o would be an object of a class exposing the Lock/isLocked/unLock methods. If a class inherited from a, say, synchronizable class implementing those methods, you would be able to do
someclass::somemethod()
{
synchronized(*this)
{
// bla bla bla
}
}
Which would be the equivalent of a synchronized method in the Java language.
You can have range checking in C++, you just need to either implement it in a class of your own or use some of the already existing classes.
You can have managed memory handling in C++ as well.





Member since:
2007-04-29
no no, c is not bad. macro's, global variables, pointers, no range checking (for arrays), bufferoverflows, the stl error messages and that kind of stuff are bad.
c(++) has a nice syntax. java and c# don't have the problems mentioned above, and that's why they are often used.