3 ms·
I think nil/null is a symptom of the real issue: the language permits partially constructed data types, so it has to assign something. That's a consequence of
by ben509 6y ago
I think nil/null is a symptom of the real issue: the language permits partially constructed data types, so it has to assign something.
That's a consequence of the "always mutable" model whereby the responsibility of initialization can be shared by the object constructor and the caller.
But there are many cases where it's very intuitive for the caller to set up an object, especially in the objects as actors model.
I think to make that work, you'd want to track the evolution of the object's state, especially noting when all fields have defined values.
- frenchy 6y agoFor what it's worth, it's more ceremony, but you can work fine with partially constructed data types without null, it's just that the nature of their construction either needs to encoded int the types directly, or they need to be initially constructed with defaults and you need to decide if you want them to explode/panic if they're not completed, or just return potentially unexpected defaults. I've seen all these approaches in Rust.
- higerordermap 6y agoI don't think mutability is problem here. Many imperative languages don't have null.
- masklinn 6y ago> That's a consequence of the "always mutable" model whereby the responsibility of initialization can be shared by the object constructor and the caller. It's not though. An "always mutable" model can require that objects be fully initialised up-front. Rust does exactly that.