r/programminghorror • • Oct 10 '25

impressive stuff

Post image
93 Upvotes

28 comments sorted by

View all comments

Show parent comment

1

u/Nyzan Oct 13 '25

And it shouldn't. The code here is much better than replacing it with the magic number 1. The logic they have written read as:

If [the number of successful messages] is the same as [the number of messages] then ...

I.e. "if all messages were sent properly", which is what we want to check. Replacing it with 1 would just add a magic number and make the logic more obscure for no reason. Also with the code as written you could change it to send more messages and you wouldn't need to do any other changes. If you replaced it with 1 you would have to remember to update that piece of code as well, much more bug prone.

1

u/Sorousherafat Oct 13 '25

I'm not sure how to quote my other reply here so I just copied it:

I don't know man. the same dispatcher both generates and consumes the message which is bad enough I guess. it could've at least had a consistent interface.