Search code examples
dartcomments

Nested multiline comments in Dart


My code contains lots of documentation comments written in the multiline comment syntax like in example

/** 
 * This class is used as an example.
 *
 * To ask about multiline comments.
 */
class A {
}

/**
 * Another example class with comment.
 */
class B {
}

Sometimes, during debuging/refactoring or experimenting with the code, I want to comment out some blocks of the code. In this example, I would like to comment out the classes A and B. Is there a way to do this in a simple way without a need to watch where the documentation comments starts and ends and also without a need to comment each line separately with one line comment syntax //?


Solution

  • Dart (contrary to other C-like syntax languages) natively supports nested multiline comments.

    So you can just write

    /* Commented for debugging purposes!!! Do not forget to uncomment!!!
    /** 
     * This class is used as an example.
     *
     * To ask about multiline comments.
     */
    class A {
    }
    
    /**
     * Another example class with comment.
     */
    class B {
    }
    */
    

    And do not care about some nested comments inside the comment block.