Mojo is a newly launched programming language that combines the simplicity of Python with the speed and memory safety of Rust. It's still in the early stages of development but offers users an online playground to explore its features. Committed to excellence in data science and machine learning, Mojo serves as a fast alternative to Python, and we're gradually planning to open-source it.
Mojo was created by Chris Lattner to provide AI programmers with programmability and scalability for efficient programming on AI hardware. Compared to Python, Mojo is significantly faster—22 times faster than PyPy and 5,000 times faster than scalar C++. This performance boost is achieved by seamlessly extending hardware types without introducing complexity through multilevel intermediate representation (MLIR). Mojo compiles to machine code using the LLVM toolchain, leveraging Mojo-specific features for better performance, unlike Python, which relies on runtime interpretation.
Mojo introduces new language features that can be grouped into two categories: those entirely new or non-existent in Python, and existing Python features made less dynamic. For example, Mojo allows variables to be declared using keywords such as let and var, indicating whether they are immutable or mutable. These restrictions are enforced during compilation, preventing any attempt to change an immutable reference.
Additionally, Mojo uses its struct keyword (unlike Python's classes) to define types with fixed permutations optimized for native machine speed, much like C/C++ and Rust equivalents. Another unique keyword in Mojo is fn, used to define functions. Mojo functions take immutable arguments by default and require explicit types as well as local variable declarations. These language features make Mojo distinct from Python.
To experience working with Mojo, users can access the Modular Playground, a web-based Jupyter Notebook environment available ahead of time. Although Mojo does not yet have a downloadable runtime environment, this allows Mojo to run on any computer with a browser. The environment provides sample notebooks with detailed annotations.
The community is eager about the language's development. On Twitter, Jeremy Howard shared his view that Mojo applications can be compiled into small, self-contained, quick-launch binaries—a game changer! Imagine creating small, quick tools and distributing them in a single file effortlessly.
On Lex Friedman's podcast, Chris Lattner explained that the idea behind creating Mojo is to make machine learning and its infrastructure more accessible and understandable for non-experts. This has led to the development of a programming language with user-friendly syntax, enabling researchers and those unfamiliar with advanced technologies like GPS to use machine learning effectively.