logoalt Hacker News

ninkendo • today at 7:11 PM • 1 reply • view on HN

Objective-C has implementation inheritance but doesn't have constructors, I don't think constructors are essential there. As I said in the OP, `Cow::new()` can easily just call `Animal::new()` before continuing to initialize its own fields, etc.

Heck, Smalltalk is the original OOP language and has implementation-based inheritance, and construction is done through ordinary methods on class objects.


Replies

layer8 • today at 7:28 PM

Objective-C plays it fast and loose here. It doesn’t enforce object initialization, hence client code including subclasses can create and use uninitialized instances.

Smalltalk is even worse, but it also has the philosophy that anything can be patched at runtime, so it kind of is in line with that.

This is basically about static type safety.

You could in principle enforce proper initialization and encapsulation by static analysis requirements instead of by a dedicated language construct. The latter is traditionally more efficient however, and arguably makes the code more explicit about its intent.