Search code examples
flutterdartcomments

Differences between Doc comments and Comments in Dart


May be it seems simple but I'm interested about knowing the exact differences between Doc Comments and Comments in Dart.

/// this is a Doc Comment

// this is a Comment

In my view, Asking and Answering here can be helpful for others too :)


Solution

  • Comments (//)

    Comments usually used to comment out some part of your code or adding some comments in your code, which you want to communicate with your team-mates.

    Doc Comments (///)

    Doc comment is for documentation purpose. The dartdoc parses doc comments and creates documentation pages.

    +--------------------------------------------+-----------------------------------------------------+
    | Comments                                   | Doc Comments                                        |
    +--------------------------------------------+-----------------------------------------------------+
    |  - Comment out some part of your code      | - Anything that you want to document using dartdoc  |
    |  - Private APIs                            | - Usually used for public API/Framework/Library     |
    |  - Private variable declaration            |                                                     |
    |  - Method implementation logic             |                                                     |
    |  - Something you need to do in future      |                                                     |
    |    for improvements or cleanup purpose etc |                                                     |
    +--------------------------------------------+-----------------------------------------------------+
    

    You can read more about these in Effective Dart - Documentation