Re: Add a ternary operator to the language?

From: Will DeWitt Jr. (edge_at_boink.net)
Date: 06/23/04


Date: 23 Jun 2004 06:05:47 -0700

Jim Cooper wrote:

>
> > It takes what would traditionally be four lines of code and reduces
> > it to a single line.
>
> But it doesn't improve the readability (ie understanability) of the
> code.

But it doesn't make it any more difficult to understand either. It
*does* improve readability in the sense that now you can see three more
lines at once that you wouldn't have been able to see before. If you
had a lot of code that did this kind of checking (and it's not uncommon
to have such blocks of code) you could save potentially 30+ lines and
make the actual code overall *more* readable.

> A handful of lines here and there makes little difference these days.
> You can save even more lines by writing more than one statement on a
> line :

Yes, but *that* would be confusing to follow. =)

> Less lines is very definitely not equal to clearer code. At best the
> ternary operator is as clear as the alternative, at worst it is a
> hazard to sanity. As I said, I don;t think you've proved your case,
> just proved that you like the construct :-) Since it's one of those
> that there is nowhere near universal agreement about, I think you
> will need a stringer case to get it included in the language.

Well, considering the IfThen functions are a rather recent addition to
the RTL, I'll assume that Borland saw the need at some level and
decided to introduce that hack to (hopefully temporarily) address the
need. Adding a ternary operator proper would be the correct solution,
and I hope Borland can see fit to add this (assuming it's not a time
consuming addition).

Will

-- 
Want a 64-bit Delphi compiler for AMD64 / IA-32e?  Vote here--
http://qc.borland.com/wc/wc.exe/details?reportid=7324


Relevant Pages

  • Re: Why does python not have a mechanism for data hiding?
    ... with the ternary operator in other languages, especially C, where it ... obfuscated than easing readability. ... In case you didn't notice, the and-or simulation is a hack, it is not ... Obfuscated Python Code Contest) to substitute it for inline if. ...
    (comp.lang.python)
  • Re: Code Behind vs not
    ... Because truly efficent code in NEVER readable, ... understanding is a result of readability. ... inline code is good for single page projects where very simple ... I prefer VS to borland in this arena). ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Why does python not have a mechanism for data hiding?
    ... But when it came to the ternary operator that was exactly the ... the primary motivation was developers experience ... obfuscated than easing readability. ...
    (comp.lang.python)
  • Re: Add a ternary operator to the language?
    ... code improved readability. ... The ternary operator was rarely used ... in any of the C code I wrote, and I've never seen Delphi code that would ... I had a uni lecturer who wrote code like that. ...
    (borland.public.delphi.non-technical)