Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Introduction to Mojo Programming Language

Introduction to Mojo Programming Language

This item in japanese

Mojo is a newly presented programming language that combines the simplicity of Python with the speed and memory security of Rust. It is at an early stage of development and offers users an online playground to explore its features. Mojo aims for excellence in data science and machine learning, providing a fast alternative to Python. There are gradual plans to make it available to open-source.

Mojo, created by Chris Lattner, offers programmability and extensibility to AI programmers, enabling efficient programming on AI hardware. Mojo shows significant speed improvements, making it 35000x faster than Python (PyPy is 22x faster and Scalar C++ 5000x faster in comparison with Python). It achieves this by using Multi-Level Intermediate Representation (MLIR) to seamlessly scale hardware types without introducing complexity. Mojo is compiled into machine code using the LLVM toolchain, providing better performance through the use of Mojo-specific features. Python, on the other hand, relies on runtime interpretation. 

Mojo introduces new language features that can be divided into two groups. There are completely new and non-existent elements in Python, and those existing Python features with reduced dynamics. For instance, Mojo allows using keywords such as let and var to declare variables, indicating whether they are immutable or mutable. These restrictions are enforced during compilation, preventing any attempt to mutate immutable references.

In addition, Mojo uses its struct keyword, distinct from Python's class, to define types with fixed arrangements optimised for native machine speed, much like the C/C++ and Rust equivalents. Another distinctive keyword in Mojo is fn, used to define functions. Mojo functions take immutable arguments by default and require explicit typing, as well as local variable declarations. These language features contribute to Mojo's unique characteristics compared to Python.

In order to experience working with Mojo, users can access Modular Playground, a web-based Jupyter Notebook environment with early access. Mojo does not yet have a downloadable runtime environment, but this allows Mojo to run on any computer with a browser. The environment offers sample notebooks with detailed notes.

The community is curious about language development. There are positive opinions about it. On Twitter, Jeremy Howard shared his perspective

A Mojo app can be compiled into a small, standalone, fast-starting binary. This is a game-changer! Think about the things you could do if you could create small fast tools quickly and easily, and distribute them in a single file.

Chris Lattner, in Lex Friedman's podcast, said that the idea behind the creation of Mojo lies in making machine learning and its infrastructure more accessible and understandable to non-experts. This has led to the development of a programming language with a user-friendly syntax, enabling researchers and those unfamiliar with advanced technologies such as GPS to use machine learning effectively.

About the Author

Rate this Article