4 ms·
I'd suggest that OOP has it's niche. Primarily it's a methodology for limiting the effects of changing state while keeping the codebase performant. Removing sta
by weavejester 6y ago
I'd suggest that OOP has it's niche. Primarily it's a methodology for limiting the effects of changing state while keeping the codebase performant. Removing state where possible is obviously going to be the safer course of action, but immutable data structures are not as efficient as their mutable cousins. This may not matter for much software, but where it does, OOP isn't the worst solution when used selectively.
The problem with OOP in 2021 is that it tends to be the default, when arguably starting from safety and working back toward performance would be a better approach.
- millstone 6y ago"Safety" and "performance" are not always the most important considerations. For example, Apple uses OOP so that its frameworks can evolve without breaking client apps. NSDictionary is a dynamic object because it permits the implementation to be changed or replaced, and this comes at a cost of performance.
- weavejester 6y agoPolymorphism isn't a trait unique to OOP; most, if not all, FP languages have that as well.
- millstone 6y agoRight. But OOP makes it central, and builds around it, while FP de-emphasizes it in preference to ADTs. Strings are a good illustration. Instead of an abstract polymorphic String type, Haskell provided a concrete String type as an ADT. This proved too inflexible, which is why we have Text, lazy Text, ShortText, etc. Compare to NSString which also has multiple representations but hides them behind a single polymorphic interface.
- javcasas 6y agoOr you use -XOverloadedStrings and then you also have in Haskell multiple representations that follow a single polymorphic interface.
- millstone 6y agoIt does not. -XOverloadedStrings unlocks `fromString :: String -> a.` That is not a polymorphic string interface; it's just syntax sugar for making something else from a string literal.
- jose_zap 6y agoThis sounds like haskell’s backpack, which lets you swap implementations of a model interface at will. But maybe I’m misunderstanding what you meant. Polymorphism is front an central to everything in Haskell, which is why your comment sound off to me.
- weavejester 6y ago"OOP makes it central, and builds around it, while FP de-emphasizes it in preference to ADTs." ADTs are not an intrinsic part of FP, as not all FP languages even have them. I'd also question whether ubiquitous polymorphism is overall a good thing in a language, or whether it's misguided complexity. In most OOP languages, any public method can be polymorphic, but a polymorphic function is inherently less predictable than one dispatches off a single type.