If you don't want to rely on authority or reason, I suppose you could actually work a decade as a C++ developer and learn all these rules by trial and error. Reading a book is much faster |
No, you seem to have not understood me. What I'm saying is, many smart companies / developers have actually *spent* that decade of C++ programming by trial and error and came to completely divergent rules. Some say you should write C++ like C with classes, some uses heavily templates and loathe on seeing a raw pointer, some choose something in the middle like Google (which is pretty reasonable). That is why you really never know what to expect from someone who titles himself a C++ coder (even if you know he is a smartass).
A similar problem does not exist for Java. Smart Java coders just know whole language and use all the constructs when required (except the ones purposely deprecated by Sun/Oracle, but there are really very few).
I work on a big commercial project with over 30 people involved, which already is a huge commercial success (doing over a $1M per quarter and having some top-500 companies as customers) and I don't remember us having a discussion on particular style of coding, even though we have very different backgrounds - some from academia, some were diehard C++ coders, some would immediately switch to LISP if allowed to. In the previous company I worked for, C++ guys could endlessly discuss whether you should use iostream vs stdio or how you should structure your header files, or which things to pass by pointer, reference or value, instead of doing real work - things that for Java coders are just obvious and trivial.
That's what Generics are...the compiler just hides it all from you. And the worst part is that they're still unsafe because of erasure |
Unsafe? Only if you deliberately break the rules and ignore compiler warnings (casting back to old-style non-generic variants). So this is exactly the same as in C++ - if you use reinterpret_cast you are on your own. And even then, in Java it ends up by throwing an exception, so this is nowhere near the "unsafe" level you can get in C++.
At least generics are a part of the type system and not a textual substitution (macroprocessor) magic like in C++.
Java doesn't have a template system... |
C++ templates are a poorman's generics imlemented by a macroprocessor, which accidentally turned out to be turing complete and became a (pretty limited) metaprogramming framework. They are even not a part of the typesystem. However, having these features separate - i.e. properly designed generics + proper metaprogramming framework is a much cleaner and practical solution (D, Scala).