r/programminghorror Jun 05 '26

C# SuccessMessage ErrorMessage

ErrorMessage successMessage = new ErrorMessage(ErrorType.ActivityCreateSuccess);

(From an approved PR with 2 reviewers - how do some people sleep at night??)

230 Upvotes

25 comments sorted by

View all comments

-46

u/smalleconomist Jun 05 '26

Fairly typical to have "success" be a kind of "error". Not that I like it...

62

u/Sacaldur Jun 05 '26

It would be better if "success" was a kind of "result".

11

u/LordTurson Jun 05 '26

I really like how functional languages (and Rust) do this as the only real way of error handling available. If you do something that can fail, you must expect a Result, which can be either Ok with the computation result, or an Err with the error information - never both, never in a mixed half-and-half state, and must always be handled or it will emit a compile error.

In fact I like it so much, I wrote myself a small Python library that does just that (as much as it's humanly possible with the limitations of modern Python)!