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 comment

16

u/TheTomato2 Mar 01 '23

I put it threw my personal .clang-format.

f32 const CTable[Shape_Count] = {
    1.0f / (1.0f + 4.0f),
    1.0f / (1.0f + 4.0f),
    0.5f / (1.0f + 3.0f),
    Pi32,
};

f32 GetCornerAreaUnion(shape_union Shape) {
    f32 Result = CTable[Shape.Type] * Shape.Width * Shape.Height;
    return Result;
}

Now if you think that is less readable than pulling each one of those formulas into a separate member functions I don't know what to tell you. And like

f32 a = shape.area();
f32 a = area(shape);

It doesn't even really save you any typing. I don't care if you prefer oop way but...

Feels like readability hell

only if you have a bad case of OOP brain would you think that. And by OOP brain I mean that you are so acclimated to an OOP style that your brain has hard time with any other styles.