On Friday, 28 February 2014 at 11:11:28 UTC, Dicebot wrote:
On Friday, 28 February 2014 at 09:24:23 UTC, John Colvin wrote:
Chaining . operation is a code smell to begin with
It is? Why?
If a system is well-designed, then "null" state either means
something (and needs to be explicitly handled) or is not
possible.
?. provides simple and easy way to write a sloppy code that
does not tell the reader if resulting code flow for null case
was intentional. Also it is very easy to get accustomed to use
?. everywhere instead of . and get broken logic instead of
NullPointerException for cases when pointer is wrongly assumed
to never be null.
Do you mean:
Chaining operations that can return null (or some other
known-to-be-invalid state) is a code-smell.
That's quite different to saying:
Chaining operations using . is a code-smell.
which is what deadalnix said.
Either way, a do-this-if-you-can pattern is quite reasonable IMO.
However, I do question whether it's common enough to justify
syntax sugar.