Re:Law of Demeter and immutability
by recursive on Friday September 30, 2016 @11:52AM
(#12613191)
Or use a null safe member access operator like the one in c#.
[ Parent
| on HN ]
If it's C#, you could also make Position be a struct that can't be null. Generally things like Points and Vectors are structs anyway in a lot of cases for performance reasons.
That doesn't really solve the problem. What if "x" is a nullable type (i.e. not a primitive type)?
The nulls get coalesced. In what way is it not solved?
"x" could be of a nullable type.
And the result of the entire expression is still nullable. I'm not seeing any problem.
Hm. What do you think "42 + null" is?
According to c# (the language I'm talking about) I think it's null. That seems correct to me. Arithmetic on null operands logically seems to have a null result to me. I'm not sure what you're getting at.
That's OK, I.. guess. I don't think I should even be allowed to ask the question because it's an absurd question[1]. Does that position make sense to you?
[1] Not for frivolous reasons. It's almost always nonsensical to ask this type of question with "null" values. For the sensical cases we have Maybe/Option.
I think I see what you want now. In order to get the value out, you'd have to use pattern matching or a type guard or something, inside of which you'd know there was a value.
That makes sense to me too. But compared to Maybe, a null-safe member accessing operator, along with null-lifted operators seems nearly as good from my point of view.