3 ms·
Yeah, it looks a lot cleaner - but if you make that code available as a library then other people can't add new shapes easily, or deal with shapes that have mor
by AndrewDucker 12y ago
Yeah, it looks a lot cleaner - but if you make that code available as a library then other people can't add new shapes easily, or deal with shapes that have more than one length (e.g. a rectangle, which has two).
- wwosik 12y agoThat comment about shapes with more than one defining size property is very valid.
- couchand 12y agoWell, yes, you can add a rectangle quite easily: type Shape = | Circle of float | Square of float | Rectangle of float * float The thought about adding new shapes (mentioned several times in this thread) is just misplaced. If you're releasing library code people should not be extending your built-in types, that's bad form -- consumers of a library should interact with it through interfaces only.
- ufo 12y agoThe flipside is that its very easy for your library users write a new function that takes a Shape as a parameter. If you model things with a class hierarchy its easy to add a new Shape subclass but you can't add any new methods to the Shape interface.