Notes from C++ static analysis
Paulo Pinto
pjmlp at progtools.org
Thu Jun 27 00:48:50 PDT 2013
On Wednesday, 26 June 2013 at 22:04:39 UTC, H. S. Teoh wrote:
> On Wed, Jun 26, 2013 at 11:47:32PM +0200, Paulo Pinto wrote:
>> Am 26.06.2013 20:52, schrieb H. S. Teoh:
> [...]
>> >None of my C++ code uses iostream. I still find stdio.h more
>> >comfortable to use, in spite of its many problems. One of the
>> >most
>> >annoying features of iostream is the abuse of operator<< and
>> >operator>> for I/O. Format strings are an ingenious idea
>> >sorely
>> >lacking in the iostream department (though admittedly the way
>> >it was
>> >implemented in stdio is rather unsafe, due to the inability
>> >of C to
>> >do many compile-time checks).
>>
>> I have been an adept of iostreams since day one and never
>> understood
>> why people complain so much about them or the operator<< and
>> operator>> for that matter.
>
> They're ugly, that's why. :) And misleading to anyone familiar
> with bit
> operators.
You just have to get used to the concept that operators are just
abstract method names, like in abstract math.
Operators are method calls, never think of them as anything else.
This is no different from languages like Eiffel, Smalltalk and all
the others that allow special characters as method names.
>
> But that's beside the point. The main problem is that format
> strings are
> inadequately replaced by operator<< and its ilk; C++ tried to
> get around
> them by introducing the concept of manipulators and whatnot,
> but that
> only increased the ugliness of it all. Plus, it made a string
> of <<'s
> stateful, (if the previous line sends a manipulator to cout,
> then
> subsequent <<'s are subtly modified from their usual behaviour)
> making
> it harder to read.
Yeah, the state fulness is a bit verbose, but I can live with it.
>
> D's writefln is far superior to C's stdio and C++'s iostream,
> in any
> case.
Agreed.
>
>
>> But I try to keep my C++ code clean from C'isms anyway.
> [...]
>
> I tried doing that once. It was a rather painful experience.
> That's the
> problem with C++: it started out as being C + classes, but then
> wanted
> really badly to assume its own identity, so it accumulated a
> whole bunch
> of other stuff, but then it never really cut its ties with C,
> and the
> old C + classes heritage lives on. As a result, its OO system
> leaves a
> lot to be desired when compared with, say, Java, but using it
> for just C
> + classes seems underwhelming when there's so much more to the
> language
> than just that. So you end up in this limbo where it's more
> than C +
> classes, but doesn't quite make it to the level of real OO like
> Java,
> and lots of hacks and ugly corner cases creep in to try to hold
> the
> tower of cards together. Trying to be free of C'isms only
> exposed the
> flaws of C++'s OO system even more. I found that writing C +
> classes is
> still the least painful way to use C++.
>
> Fortunately, there's D to turn to. ;-)
>
>
> T
When I got to use C for the first time, back in 1992, I already
knew a few Basic and Pascal dialects. So C felt really primitive
with no added value over Object Pascal other than being more
portable to systems I could not afford anyway.
The year thereafter I got my hands on Turbo C++ and then I found
a world where I could have C's portability and with a bit of
effort some of Pascal's safety back.
Since those days, I only touched C when required for university
work and on my first job.
Nowadays it is mostly JVM/.NET at work, with alternative
languages on my free time, including D. :)
--
Paulo
More information about the Digitalmars-d
mailing list