C# is getting “?.”, sometimes called the Safe Navigation Operator
1–10 of 12 posts
Re: C# is getting “?.”, sometimes called the Safe Navigation Operator
#2Re: C# is getting “?.”, sometimes called the Safe Navigation Operator
#3The question I have about this: Does making it easy to do parent?.child?.grandchild?.property help or hinder the software development process in the long term?
Re: C# is getting “?.”, sometimes called the Safe Navigation Operator
#4The question I have about this: Does making it easy to do parent?.child?.grandchild?.property help or hinder the software development process in the long term?
Re: C# is getting “?.”, sometimes called the Safe Navigation Operator
#5The question I have about this: Does making it easy to do parent?.child?.grandchild?.property help or hinder the software development process in the long term?
This will help getting rid of the Maybe monad pattern in our code (at least partially) - all patterns are patches for missing language features. I cannot see any drawbacks personally. Would much rather prefer the 'object! paramName' not-null enforcement operator though, but it is tricky to make it backwards-compatible.
Re: C# is getting “?.”, sometimes called the Safe Navigation Operator
#6The question I have about this: Does making it easy to do parent?.child?.grandchild?.property help or hinder the software development process in the long term?
Re: C# is getting “?.”, sometimes called the Safe Navigation Operator
#7The question I have about this: Does making it easy to do parent?.child?.grandchild?.property help or hinder the software development process in the long term?
Re: C# is getting “?.”, sometimes called the Safe Navigation Operator
#8The question I have about this: Does making it easy to do parent?.child?.grandchild?.property help or hinder the software development process in the long term?
The ?. has only really worked in scripting, i.e. writing quick scripts to manipulate code written in a proper type-checked programming language. Groovy has it but Java doesn't. In Groovy's heyday if some code spewed out NullPointerException, the first thing people did was replace all the . with ?. and run it again, because the code was throwable quality anyway. I can't imagine anything good will come of putting ?. in…
var = foo()?.bar?.bing()
if(foo==null){...}
instead of putting a null check between every call. In many cases null is used to indicate that a computation failed. If you are doing a chain of computations, there is often not a reason you need or want to do a check between every computation, instead of having a single handler at the end for if any of them fail.This pattern comes up fairly often in Haskell, which accomplishes it with the Maybe monad.
Re: C# is getting “?.”, sometimes called the Safe Navigation Operator
#9Earlier quoted context omitted.
The ?. has only really worked in scripting, i.e. writing quick scripts to manipulate code written in a proper type-checked programming language. Groovy has it but Java doesn't. In Groovy's heyday if some code spewed out NullPointerException, the first thing people did was replace all the . with ?. and run it again, because the code was throwable quality anyway. I can't imagine anything good will come of putting ?. in…
Using ?. lets you do code like: var = foo()?.bar?.bing() if(foo==null){...} instead of putting a null check between every call. In many cases null is used to indicate that a computation failed. If you are doing a chain of computations, there is often not a reason you need or want to do a check between every computation, instead of having a single handler at the end for if any of them fail. This pattern comes up fairl…
It's not always so cut and dry, and there are situations where this is a very valuable tool. I just feel that down the road if you feel like there is a valid reason for refactoring object hierarchy that you'll potentially be doing yourself (or those that follow) a disservice in the long run.
Re: C# is getting “?.”, sometimes called the Safe Navigation Operator
#10The question I have about this: Does making it easy to do parent?.child?.grandchild?.property help or hinder the software development process in the long term?
The ?. has only really worked in scripting, i.e. writing quick scripts to manipulate code written in a proper type-checked programming language. Groovy has it but Java doesn't. In Groovy's heyday if some code spewed out NullPointerException, the first thing people did was replace all the . with ?. and run it again, because the code was throwable quality anyway. I can't imagine anything good will come of putting ?. in…