Feature request: scoped comments #1793
Replies: 5 comments 4 replies
-
// and /* */ comments are removed by the preprocessor before compiling. This can easily be done because any time you encounter // you remove until the end of the line. and any time you encounter /* you remove until the next */. I am also not convinced this will improve the quality of comments. Nothing prevents someone from changing this line of code: |
Beta Was this translation helpful? Give feedback.
-
I am having trouble coming to agreement that this is the main reason comments rot. My intuition is that most comments rot because sufficient care was not taken to update the comments when individuals edit code. Key point here is that humans almost always know what each comment refers to. When tools modify code, they can sometimes fail to place existing comments in the correct place. Here I can see value in formalizing how comments relate to specific code constructs. Even without something as explicit as Have a look at https://github.com/carbon-language/carbon-lang/blob/trunk/proposals/p0198.md, which explains the current thinking on comments. The interesting thing I see there is that comment lines must be preceded by white space only (which is unusual), and that an entire class of comments (such as those that appear at the end of a scope) are intended to be rendered unnecessary with clearer language grammar. |
Beta Was this translation helpful? Give feedback.
-
Comments should be also involved in ast. Also, all the white spaces. |
Beta Was this translation helpful? Give feedback.
-
Like other languages, one can use few available documentation generators and they work similarly. Is this what you are talking about? |
Beta Was this translation helpful? Give feedback.
-
What you are proposing would be equivalent to do, in a C++ code-base: variable.code();
// because (this is human readable text) {
variable.code();
// }
variable.code(); Please note the unnecessary indent in the fourth line. You can achieve the exact same thing if you only do, in Carbon code: variable.code();
// because (this is human readable text) {
variable.code();
// }
variable.code(); Without actually getting into over-indenting code to cover a block of code with one comment. |
Beta Was this translation helpful? Give feedback.
-
The main reason comments rot is because they are not part of the syntax tree, making what they are referring to ambiguous.
Proposal, the 'because' keyword.
because( this is human readable text )
{
// code
}
and:
x = y + z because( this is human readable text );
and:
{
// code
} because( this is human readable text);
Beta Was this translation helpful? Give feedback.
All reactions