Re:My most common code review suggestions
by alanfranzoni on Thursday December 07, 2017 @01:36PM
(#15872678)
In Python you can subclass builtin types and override __new__. Not every method can be subclassed with success, though, because of optimizations.
I agree it's the way to go, though. My typical tiny type in Python just has preconditions on string content.
In general I lack the Smalltalk ideal of being able to subclass any type, like 'Int', call it something new and attach behaviour to it, while preserving API & DB compatibility.
Type aliasing in F#, ie `type Customer = int`, or discriminated unions with the same info, like `type CustomerId = CustomerId of int`, are wonderfully useful in that regard.