Yea or Nay? Thoughts? <https://twitter.com/pablisc...
# announcements
p
🚫 5
πŸ‘ 7
I’m genuinely curious, why 🚫?
l
I would use simple
if
here, so there is no need for doNothing() at all πŸ™‚
βž• 2
p
@littlelightcz What if we had more than two cases?
l
Or from philosophical point of view (of a lazy programmer): "Why would you need to type something to *do nothing*" - in this case not typing at all is a better option 😁
In more than two cases you could skip the
else
branch all together - in your original code snippet (I think)
i
doNothing
can be helpful if you want to find later all places in code where you do nothing. However not sure why one would want that.
p
@littlelightcz For future reading comprehension? Beats having an ugly comment. πŸ˜„
l
@ilya.gorbunov: Interesting πŸ™‚. Anyway I never wanted that yet 😁
a
@littlelightcz because your current or new team mates might not be in the same context as you and understand why there's an empty case. It also favours reasoning about having an empty case at all, because you might be discovering you encoded your adts in the wrong way, for example
☝️ 5
l
@aballano: valid point πŸ™‚ . I think I would go with a comment anyway since this happens really rarely, because most of the times, the clean code documents itself πŸ˜‰ 😁 (no comments needed)
s
That’s what commit messages are for, isn’t it? To describe the whys and the whats of your code
p
@sergio250 Until that file is moved somewhere else πŸ™ƒ
βž• 1
s
You can still keep track of that with commit messages 😐
a
@sergio250 depending on the size of the project you might be seeing yourself in a deep pit of file moves, renamings, refactors, etc until you find the original author of that piece of code, not very handy for a day-to-day use I'd say 🀷
@littlelightcz A comment is a perfectly valid alternative, although in my opinion making your IDEs autoformat to put them in a nice and readable way is usually a bit cumbersome as it tends to get reformatted πŸ˜• I'm also a fan of reading ADTS/Sealed classes all over the place so it's still my perspective πŸ˜„
j
To be fair I think what @sergio250 is referring here is that ideally you'd want to avoid polluting your codebase with comments like "this is done like this because of this, or because of that", since comments in any form can get outdated pretty easily. Ideally git history never lies and would tell you about all those details, if done well. But that's on ideal terms ofc, until you join a company where git history is a total mess and you can't get people to write a proper commit message right away. So like everything else, to me it'd depend on circumstances. Overall if possible I'd personally avoid if statements without else in any way, that's side effecty and biased. I'd always want to know why the else option is unhandled, otherwise reasoning about code becomes painful since it's not deterministic. Same reasons for using exhaustive when statements as much as possible.
πŸ‘ 1
p
Yeah sure, like rise your hand if you go straight to the commit messages every time your wondering code, come on! πŸ˜‚
πŸ–οΈ 2
πŸ˜‚ 1