Comments
Serverless Stack
Comments are used to explain or annotate code and make it more readable. They are ignored when the script is executed, allowing you to add notes or temporarily disable code sections without affecting the functionality.
Painless supports two types of comments: single-line comments and multi-line comments.
Single-line comments start with // and continue to the end of the line. Everything after // on that line is ignored by the compiler.
SINGLE_LINE_COMMENT: '//' .*? [\n\r];
// This is a single-line comment
int value = 10;
int price = 100;
- Comment at the end of a line
Multi-line comments start with /* and end with */. Everything between these markers is ignored, even if it spans multiple lines.
MULTI_LINE_COMMENT: '/*' .*? '*/';
/* This is a
multi-line comment
spanning several lines */
int total = price * quantity;
/* You can also use multi-line comments
to temporarily disable code blocks:
int debugValue = 0;
debugValue = calculateDebug();
*/
int result = /* inline comment */ calculateTotal();
Use comments to:
- Explain complex logic or business rules
- Document function parameters and return values
- Provide context data transformations
- Temporarily disable code during development
Good comments explain why something is done, not just what is being done. The code itself should be clear enough to show what it does.