Does the syntax '//' have any special meaning?

Asked

Viewed 298 times

15

I was using Notepad++ (v 6.5) to write a javascript file when I noticed the following:

I wrote a comment line starting with ///, three instead of the usual two. When running this line seems to be ignored, but it is not colored like a comment. (Also note that the background of the line is white, of different color). Is this a Notepad++ Highlighter syntax bug or is it some special javascript syntax I don’t know about? Something related to /regex/?

  • In my view it’s a Notepad++ bug. I use eclipse and is referenced as comment in the same way, with 3 or more Slash’s

  • 1

    Here’s version 5.6 and it’s a comment. Probably a bug introduced in parser.

2 answers

25


This three-bar set is commonly used by some programs for formatting code documentation (such as the Doxygen), as a way to indicate that a single line comment should be included in the generated documentation. In practice it is still a one-line comment, but it is a special comment.

Some editors, such as the Visual Studio, for example, color these comments differently precisely to indicate that it is a documentation. Others do not differentiate this from a normal comment (as in the case of Stackoverflow itself - see below). The function below (extracted from the link referred above to Visual Studio) exemplifies the use of this type of comment:

<script type="text/javascript">
function areaFunction(radiusParam)
{
    /// <summary>Determines the area of a circle based on a radius parameter.</summary>
    /// <param name="radius" type="Number">The radius of the circle.</param>
    /// <returns type="Number">The area.</returns>
    var areaVal;
    areaVal = Math.PI * radiusParam * radiusParam;
    return areaVal;
    // Note como o StackOverflow NÃO COLORE esse comentário DE FORMA DIFERENTE do anterior...
}
</script>

The colorizer (syntax Highlighter) Notepad++ (the reference version is 6.5.5) is able to differentiate these characters from a simple comment. In some languages where this use is more common, there is a specific configuration for this:

inserir a descrição da imagem aqui

I intentionally changed the style of documentation comments (COMMENT LINE DOC) in Java* to blue as an illustration. This is done directly in the "Style Configurator" tool available in the "Settings" menu of Notepad++:

inserir a descrição da imagem aqui

* Although Notepad++ colors comments with three bars differently (to indicate documentation), there are no references to this style other than the /** <codigo> */ in the Javadoc documentation - as indicated in a comment made in this reply.

In the case of Javascript, Notepad++ also differentiates this comment from the "common", but does not provide a unique colorization option for it (as it does in the case of Java). Honestly, I do not understand the reason why this option for color setting is missing, since the distinction is clearly made (if there is a bug it may be in this lack of configuration, not in the differentiation of comment types).

Just to be precise about what happens in the case of this comment with three bars in the case of Javascript, the line falls into the default configuration (default) of global styles (global Styles), And so it has the white background color distinct from the rest of the file. If it’s of interest to you, you can still set the color for Javascript by changing here:

inserir a descrição da imagem aqui

  • 1

    Um... nice to know all this. BUT, in Java, it is not common to use three bars. I couldn’t find any reference to it in Javadoc. I saw that this feature is used in C# or C++ in Visual Studio, but it would just be visual, because simple comment documentation is also read.

  • @utluiz Vc is right, sorry. I swore that Javadoc also used this format, but I also went to look and did not find in the documentation. I found that request well old, but that apparently did not go forward. I will take the reference to the Javadoc of the answer. Thanks for the warning!

4

According to the Specification ECMA-262, in the case of comments by single line, any character type is accepted after adding the two "bars" that start the comment (//).

So, despite the color change in your editor, the Javascript comment is still valid.

  • 3

    Doesn’t look like a Notepad++ bug, just a different color to indicate a Marking of code documentation.

  • 1

    @Luizvieira good placement, had not thought of this reason. I made a change in the last line by removing the term "bug".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.