CodeDmitry wrote > Why don't Smalltalk or Smalltalklike languages have checked interfaces? > The compilation occurs at runtime but it is still technically a > compilation, why don't languages allow implementing interfaces at runtime? > The type information is there, and the source can load the list of > messages expected and check if the compiled class contains all members or > removes it and throws an exception. Is this just too expensive?
Because you never do a batched class def + all methods compilation, which would be the proper place to raise an exception that you're missing something, in a normal Smalltalk workflow. First you compile a class definition, then you add/compile methods defining instance behaviour of that class. Instead, a good code critic will inform you if there are subclassResponsibilities remaining to be defined. If you disregard that, and actually try to use the method on an instance, you get the runtime exception instead. Also, traits can work as a sort-of-interface with behaviour defined ala abstract classes like Boolean, with the benefit that they are not restricted by class hierarchy, and the downside that the behaviour they define, can't access any state directly. Interfaces in other languages often feel somewhat self-defeating in my mind other than as a way to satisfy the typing system; the API you want polymorphic across implementors is usually a high-level one (akin to the protocol in Boolean sans subclassResponsibilities), while the state that actually needs to be different, is (usually) rather low-level. So if you use an API interface across class hierarchies, copy pasta is inevitable, while if you stay within a single hierarchy, what do you need the interface for anyways? If you instead define/share the low level interface that actually needs to differ, the temptation of adding Helper Classes containing the actual behaviour, and all of a sudden, you've split state and behaviour. At which point you've avoided duplication of code, but you can't really call it OO any more either. Cheers, Henry -- View this message in context: http://forum.world.st/How-does-Boolean-ifTrue-work-tp4920873p4921198.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.