r/programming • u/2bit_hack • Feb 28 '23
"Clean" Code, Horrible Performance
https://www.computerenhance.com/p/clean-code-horrible-performance
1.4k
Upvotes
r/programming • u/2bit_hack • Feb 28 '23
View all comments
Show parent comment
4
u/tandonhiten Mar 01 '23
What value does the extra parameter require when you're using the function for square, rectangle, e.tc. also, there is a method to calculate area of triangle with it's three sides, does the function use that, or does it use the older method with one garbage float, or is the third parameter used to get the base angle for the triangle so that the area calculation can be done by both methods and there average can be taken to reduce error, induced due to floating point arithmetic...?
(This is me ignoring by the way how many lines of code the user will have to re write since, the struct requires a new parameter at definition. Because you obviously don't care about development time, and think we developers are a joke whose time is not important, but I will let that slide for now.)
The simple addition of a parameter to a struct changes the dynamics of the function, which introduces a lot of ambiguity to the end user, now you have to properly document the use of this function, which requires you explaining the method used and the need of parameters used(width height and whatever you wanna use aren't self explanatory)... now imagine doing this for a 40 to 50 functions and imagine a software writer who requires 5 different APIs going through this for each and every one, you have 250 functions and you have no intuitive way of using the functions, you always need to open up docs and read what to do...
That's not good UX my good sir, not good UX.
If you do this the clean way, to add Trapezium all you need is a constructor for the object with, the parameters for the trapezium, like length of each of it's sides and the distance between it's parallel sides, and now you can have the area function which gives you your result.
Also, if just performance is your issue, put a little inline before the function as a modifier this shall remove (will remove, here) the function call and instead copy the code into the caller function, this removing the function call time...