P is for Practical | |
PerlMonks |
Re^3: Ternary operators: a hinderance, not a helpby fizbin (Chaplain) |
on Aug 09, 2005 at 20:55 UTC ( [id://482426]=note: print w/replies, xml ) | Need Help?? |
I think that what you may be missing is that vertical space savings often enhance readability in terms of making it possible to see the whole forest at once. In the same vein, I've seen (mostly beginning C++) people say that printf-formatted strings are too much like line noise, and everything should really be formatted through the expressive cout format, with operators to change the number of digits of precision, etc. The same people might well complain about pack. The common lisp community often fields complaints about how terribly obscure the syntax is to format. The point is that compressing stuff that's not terribly important to understanding the whole improves understanding of the code overall. Good code should read like stuff you want to read, and my eyes glaze over with too much pointless verbosity. (Usually, my eyes glazing is a sign that the code I'm reading suffers from severe cut-and-paste and really needs to be refactored to deal with multiple cases in a more generic fashion.) You've obviously encountered several bad uses of the ?: operator. Allow me to present at least one good one: Now in this case I'm sure you could do: But I think that the first version is easier - or at least, faster - to read. (more whitespace per bit of meaning) And code that's faster to read is more likely to get read in full before someone makes changes to it. (Yeah, I'm just getting around to reading book 6 now)
In Section
Meditations
|
|