Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Why, in code, is there a tendency to use multiple // instead of a /**/ when writing multi-line comments?
11 Answers
- Anonymous4 years ago
do not know sorry
- PoohBearPenguinLv 74 years ago
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.
- How do you think about the answers? You can sign in to vote the answer.
- ?Lv 54 years ago
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)
- RichardLv 74 years ago
// 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 BLv 74 years ago
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.
- Anonymous4 years ago
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