Comments

You shall comment ALL your code!

Comments are necessary for any programming language. BoxLang is no different in helping you add code comments in both script and tag syntax. The syntax is the same if you are a Java/Kotlin developer.

Tag Comments

You can use the <!--- and ---> Syntax to comment within a BoxLang template (.bxm). This is similar to HTML comments but adds an extra - to demarcate it as a BoxLang comment.

HTML Comment
<!-- I am an HTML Comment -->

BoxLang Comment
<!---  I am a BoxLang Comment --->

Nested Tag Comments

BoxLang supports nested tag comments, which is useful when you need to comment out a block of code that already contains comments. The parser tracks the nesting depth and only closes the outer comment when all nested levels are properly terminated.

<!---
    This is an outer comment
    <bx:set fruit = "apple">

    <!--- This is a nested comment inside --->

    <bx:output>#fruit#</bx:output>
--->

This feature is particularly helpful during development when you want to temporarily disable a section of code without removing existing comments.

Note: Script-style comments (/* */ and //) follow standard Java/C conventions and do not support nesting. Attempting to nest /* */ comments will result in the first */ closing the comment block.

Script Comments

If you are within a class, scripting or in a <bx:script> block, you can use an alternate style for comments. You can leverage // for single-line comments and the following for multi-line comments:

BxDoc: "Javadoc" style comments

A multi-line block can affect the metadata of a class or function if the opening line contains 2 asterisks. Also, for readability, some people will start each line of the comment with an asterisk. BoxLang will parse out those starting asterisks, but they will not appear in the class or the function metadata.

You can use all the JavaDoc style comments; however, when doing parameters, we omit the verbosity of the @param {name} hint and use the @{name} hint.

Documentation Metadata vs Standalone Annotations

It's important to understand the difference between documentation annotations (using @ inside BxDoc comments) and standalone annotations (using @ before declarations):

  • Documentation annotations (@something inside /** */ comments) become part of the documentation metadata struct

  • Standalone annotations (@something before a class/function/property) become direct metadata properties

Documentation Annotations Example:

When you call getMetadata( test ), the documentation annotations are available in the documentation struct:

Standalone Annotations Example:

These become direct annotations struct in the metadata:

Best Practice: Use documentation annotations (@see, @version, @author, @return, etc.) for human-readable documentation that tools like DocBox can process. Use standalone annotations for framework-level metadata that affects runtime behavior (dependency injection, caching, validation, etc.).

Flexible Annotation Syntax

BoxLang's documentation metadata system is open and flexible. You can use any @name annotation inside BxDoc comments - there are no reserved keywords or restrictions. This allows you to create custom documentation annotations tailored to your application or framework needs.

Common Documentation Annotations:

Custom Documentation Annotations:

You can create your own annotations for any purpose:

All @name annotations become entries in the documentation metadata struct, accessible via getMetadata():

Simplified Parameter Documentation:

Unlike traditional JavaDoc's verbose @param name description syntax, BoxLang uses a simplified approach where you can directly use @parameterName followed by the description:

DocBox

We have a tool call DocBox that can generate the documentation off your BoxLang classes, much like JavaDoc.

Please check out the annotating your code section in the DocBox documentation to get a feel for how to document your code: https://docbox.ortusbooks.com/getting-started/annotating-your-code

Read about DocBox

Last updated

Was this helpful?