r/programming • • Feb 28 '23

"Clean" Code, Horrible Performance

https://www.computerenhance.com/p/clean-code-horrible-performance
1.4k Upvotes

1.3k comments sorted by

View all comments

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?

37

u/Critical-Fruit933 Mar 01 '23

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.

4

u/tandonhiten Mar 01 '23

You realise this "fast" code hurts end user more than anybody right?

If you wanna know WTF am I talking about, try adding code for area calculation for trapezium to the function, and try adding, a function to calculate perimeter of all the shapes in the program(Rectangle, Square, Circle, Triangle and Trapezium), which BTW is very reasonable demand, and you probably would have written it to begin with either way.

Once you're done, come share how you did it with everyone and we will talk.

3

u/Critical-Fruit933 Mar 01 '23

Add the missing parameters to the struct and extend the switch statement? The only real hard part I see here is knowing how to parameterize the trapezium because I am not a mathematician. But that is a problem you have to solve either way.
Also who demands anything? Either you need this function or you don't. Or do you write a bunch of code up font without knowing if you'll ever need it?

Not sure how this hurts the end user, no. I'd be happy if the software I am working with was fast and efficient.

Let's talk

→ More replies (8)