Comments in Julia
Comments are the statements in a code that are ignored by the compiler at the time of execution. These statements are written to beautify the code, providing an explanation for the steps that are used in the code. During coding, proper use of comments makes maintenance easier and finding bugs easily.
In Julia, comments are used in a similar manner as in Python. Comments can be of two types, based on their usage. These are:
- Single Lined comments
- Multi lined comments
Comments are generally used for the following purposes:
- Code Readability
- Explanation of the code or Metadata of the project
- Prevent execution of code
- To include resources
Single Line Comments
Single line comments in Julia start with the hashtag symbol(#) and lasts till the end of the line. If the comment exceeds one line then put a hashtag on the next line and continue the comment. Julia’s single lined comments are useful for supplying short explanations for function declarations, variables, and expressions. See the following code snippet demonstrating single line comment:
In the above code, the compiler ignores the statement written after #, because it considers the line as a comment and skips its execution.
Julia multi-line comment is a piece of text enclosed in a delimiter (#=) on start of the comment and (=#) on the end of the comment. A multiline comment is useful when the comment text does not fit into one line; therefore needs to span across lines. Multi-line comments or paragraphs serve as documentation for others reading your code. See the following code snippet demonstrating multi-line comment:
In the above code snippet, the statements that are inclosed within #= and =# are considered as comments and are ignored by the compiler at the time of Code execution.