5 ms·
Yes, I suppose null references are only a problem if you are unable to write a conditional statement.
by itronitron 4y ago
Yes, I suppose null references are only a problem if you are unable to write a conditional statement.
- josephg 4y agoThe problem with null references is you have to write those conditional statements everywhere, otherwise your program might crash. You generally know as the programmer which pointers you expect to be nullable and which should always be an object. But the compiler has no idea, so it can’t help make sure you have null checks in all the places you need them.
- GoblinSlayer 4y agoAnd what to do if null check fails? Call abort()?
- tadfisher 4y agonull references are a problem when: - null is a valid member of every type - there's no way to constrain a reference to only non-null members of the referenced type - the compiler allows dereferencing values of a nullable type Weirdly, all three are true of C, C++ and Java.
- GoblinSlayer 4y agoNull is a valid member of every type only in Java. C and C++ have value types.