Code comments in Mojo Programming Language

Shriram Sivanandhan
2 min readMay 17, 2024

--

Mojo Programming Language combines the usability of Python with the performance of C, C++ and Rust. Mojo Programming Language utilizes next-generation compiler technologies with features like caching, multithreading and cloud distribution technologies. Further, Auto-Tuning and compile-time Metaprogramming features allows to write code for several hardware. The advantages of Mojo Programming Language are Usability & Programmability, best performance, Interoperability and Extensibility.

As we saw Interoperability of Mojo Programming Language with Python Ecosystem to use Matplotlib Python Visualization Library, Pandas Python Data Analysis and Manipulation Library, NumPy (Fundamental Package for Scientific Computing in Python) Library, SciPy Python Library in Mojo Programming Language and various concepts and implementations regarding Mojo Programming Language in previous Articles/Blogs. In this Article/Blog, we are going to see Code comments in Mojo Programming Language.

Since the older JupyterLab-based Mojo Playground is deprecated, in this Blog, Programming in Mojo is done using the new Mojo Playground.

Code comments in Mojo Programming Language:

Comments are non-executable statements used to provide source code explanations and information. Comments are used for documentation and they are also used for improving code readability. Compiler ignores the Comments and they consider them as not-executable statements.

Single-Line Comments in Mojo Programming Language:

In Mojo Programming Language, we can create Single-Line Comments by using # (hash) symbol.

# This is a Single-Line Comment.

Example Code 1:

Single-Line Comments in Mojo Programming Language (In New Mojo Playground)

Multi-Line Comments in Mojo Programming Language:

In Mojo Programming Language, we can create Multi-Line Comments by using Triple quotes as shown below.

"""
This is a Multi-Line Comment.
This is Mojo programming Language.
"""

Example Code 2:

Multi-Line Comments in Mojo Programming Language (In New Mojo Playground)

In Mojo Programming Language API Documentation can be done more preferably using Multi-Line Comments (Triple quotes).

Modular-Mojo Development Team needs to yet fully specify about Documenting our Code with comments like docstrings and they also mention that we can use mojo doc command to generate API reference from docstrings.

Thankyou for reading this blog on Code comments in Mojo Programming Language.

Reference:

https://docs.modular.com/mojo/manual/

https://docs.modular.com/mojo/manual/basics/

--

--

No responses yet