J
Jerry Coffin
[ ... ]
This depends (heavily) upon what you mean by "cryptic". Just for
example, consider changing:
if (x) y();
to:
x && y();
Is this cryptic or just strange? It does the same thing, and anybody who
knows C or C++ at all well should be able to figure out what it does
pretty easily, but I doubt anybody would claim it makes the code any
easier to read. Certainly few people code that way on a regular basis.
That depends. It's pretty typical that (especially in C) macros can be
written in a fashion that would otherwise be rather cryptic. For
example, if you want to put more than one statement in a macro, you
typically write it like:
do { statement1; statement2; } while (0);
In normal code that would be pointless and probably cryptic. In a macro,
it's widely recognized, though some frown upon it.
As it stands, no, it's fairly readable. OTOH, somebody might be likely
to wonder why you didn't just use std::swap.
I don't think there's any such phobia. There is, however, a perfectly
natural and well-founded dislike of using constructs that are odd for
the sake of being odd. Most code gains little or nothing from such
things as the XOR-based swap mentioned previously in this thread.
For most code that's really as efficient as its author can make it,
there's also something about 95% as efficient that's MUCH more readable.
The latter is _usually_ preferable.
I think if you want to make such claims, you should back them up with
some sort of evidence -- and you should do so somewhere that such a post
is topical, of course. As it stands, your opinions appear to have little
basis in reality and marginal topicality (at best) to the newsgroup.
I'd love to give a great example of cryptic-looking code that I'd
actually use... but I can't really think of any. I'd bitshift instead of
multiplying or dividing by a power of two... but that's not really
cryptic.
This depends (heavily) upon what you mean by "cryptic". Just for
example, consider changing:
if (x) y();
to:
x && y();
Is this cryptic or just strange? It does the same thing, and anybody who
knows C or C++ at all well should be able to figure out what it does
pretty easily, but I doubt anybody would claim it makes the code any
easier to read. Certainly few people code that way on a regular basis.
Are things considered cryptic if they're hidden away in a macro?
That depends. It's pretty typical that (especially in C) macros can be
written in a fashion that would otherwise be rather cryptic. For
example, if you want to put more than one statement in a macro, you
typically write it like:
do { statement1; statement2; } while (0);
In normal code that would be pointless and probably cryptic. In a macro,
it's widely recognized, though some frown upon it.
Is the following cryptic?
SWAP_INTS(a,b);
As it stands, no, it's fairly readable. OTOH, somebody might be likely
to wonder why you didn't just use std::swap.
The only thing I am against is the phobia of using efficient constructs
that are a little more complicated than their less efficient
counterparts. Of course, there are times I have gone for elegancy
instead of efficiency (especially when it comes to designing abstract
base classes as interfaces), but if I'm writing an algorithm then you
can be sure I won't be programming in the manner in which old women
drive.
I don't think there's any such phobia. There is, however, a perfectly
natural and well-founded dislike of using constructs that are odd for
the sake of being odd. Most code gains little or nothing from such
things as the XOR-based swap mentioned previously in this thread.
For most code that's really as efficient as its author can make it,
there's also something about 95% as efficient that's MUCH more readable.
The latter is _usually_ preferable.
Take an operating system like Windows XP... how much faster do you think
it would run if the programmers didn't go for the easiest solution every
time? Actually that's a bad example; Windows XP wouldn't run at all if
they went for the easist solution every time because Microsoft
programmers are mostly incompetant. But pretending for the moment that
they can program competantly, how much faster do you think it would run?
I'd say maybe 15% or 20% faster.
I think if you want to make such claims, you should back them up with
some sort of evidence -- and you should do so somewhere that such a post
is topical, of course. As it stands, your opinions appear to have little
basis in reality and marginal topicality (at best) to the newsgroup.