KDnuggets Top Blog Winner

Mojo Lang: The New Programming Language

Introducing Mojo Lang, the new programming language designed as a superset of Python.



Mojo Lang: The New Programming Language
Image by Author

 

Just when we thought things couldn’t shake up the tech industry anymore, welcome the new programming language that has been designed as a superset of the Python programming language.

Python still ranks high as one of the most popular programming languages due to its ability to create complex applications using simple and readable syntax. However, if you use Python, you know its biggest challenge is speed. Speed is an important element of programming, therefore does Python's great ability to produce complex applications with easy syntax dismiss its lack of speed? Unfortunately no. 

There are other programming languages such as C or C++, which have incredible speed, and higher performance in comparison to Python. Although Python is the most widely used programming language for AI, if speed is what you’re looking for, the majority of people stick with C, Rust, or C++.

But that may all change, with the new programming language Mojo Lang.

 

What is Mojo Lang?

 

The creator of Mojo Lang, Chris Latner, the creator of the Swift programming language and the LLVM Compiler Infrastructure has taken the usability of Python and merged it with the performance of the C programming language. This has unlocked a new level of programming for all AI developers with unparalleled programmability of AI hardware and the extensibility of AI models.

In comparison to Python, PyPy is ??22x, Scalar C++ is 5000x, and Mojo Lang is 35000x faster. 

Mojo Lang is a language that has been designed to program on AI hardware, such as GPUs running CUDA. It is able to achieve this by using Multi-Level Intermediate Representation (MLIR) to scale hardware types, without complexity. 

Mojo Lang is a superset of Python, which means that it does not require you to learn a new programming language. Handy, right? The base language is fully compatible with Python and allows you to interact with the Python ecosystem and make use of libraries such as NumPy. 

Other features of Mojo Lang include:

  • Leverage types for better performance and error checking.
  • Taking control of storage by inline-allocating values into structures, with zero cost abstractions.
  • Ownership and borrower checker by taking advantage of memory safety without the rough edges.
  • Auto-tuning, allows you to automatically find the best values for your parameters.

 

Differences between Mojo Lang and Python

 

Mojo Lang and Python are so similar, but there must be some differences, right?

Well yes, we’ve stated that the most significant difference between the two is speed. But there are a few more. 

 

Adding Types

 

Mojo Lang has a built-in struct keyword similar to a Python class. The difference is that struct is static, whereas class is dynamic. 

Inside struct, Mojo Lang has keywords such as var, which is mutable and let which is immutable. def as we know in Python defines a function, in Mojo lang, def is replaced with fn which is a stricter function. 

It can also include SIMD, single instruction multiple data which is a built-in type that represents a vector where a single instruction can be executed across multiple elements, all in parallel on the underlying hardware. 

Using struct as a type and using it in the Python implementation can improve your performance by 500x. 

 

Parallel Computing

 

Mojo Lang has a built-in parallelize function, which can make your code multi-threaded, which can increase your speed by 2000x. Parallel processing is not available in Python and can be very complex to do. 

 

Tiling Optimization

 

Mojo has a built-in tiling optimization tool, which allows you to cache and reuse your data more effectively. You can use memory that is close to each other at a time, and reuse it. 

 

Autotune

 

Mojo Lang allows you to autotune your code to help you automatically find the optimum parameters for your target hardware.

There are some more features to the Mojo Lang, to see how it works, watch this Mojo demo with Jeremy Howard:



 

Can I Use Mojo Lang Now?

 

Unfortunately, Mojo Lang is not available to the public as it is in early development. It will be open-sourced in the future, however, you can join the waitlist to try Mojo Lang when available. 

 

Wrapping it up

 

You’ve had an insight into the new Mojo Lang programming language and its features. Is Mojo Lang just Python++ or will it completely convert all Python users?
 
 
Nisha Arya is a Data Scientist, Freelance Technical Writer and Community Manager at KDnuggets. She is particularly interested in providing Data Science career advice or tutorials and theory based knowledge around Data Science. She also wishes to explore the different ways Artificial Intelligence is/can benefit the longevity of human life. A keen learner, seeking to broaden her tech knowledge and writing skills, whilst helping guide others.