4 ms·
How would one do inline comments without block comments? I don't know if Python's triple-quote can be used inline, but otherwise that seems like a good solutio
by iiv 9y ago
How would one do inline comments without block comments?
I don't know if Python's triple-quote can be used inline, but otherwise that seems like a good solution. I am not entirely familiar with Python comments, does any of his arguments apply to triple-quotes?
- beojan 9y agoTriple-quotes are string literals, not comments. It's just that a string literal at the start of a function, file, or class is a docstring.
- simias 9y agoYou mean comments in the middle of a line of code? I don't think I've ever done that (and I write a lot of C which would allow it). Seems like a readability nightmare to me, even with proper syntax highlighting. I guess it could be useful if you want to temporarily debug the middle of a line for debugging purposes but in this case you could just add a line break if blockquote didn't exist. That being said I don't feel very strongly about this topic, I let emacs handle the commenting for me so I never really have issues with nested comments. Besides commenting comments is probably only useful for temporary debugging. I do feel strongly about people committing commented/dead code however, it's just distracting and misleading. Nowadays versioning your code is just one `git init` away so nobody should be worried about keeping old dead code "just in case". Sample code is acceptable however, I like Rust's approach where commented sample code can actually be tested to make sure it's up to date.
- chrismorgan 9y agoI view inline comments as a code smell in most languages; I can’t think off-hand of having seen even one occasion where the code couldn’t be tweaked into another nicer form that didn’t depend on inline comments.
- umbrai_nation 9y agoI use them with functions that have too many arguments. It's not always feasible to fix the problem at the source. damageDealt = calcDamage(weaponType, monsterType, DamageType.FIRE, null /* specialEffectFlags /, false / hasMagicTargeting */ ); It's definitely a code smell, but it's much better than nothing and I'm always glad to see these comments when I come back to the code.
- chrismorgan 9y agoYeah, that was the closest I could think of. But in Python you’d use keyword arguments, and in JavaScript you’d use objects with named fields in lieu of that, and in Rust you’d commonly try to use struct fields or custom enums for such things (I still want named arguments there). The extreme in your case would be `hasMagicTargeting = false` and then pass `hasMagicTargeting` instead of `false`.
- ragebol 9y agoYes, that is very well possible. However, I do not recommend using triple-quotes for comments, as git diff only shows 2 lines with quotes while the actual difference is much bigger.