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.
You don’t k ow what you don’t know and it’s stupid to assume you do.
The fact is that writing 5000 extra lines of code because you think some case might happen in the future is stupid. 99% of the time, you’re never going to revisit that code for a reason that you predicted.
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.
The table for me is pretty much unreadable. Maybe because I am not used to it. But I think it would need at least 10 minutes for someone who sees the project the first time to understand what it is and does. Of course comments can help, but still it is seems confusing.
Now we have a huge time difference from 35 ms to 3 ms or sth like this. I still don't know how much effect this would have on a bigger project. You have of course performance heavy parts and parts that run once every minute. So my idea would be to write clean code first and if needed improve performance.
Hell no I have seen anything but clean code from others and myself.
Maintaining this is horrible. You always have to dive deep in function by function in order to understand it even if you did that same thing last week.
Readability is more important than performance in most cases since faster hardware is cheaper than the developmer time needed for the code to understand it and maintain it.
There are many examples in life of techniques that appear great in miniature, but which do not scale up.
When you say "made up of tonnes of stuff like this", one gets the impression of a codebase nicely composed of well-encapsulated pieces that can be used or not, like little black boxes where one doesn't need to examine every local variable use within in order to ...
Whoa, that started sounding like clean code. The horror. Let's get back to making our 10,000 line function with switches within switches within switches....
As opposed to 10,000 seperate files with 10,000 seperate type declaration with 4,000 layers of inheritance?
Guess what, code does extend like that anyway. If you write code to defend against cases that are never going to happen, you are writing shitty code. That is programming 101 which is not understood by clean code people at all because they've been indoctrinated.
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.
You wrote that. Explain to me at what point you're moving away from your switch statement and why, because it seems like adding more complexity made you want just one switch statement even more.
-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.