logoalt Hacker News

taybintoday at 3:39 PM7 repliesview on HN

Yes, a toy problem only needs a simple implementation. This is a straw man. And I don't even like Robert Martin's Clean Code, but the author is not addressing where this style actually provides benefits. When you're updating 23 if-statements because you had to add support for some new business workflow, you'll wish you had a conceptual entity that encapsulated the operations on the type of workflows so you just had to implement them in one place.


Replies

hyperbolablablatoday at 8:43 PM

This is the author's gripe, though. You're sacrificing end user experience for developer ergonomics.

show 1 reply
alerighitoday at 4:31 PM

Indeed. The problem is trying to apply the principles of "Clean Code" or more generally of OOP everywhere. There are surely cases where having an interface as an abstraction and multiple implementations makes sense. There are case where it doesn't, and if you take as a dogma "everything shall be the implementation of an interface" you get more complex code and performance penalty for nothing.

There is nothing wrong with having procedural code with a switch case, as there is nothing wrong in having global variables, in having even goto, depends on how you use it.

show 3 replies
HeavyStormtoday at 4:00 PM

Thank you! I always see this stupid conversation about performance and nobody seems to get this.

show 2 replies
leecommamichaeltoday at 7:17 PM

> you'll wish you had a conceptual entity that encapsulated the operations on the type of workflows so you just had to implement them in one place.

Why have you drawn the conclusion that the author is against this? A function with a switch-statement can do this.

show 1 reply
wasmpersontoday at 5:18 PM

> When you're updating 23 if-statements because you had to add support for some new business workflow, you'll wish you had a conceptual entity that encapsulated the operations on the type of workflows so you just had to implement them in one place.

Polymorphism won't get rid of the 23 if statements, it will just replace them with 23 method implementations. Then when you try to serialize that "conceptual entity" to a file or network socket you'll yearn for the if statements once more.

The main benefit of polymorphism is that it allows you to modify one part of a program without recompiling the other parts. In the absence of pre-compiled modules, polymorphism is isomorphic to branching/switch statements:

https://en.wikipedia.org/wiki/Expression_problem

jacklingtoday at 4:29 PM

It's a problem chosen by the author of Clean Code. How is it a strawman? The author of the article is directly refuting the style of the problem/solution that the original author chose, and arguably demonstrated a better approach. That is not a strawman.

show 1 reply