What is Mojo programming language and what is it used for?
Mojo is a high-performance programming language initially designed to unify and simplify the development of applications across all layers of the AI stack. It combines the usability and syntax of the Python high-level language with performance of system-level languages such as C and Rust, able to run across the AI stack and custom domains.
Modular Inc. began development of the Mojo programming language in 2022, and the language's first general availability release happened in September 2023. The impetus behind Mojo's creation, according to the company, was to address difficulties encountered during development of its own AI platform, which it believed required a fundamentally different approach in terms of architecture and compilation, hardware access and memory management.
Mojo and AI
Across the current software development landscape, a programmer who wants to work across the AI stack likely is forced to write code in two or three different languages, beginning with the following:
- Python is typically the glue code that feeds data into complex AI systems.
- Complex AI processing systems are typically written in highly efficient languages such as Rust or C and its supersets.
- Knowledge of C and C++ is required to use the CUDA programming model and take advantage of parallel GPU processing.
Mojo's promise is to simplify the way applications are built, initially throughout the AI stack. The goal is to provide a single programming language for AI developers to address unique aspects across the entire AI stack, such as accelerators, machine learning environments and adaptive compilation techniques, without sacrificing performance or usability or requiring a blend of languages to meet those needs.
Modular Inc., the company that created and maintains Mojo, has said the impetus behind the language's creation was the difficulties Modular encountered while developing its own AI product called the Max platform.
Mojo's extensibility
While Mojo's primary intent is to fix a serious problem in the field of AI development, the language is not inherently tied to AI. Projects built with the Mojo programming language have already appeared in web development, 3D graphics and image decoders. Furthermore, Mojo's use of the modern MLIR compiler framework enables its source code to target a wide range of domains, from handheld devices to quantum computing engines.
Mojo and Python
One of Mojo's primary benefits is that it embraces a Pythonic syntax.
Python is well-known in the software development community for being easy to learn, and it has been enthusiastically embraced. Furthermore, Python is already entrenched in the AI space with popular libraries and projects such as PyTorch, NumPy and TensorFlow.
Additionally, the Mojo development team highly prioritizes Mojo's superset compatibility with Python, where the Mojo runtime fully supports Python syntax.
Mojo enables Python developers to port their existing Python code directly into a Mojo environment without having to edit their code or learn Mojo-specific syntax. When specific Mojo functionality is required, developers can incrementally learn Mojo as needed.
Mojo's Python support removes significant barriers to adoption. Modular's hope is that developers recognize Mojo's performance and scalability benefits, and it will become a natural choice for Python development projects.
Mojo and performance
A key problem with the Python programming language is its poor performance and its inability to thread across multiple CPU cores. This greatly limits Python's use in high-workload, data-processing use cases, which are ubiquitous throughout the AI stack.
Mojo supports a Pythonic syntax, but its underlying architecture and additional language features and compiler advancements help Mojo approach the high performance of system programming languages including Rust and C.
Given its relatively recent incarnation, Mojo is architected to natively support a variety of modern features and system optimizations, such as the following:
- Support for the MLIR compiler, as opposed to the LLVM compiler used by languages including Rust, Swift and native Kotlin.
- Transparent use of single instruction, multiple data (SIMD) operation types throughout the language.
- An ownership and borrow checker that helps to ensure memory safety, prevent memory leaks and simplify concurrency.
Mojo's staying power
While many programming languages come and go, there are a few factors that set Mojo apart.
First, most successful programming languages initially address a problem with a specific platform or technology and then expand their pervasiveness into other domains.
The specific problem Mojo addresses is the challenging complexity and disparity of a unified programming manner throughout the AI stack. Developers are also finding ways to apply Mojo outside of AI and machine learning. Thus, as with other successful programming languages, Mojo has strong potential to succeed.
Secondly, Mojo boasts the experience, guidance and leadership of its co-creator, Modular CEO Chris Lattner. His long and illustrious history in compiler technology and programming language development includes the following credentials:
- Created the LLVM compiler as part of a University of Illinois research project.
- Co-created the MLIR compiler while working at Google.
- He was central to the development of the Swift programming language at Apple.
Lattner's leadership in the software development field and experience with compiler development provides a strong pedigree to guide the ongoing development of an ambitious project such as Mojo.
Cameron McKenzie has been a Java EE software engineer for 20 years. His current specialties include Agile development; DevOps; Spring; and container-based technologies such as Docker, Swarm and Kubernetes.