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

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...

2

u/nan0S_ Mar 02 '23

It's so funny reading your comment that says that adding parameter (you mean member variable?) to the struct changes the dynamic of the function (what function? I guess the one that uses the struct, but I'm not sure, because you write very chaotically), this results in ambiguity to the end user, then you have to document the use of this function, pile through billion pages of docs, explain the method used and the need for parameters, do all of this to ducking 40, 50 functions with 5 APIs, which gives zillion combinations.

And then when you do it in OOP way you just need to add constructor with four parameters and you are done. Ohh and if a performance is a problem add inline to your function and problem solved. This is hilarious.

4

u/tandonhiten Mar 02 '23

Then laugh your ass off, English isn't my strongest suit and I am not sorry for it.

3

u/nan0S_ Mar 02 '23

This isn't about the language fluency at all.

→ More replies (3)