3 ms·
Functions are evil in some languages (C++, Java) because they can't be overridden or customized with virtual methods. In functional languages that don't need po
by dustingetz 11y ago
Functions are evil in some languages (C++, Java) because they can't be overridden or customized with virtual methods. In functional languages that don't need polymorphism as much, it's because you can accomplish similar effect with heavy use of higher order functions, which is something that is impractical to do in many OO languages. Functional languages also have their own set of rough edges, FP langauges force an OO programmer to look at a lot of concepts (objects, polymorphism, mutability, encapsulation) in a new light, as they are applied quite differently when you start leaning on functions so heavily. I think if one is in an OO language like Java and starts using static methods everywhere, you end up in a half-way danger zone which can be extremely painful down the road.
Anyway, beware challenging conventional wisdom, it evolved due to past pain and gets passed down generations to avoid that pain, even if the reason is not well understood anymore.
- lawpoop 11y agoFor the 'best practice' to work, you'd have to make your object accept an interface, in order to be able to accept one with the overridden function that you want, correct? I think this is the problem with the received-but-not-understood wisdom -- the implementers don't actually use an interface but hard-code the class that has the method, so it's not any more over-rideable than a regular function call.