Language - Comment

1 - About

Comments are the code document.

They should explain why, not what. They can optionally explain how if what’s written is particularly confusing.

3 - Example

Javascript

// This is a single-line comment 
 
/* But this 
           is a multiline
                    comment. 
*/
 
var a = /* It can also appears in the middle of an expression */ 42;
console.log(a);

4 - Snippet

4.1 - Suppressing comments with regular expression

In javascript with the Replace function.

text = "// My beautiful comment\r\nmy beautiful code\r\n";
text = text.replace(/^[/]{2}[^\r\n]+[\r\n]+/mg, "");
console.log(text);

where:

  • The regexp pattern can be read as:
    • ^ - the start of the pattern
    • [/]{2}: two backslashs
    • [^\r\n]: All characters excepts the end of line \r\n. The ^ character is a negation in a class.
    • + is a quantifier meaning one or more

code/grammar/comment.txt · Last modified: 2017/09/17 17:36 by gerardnico