In the languages like python, ruby, javascript, there is separate syntax for single-line and multi-line comments. I don't see the benefit of this complexity. Why, from a language design perspective, is there a distinction between the two? Using javascript as an example, here's the implementation:
// I'm a single-line comment!
/*
I'm a
multi-line
comment
*/
Why not simply (something like):
/* Just a comment */
/*
Doesn't matter
how many
lines
/*
Commenting out a single line is faster when there’s only one change to make.
There are languages that only support comments with a starting and ending delimiter — C89 is a notable example (ever think C99 added // for a reason?). However, using the same starting and ending character would make a complete mess if you forgot to take one (or the other) out. Every comment following it would be flipped, and how would the compiler (if it’s a somewhat helpful one) know where the syntax error was?
One possible answer is that single-line comments are faster to add. For example, in JS you need 2 special characters to add single-line comment and 4 to add multi-line comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With