News for hackers. Stuff that matters.
Re:There’s No Such Thing as Clean Code by mpweiher on Friday January 28, 2022 @03:49AM (#30112218)
Hmm...polymorphism is almost invariably simpler than if/else or switch/case, so not seeing the contradiction.
Re:There’s No Such Thing as Clean Code by ajuc on Friday January 28, 2022 @03:56AM (#30112272)
I've seen this happening a lot:

- you have the same if-then-else in 3 places in code with 3 different effects

- you refactor it to polimorphism (Enum with a few overloaded methods works well in java)

- now one of these places need additional condition so you make it a little more complex

- year passes

- you have eldritch abomination of OOP instead of 3 if-then-elses with slightly different conditions because at no point someone was brave enough to refactor back into if-then-elses as the special cases piled up

Re:There’s No Such Thing as Clean Code by ziml77 on Friday January 28, 2022 @09:51AM (#30115287)
Exactly my experience with polymorphism. It starts out looking super clean but then the business requirements shift and each has its own edge cases that turn it into a giant mess, often ending up as a mix of both polymorphism and convoluted if statements.
Re:There’s No Such Thing as Clean Code by fortylove on Friday January 28, 2022 @03:54AM (#30112261)
Is that view not subjective though? Might someone think that if/else is simpler?
Re:There’s No Such Thing as Clean Code by qayxc on Friday January 28, 2022 @06:33AM (#30113373)
Depends entirely on the metric used.

Cyclomatic complexity would put if/else behind polymorphism while using lines of code and depth of inheritance would favour the if/else way.

That's the crux with software - there's not always an objectively better solution in terms readability/comprehensibility and some metrics that try to capture these qualities are inherently at odds with each other.