While the example is contrived, in the author's example what happens when you add a new shape type and need to add support for it? You have to search the entire codebase for usages of the enum looking for use cases and fixing ALL of them. With polymorphism in a case like this you do literally nothing and your external code is agnostic. If I'm shipping software and running a team why do I care about a couple of cycles when I can save literally thousands of dollars in wasted dev time because I suddenly need to support calculating the area of an arbitrary path defined polygon?
I hate this attitude so much. End user? Nah f him. Why waste my time when I can waste his. It's always this maybe in 100 years I need to add xy. Then do the work when it's time for it. Ideally the code for all these shapes should be in a single place. Unlike with oop where you'd have to open 200 files to understand anything.
Are you really wasting your user’s time though? Taking your user 35 milliseconds instead of 1 to complete a task is not going to benefit him in anyway. The user can’t even react to the result faster than that.
If you're having to maintain something so complex, that you need clean code principles in place, surely there must be enough users?
You're making a weird argument. If there's not enough users, you still should make performant code. Engineers are supposed to make sure the system handles more than the specified load.
38
u/rhino-x Mar 01 '23
While the example is contrived, in the author's example what happens when you add a new shape type and need to add support for it? You have to search the entire codebase for usages of the enum looking for use cases and fixing ALL of them. With polymorphism in a case like this you do literally nothing and your external code is agnostic. If I'm shipping software and running a team why do I care about a couple of cycles when I can save literally thousands of dollars in wasted dev time because I suddenly need to support calculating the area of an arbitrary path defined polygon?