

What are some anti-patterns when writing code comments?Īvoid excessive comments, instead summarize a block of code.

Some developers treat these as documentation, not comments. Tools exist to automatically create documentation from these comments. Documentation: For documenting interfaces and to assist editors/ IDEs.Python uses # -*- coding: UTF-8 -*- to inform the encoding used for the source file. For example, UNIX scripts use #! to know what interpreter must be used. Directives: Directives meant for editors and interpreters.These comments are ideally deleted once the problem is found. Debugging: Developers comment out redundant code or code causing problems.Pending Work: Comments tagged with FIXME or TODO indicate pending work.Could include external references to provide context, such as, a published paper or a StackOverflow answer. Metadata: Could include author and date of the first version, name and contact of current maintainer.Licensing: Licensing or copyright information are written as comments.Even flowcharts in ASCII could be included. Used for describing the algorithm or explaining why it was chosen. Description: Used for describing the logic behind the code, not the code itself.Source: Devopedia 2021.Ĭode comments are used for various purposes:

An example use of different types of comments in Java code.
