Source: Modular Website

The Future of AI Programming is here.

Mojo — A new AI-centric programming language, with the accessibility of Python and performance of C.

Om Kamath
Level Up Coding
Published in
5 min readMay 9, 2023

--

For many technology enthusiasts, Python has been the preferred language of choice. It is a language that allows people like me to build products quickly without diving deep into technical details. I, too, am impatient when it comes to building things and prefer taking the shortest possible path to productize an idea.

Although, Python is widely beloved by geeks and nerds alike for its ease of use and extensive feature set, it is often criticized by those same individuals for its performance. Two factors that contribute to Python’s relatively slow performance are that it is an interpreted language and dynamically typed. Most enterprises migrate to languages such as Rust and C at the backend from Python to handle the additional traffic and improve performance, especially with the rise in AI-driven hardware-intensive applications where every bit of performance is an elixir. This is about to change now with the creation of a new language: Mojo.

What is Mojo?

Mojo is a newly developed programming language by Modular — A company founded by Chris Lattner and Tim Davis. Chris has also been the founder of the popular mobile app-development language — Swift.

Learning a new language can have a big learning curve for some people or sometimes you may not be having the time and resources to learn a new language for a specific development. If you are someone who is well-versed in Python, Mojo is a super-set of Python. This makes it easier to learn and faster to implement. I really appreciate such extensions and unifications of languages because it makes life a lot simpler for developers and mitigate the paradox of choice.

Why Mojo?

“When we started Modular, we had no intentions of building a new programming language. But as we were building our platform with the intent to unify the world’s ML/AI infrastructure, we realized that programming across the entire stack was too complicated. Plus, we were writing a lot of MLIR by hand and not having a good time.” — Modular Team

No Learning Curve

Mojo being a super-set of Python means that if you are familiar with Python, learning Mojo should not be difficult. Since most of the syntax (in a new codebase) is forked from Python, you would not face any major syntactical issues. Even if you are not well-versed in Python, there is no need to worry as Python has a simple syntax. If your coding fundamentals are clear, learning Mojo should not be a tough task.

Additional Features

Python is not considered suitable for systems programming due to its Global Interpreter Lock (GIL), which results in relatively poor low-level performance. However, Mojo overcomes this limitation by leveraging MLIR and utilizing CPython to run existing Python code for easy migration. It provides access to all features seen in C/C++ such as structs, let and var declaration, custom memory allocation using pointers, etc., with improved performance. Alongside these features, you also have the choice of declaring types, which improves type-checking and error handling.

My personal favorite feature of Mojo is its ability to parallelize tasks. With powerful hardware becoming more accessible to the general public, this feature can be utilized to improve the performance of intensive calculations. The task is simply divided among multiple cores of a processor, making operations such as matrix multiplication a breeze.

Better Hardware Compatibility

Chris Lattner is also the creator of MLIR (Multi-Level Intermediate Representation). By using MLIR, developers can write high-level, framework-agnostic code that can be optimized and deployed efficiently on a variety of hardware targets and use a wide-gamut of accelerator blocks like the Host CPU or GPUs like CUDA and Tensor Cores. The utilization of MLIR makes Mojo 35000x faster than vanilla Python and provides features such as auto-tuning and caching. Although, these are the claims made by Mojo, I cannot guarantee them until I thoroughly test the language. As Mojo is not currently open-source, I have applied to join the waitlist and gain access to the code playground. Once I have been accepted, I will be able to thoroughly test the language and evaluate the claims made by the Mojo team.

Conclusion

I hope this brief overview has provided you with useful insights into the new language. All the information I have shared has been gathered from reliable sources on the internet, and I have tried to present it in a concise and easy-to-understand manner. However, please note that I am not a programming language expert, and there is a possibility that I may have misinterpreted some of the information from the official documentation.

In the short term, I don’t think Mojo will be able to replace Python thanks to its extensive library ecosystem and support, but in the long term, it has the potential to compete with Python thanks to its strong development team and the flexibility to make low-level optimizations for improved performance.

Thanks Upendra Sir for introducing me to this new language.

If you found this article helpful you could buy me a coffee and please consider following 👉 me and clapping 👏 for it. You can also share your thoughts on Mojo in the comments section. Thank you for reading! 🚀

Resources

Mojo

MLIR

Level Up Coding

Thanks for being a part of our community! Before you go:

🚀👉 Join the Level Up talent collective and find an amazing job

--

--