Raymond Genovese
- Joined Mar 5, 2016
- 1,653
As far as the utility or efficiency of the shorthand version, I don't know - maybe @WBahn can provide some details.I'm curious about that method. As a novice, I prefer the more verbose if-then-else statements, but I'm interested in knowing the pros and cons.
I imagine with experience, the conditional operator will become easier for me to read quickly, but it's hard to imagine it would ever be as intuitive as if-then-else. The whitespace and indentations that typically go with ifs are easy on the eyes!
On the other hand, if there are performance benefits to the more compact conditional operator, it would be good to know that too.
I must confess, when I first saw @WBahn's code, it looked like it must be a magic trick - how could it possibly work while being so small? Once I recognized that there are three separate conditionals embedded in 1 line of code, it was a little easier to understand, but it's still impressively compact and efficient.
I really like the use of a character array instead of more conditionals to decode the results of the modulo function into individual characters. Wish I had thought of that myself.
As usual, this is a great forum, exposing me to new ideas and different approaches all the time!
I agree that it is good to be able to see/unpack the conditionals...as you say. While it, of course, pains me greatly to admit it - YES, his code is nice and tight....pity he (but not you or I) missed the very first instruction as the OP stated:
Ok, I am just fooling around and not that any of the code posted qualifies, you might get a kick out of the the old C obfuscation contests that I used to see - wow talk about WTF moments!1. The program must ask how many rows the triangle will have.