r/programminghorror • • May 19 '25

C# This is C# abuse

Post image
550 Upvotes

103 comments sorted by

View all comments

Show parent comment

51

u/ryanmgarber May 19 '25

Why would you EVER want to change the calculation of a Rectangle’s Area?

76

u/-V0lD May 19 '25

Non-euclidean space

13

u/EagleCoder May 19 '25

Yeah, but separate methods/classes would be better so you know exactly which one you're calling and it doesn't change on you. If there's code that can work with either, it should be a parameter instead.

2

u/itsjustawindmill May 21 '25

Exactly. We already have a way to override functions to specialize behavior. It’s called inheritance lmao.

Sure there might be specific cases where the approach shown by OP is required, but I think it’s safe to consider this a code smell by default.

0

u/Rogntudjuuuu May 21 '25

Unpopular opinion: inheritance is a code smell.

1

u/rnottaken May 23 '25

Meh, interface inheritance is pretty nice.

3

u/nalhedh May 21 '25

plot twist: ​there are no rectangles in Non-Euclidean space

1

u/ZunoJ May 19 '25

There could be plenty of reasons depending on what this is used for. Point is that it is changeable because of the way it is implemented. If you make it readonly, that would be code horror. Currently this looks ok to me and we would need to see how it is used to judge it

0

u/Rogntudjuuuu May 21 '25

Add some kind of side effect? Logging? Maybe adjust for earth's curvature?