No I write c# all day and know each of the techniques you’ve listed. It’s not that debugging it is particularly difficult, I just don’t appreciate the uncertainty it brings with it. There’s nothing wrong with a differing opinion and I respect yours
I guess I'm just not certain why you think it brings more uncertainty, the expression is either null, or the fully evaluated nested expression, there isn't an inbetween. In most cases I've found safe navigation brings both clarity and readability to what would otherwise be a very nested/chained Boolean expression (exactly what most people in js have to do). You stated it was awkward to debug, but then said it's not the debugging. I guess I tend to think that if someone new to c# or .net, or development in general would cone across your post, that is the response I would give.
I would agree there a situations that people can go a little over the top with them and sometimes a single if statement adds more clarity, but I think that is then an incorrect use of the safe navigation. All said though, it is a small price to pay over the added security of knowing your application is less likely to throw null reference exceptions. Adding it to the js spec would further js robustness, "being liberal in what you accept and strict in what you do". It makes it easier and cleaner for developers to account for situations where objects are unset, even if they are supposed to be under normal conditions.
Let's not get it twisted: the simplicity is in syntax only. Cyclomatic complexity checkers still report each ?. as a branch because they ultimately expand out to a deeply-nested if statement (technically deeply-nested ternaries since they're expressions). Add to that the fact that people use them multiple times per function, and quickly the execution path becomes deceptively complex.
Right, but without the syntactic sugar, I've seen plenty of situations where developers simply don't do the checks, and then null reference exceptions litter the logs. It makes devs more likely to account for the potential null.
1
u/Koala_T_User Feb 20 '18
No I write c# all day and know each of the techniques you’ve listed. It’s not that debugging it is particularly difficult, I just don’t appreciate the uncertainty it brings with it. There’s nothing wrong with a differing opinion and I respect yours