5 ms·
What exactly would "well commented" mean for fizz buzz? One of my pet peeves are devs that comment insane things that should be obvious from reading the code.
by tjarratt 15y ago
What exactly would "well commented" mean for fizz buzz? One of my pet peeves are devs that comment insane things that should be obvious from reading the code.
eg:
#save the model and pass along a callback
model.save(callback)
If you were writing code that was as simple as fizz buzz, would you really write any comments at all?
- danielharan 15y agoExactly. That kind of comment is worse than useless. I'd rather see tests than comments.
- 16s 15y agoJust my opinion, but here are my comments to FizzBuzz. https://github.com/16s/FizzBuzz/blob/master/FizzBuzz.cpp https://github.com/16s/FizzBuzz/blob/master/FizzBuzz.cpp
- BSousa 15y agoA few notes on this: 1) and keyword for c++ ? It has been a while since I used C++ but it used to be &&. Did it change (I'm actually asking, not being sarcastic). 2) on the 'else if' parts, you only need to do one evaluation (the == part) since the first if tests for both % 3 and % 5 so no need to do != on % 3 or % 5 as you know it will never be true. 3) honestly, I think the comments make it worst. If a programmer doesn't know by just looking at the code what it does, no amount of comments will help him.
- Confusion 15y agoI don't think those comments are very helpful. I think a function-level comment would be much clearer. # Outputs 'Fizz' when +arg+ is divisible by 3, 'Buzz' when # it is divisible by 5 and 'FizzBuzz' when it is divisible # by both 3 and 5.
- 16s 15y agoThat's a matter of opinion. I always do this. Now there is no question what each conditional is intended to do. So if I make a mistake, you can clearly see from the conditional comment what I meant to do.