by mhomde · 11y ago · 0 comments
var someVar = class1.class2.SomeProp;
would return null, even if class1 was null. I have a hard time coming up with cases where you actually would want to force an exception. I realize however they reason for the new operator since they might not want to change how existing code works...
In many cases you can guarantee that the sub-property is not null and you can safely access the value. I think the proposed operator `.?` is the perfect solution and gives you the flexibility to decide what you can guarantee and how you want to access the sub-property.
But value types are a good point, either it could then set it to default(T) or not set it at all, but it kinda has to be default(T) because null makes most sense for reference types. Might give some unexpected behavior if it variables are set to 0 because of a null reference
# authenticator == null
if (authenticator.getSessionError(session) == null) {
# Assumed session is okay, actually the bug is null authenticator
}You get the feeling though many of these problems comes down to null's largely being a language defect in itself which should have been adressed differently