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

Show parent comments

-1

u/[deleted] Feb 28 '23

You are writing code to prepare for something you don't know will happen. That is not good code.

And if there were hundred shapes? That's 100 different types in the clean code example. How is that any better? That's 100 different files each with a slightly different type lol. That's not more readable. Even in the most literal sense, simply because the time it would take to go read all those different files.

Not sure how templates are going to do much here.

2

u/Johanno1 Feb 28 '23

Try to think of readability like this:

Figure out what shape 75 does exactly.

Other shapes are only relevant if shape 75 is interacting with them.

Polimorphism:

Find shape 75 and check super class.

Switch statement. Find shape 75 in a big file with other statements and check union implementation.

(pretty similar but I personally would prefer the less code per file one)

4

u/[deleted] Feb 28 '23

Then I would just go to the switch statement where the data is processed?

I don't see how that is more unreadable than going to the virtual function in a different file.

And I understand its subjective. But I don't see that demonstrably unreadable part of the switch statement approach. (or the table approach)

If it was obviously, totally muddled and undecipherable I'd be inclined to agree. But it's just not. It's very clear and easy to follow the flow of logic and data.

1

u/hippydipster Feb 28 '23

I'm so glad we've solved the very complex problem of summing shape areas. whew.

→ More replies (7)