T
Tim Harig
elegance?
Funny that you do not make any comments where I placed my counter-example
you might as well argue that { and } and we should all code in Pascal
(actually I /do/ think we should all code in pascal, but that's
another issue)
I also code in Ada. I have not problems with begin/end style syntax; but,
{} works just as well for me. The difference is that I see less abuse of
{} then I do of ?:.
rather depends on the code base doesn't it?
1. Reference: _Writing Solid Code_ by Steve Maguire, "The ?: is an If
Statement Too", p.127-130 and "APL Syndrome", p.161-162
2. I have too much experience with programmers abusing ?: only to write
errors. When I rewrite the code using if/else syntax and give them both
copies, they see their own errors much faster using the normal if/else
syntax.
do you have figures from cognitive scientists and psychologists?
I have 1 expert opinion, quite a bit of person experience with poorly
written ?: constructs, and another simple demonstration. Properly blocked
and indented code, even smeared out so the text and operators are not
visual, provides a number of clues about the code. This technique has been
used in studies for testing the readability of different indent styles and
block layouts.
See _Code Complete_ by Steve McConnell, section 18.2-4 "Layout
Techniques", p.408-410; section 18-3 "Layout Styles", p.410-417; and
section 18.4 "Laying Out Control Structures" p.417-425.
Using this method if/if else/else control structures are clearly visible in
the code even though the actual operators are obscured. ?:'s on a single
line just look like statements. Furthermore, the indentation style is
consistant with the style of the rest of the control statements used in the
code. ?: breaks this consistancy.
not really. I was always a fan of Algol-60s (and Coral's)
x := if a = b then 1 else 2;
that is they used the same keywords for both if/elses. Only yesterday
I was arguing with someone who said this was a bad idea and the two
forms /should/ be distinguished.
The ?: implies that a value is changing. That isn't always the case.
Sometimes you just want to use a different set of steps based on the
conditional. ?:, because it implys this changing value, doesn't work
clearly in this condition. If/else handles this flawlessly.