Re: Why C++ Is Not ???Back???
On Wednesday, December 5, 2012 4:11:10 AM UTC+1, Luca Risolia wrote:
On 05/12/2012 01:49, Jorgen Grahn wrote:
Speaking of that, his main theme is that C++ is *so* huge and complex
compared to C# and Java. I don't know either of those two, but
perhaps someone who does can comment: is that really true today?
With regard to the language itself, Java has always been behind compared=
to C++. As a simple example, have a look at what you had (or still have)=
to write in Java to safely use a stream:
try {
r = new Reader(...);
// do something
} catch (Exception e) {
//..
} finally {
try {
if (r != null) // cannot omit != null, no convertion op.
r.close();
} catch (Exception e){
//..
}
}
You should put construction of the reader outside the try, and you then hav=
e no "if" in the catch below. I see people do this all the time, why?
That is *complex*. Only with Java 7 they finally realized that above
code is too cumbersome and patched the language by inventing (yet)
another construct called "try with resource" (a sort of RAII), which in=
turn introduces new concepts such as "AutoCloseable"...
That, however, is absolutely true. RAII of C++ beats try/finally any day of=
the week. .NET world uses "using" blocks and IDisposable. But properly imp=
lementing IDisposable is __so much__ dumb code that many people just don't =
do it, instead they mandate that if a type is IDisposable, it's the user's =
responsibility to "correctly" call Dispose() on it (meaning, wrap it in "us=
ing" and write their own IDisposable).
Actually... What Java and .NET code puts up with is not complex. It's just =
__bloat__. ;-)
On the other hand, cognitive load (not code!) and correctness of design req=
uired to properly handle dynamic memory (heap) in C++ is orders of magnitud=
e bigger than in GC world ;-).
Goran.