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 compared to Python – making it 35000x faster than Python when PyPy is 22x faster and Scalar C++ 5000x. It achieves this by using Multi-Level Intermediate Representation (MLIR) to seamlessly scale hardware types without adding 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, depends 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, but with reduced dynamics. For instance, Mojo allows using keywords such as
var to declare variables, indicating whether they are immutable or mutable. These restrictions are enforced during compilation, preventing any attempt to mute immutable references.
In addition, Mojo uses its
struct keyword, distinct from Python’s class, to define types with fixed arrangements optimized 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, on 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.