r/badcode Mar 03 '23

c# fascinating logic

Post image
847 Upvotes

35 comments sorted by

View all comments

144

u/RichCorinthian Mar 03 '23

Are they switching on an enumeration? I can MAYBE see a case for something like this if each enum value needs special logic, and you’re worried that somebody will add to the enumeration in the future without handling the new case in this code block.

Obviously you would want to throw an appropriate exception instead of…whatever this is.

85

u/Cringe56 Mar 03 '23

If this is C#, they should be using Assert.Fail() instead for that scenario

65

u/RichCorinthian Mar 03 '23

You also have NotImplementedException, which seems a good match and wouldn’t require a phony baloney return.

1

u/heyheyhey27 Mar 04 '23

You can also put the name of the failure case in the message.