Adding code comments

Introduction

Comments are parts of the code that don't get executed.

Why do I need comments?

Comments come in handy in a few situations:

  • Annotating - they can describe what a specific part of the code does
  • Testing - you can temporarily disable a single section to test a different part
  • Documenting - comments can act as a code documentation e.g explain custom functions

With our syntax it's pretty easy to add comments:

// Single line comment 

/* Multi
Line
Comment
*/

Single line Comment

A single line comment can be achieved by placing two forward slashes at the beginning of a line:

Code

Let's code something and describe it with a short comment

// this part sums 2 numbers
$let[num1;5]
$let[num2;10]
Result is $sum[$num1;$num2]

Output

Now it's time to check if the comment worked fine

Custom Command Bot 08/02/2024
Result is 15

As you see the comment at line 1 didn't appear in the result

Multiple Lines Comment

In some cases you may want to comment out more than one line or a specific part of it. You can do that by wrapping the comment with a combination of slashes and asterisks: /* Comment */

Code

Let's extend our previous comment with some extra lines:

/* This part
Sums two numbers
num1 and num2
and it send the result 
*/
$let[num1;5]
$let[num2;10]
result is $sum[$num1;$num2]

Output

Here's what the bot returns:

Custom Command Bot 08/02/2024
Result is 15

As you can see it didn't add any extra content despite adding more lines.

Keystroke

When using the dashboard editor, you can hit ctrl + / to automatically comment out the selected line(s)