Question:
Why, in code, is there a tendency to use multiple // instead of a /**/ when writing multi-line comments?
Caleb
2017-06-18 19:21:42 UTC
Why, in code, is there a tendency to use multiple // instead of a /**/ when writing multi-line comments?
Eleven answers:
anonymous
2017-06-24 17:45:58 UTC
do not know sorry
willi
2017-06-24 14:49:13 UTC
Just habit and what is easier at the time.
?
2017-06-23 03:46:09 UTC
form preference
PoohBearPenguin
2017-06-22 21:58:46 UTC
Style.



When I was first learning programming, there wasn't a multi-line comment, so I'm accustomed to using single-line comments for things like documentation. Some programming languages still don't have this feature.





I only use multi-line comments when debugging, and I want to skip a block of code.
John
2017-06-22 20:38:12 UTC
This is just your supposition, and not a fact, and is based only on C, C++, and Java. Many

other languages have different styles: Python uses triple quotes for docstrings; Lisp, Scheme,

Racket and others use ; and dash-bracket combinations for comments; Haskell uses -- for

single-line comments and {- -} for multiline comments; OCaml uses another style, etc.

Don't be so parochial. The few lines of code that you've seen are a drop in the bucket.

>

> John (gnujohn)
joe
2017-06-19 13:01:05 UTC
personal preference
Richard
2017-06-18 22:26:52 UTC
// means that whatever exists from there to the end of the current line is a comment.



For two line comments, it requires the same number of keystrokes as /* */. For more than two lines in a comment, // is less efficient in terms the number of key strokes.



Not all compilers support //. Some compilers support nested /* */ comments, while others do not. A nested comment looks like this:



/* start of comment 1



/* start of comment 2



end of comment 2 */



end of comment 1 */



I tend to use /* */ for temporarily disabling sections of code when I am debugging new code. If the compiler supports nested comments, it makes it much easier to disable large sections of code that already have comments included.



For compiler portability, using non-nested /* */ should offer the best independence across different compilers.



That's my view.
Daniel B
2017-06-18 22:12:41 UTC
If you are using an editor that doesn't do syntax highlighting then using // will make it more clear which lines are comments and which aren't. This is especially important when you are commenting out code.
?
2017-06-18 21:32:46 UTC
two less key presses each time.
anonymous
2017-06-18 19:24:59 UTC
I'm sure it's because it more clearly marks the whole block of text as comments, no matter what gibberish you've typed in there
anonymous
2017-06-18 19:53:19 UTC
For me, I'm too lazy and tend to use them a lot more since most of the time I can describe it with one single line, and its faster to type even if I have multiple lines. The /**/ does look prettier though...


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...