TNS
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Programming Languages

Mojo’s Chris Lattner on Making Programming Languages Evolve

What do programmers really care about in 2024? For the 100th episode of "Software Unscripted," Chris Lattner shared his insights from a career spent designing programming languages.
Oct 11th, 2024 8:00am by
Featued image for: Mojo’s Chris Lattner on Making Programming Languages Evolve
Richard Feldman interviews Mojo creator Chris Latter on Software Unscripted podcast (screenshot).

Modular’s new Python-based Mojo programming language — launched in 2023 — is designed for deployments on GPUs and other accelerators, according to its FAQ. “Our objective isn’t just to create ‘a faster Python,’ but to enable a whole new layer of systems programming that includes direct access to accelerated hardware.”

Or, as language designer Chris Lattner said in a new interview, they wanted to focus on “how we express” the hardware’s full capabilities. But they also wanted to “meet people where they are” — maintaining the look and feel of Python — since a lot of people, especially in the AI community, were using Python.”

But as a new language evolves, it’s a unique chance to explore not just the logic behind its language-design decisions, but also the underlying philosophy that will ultimately unite them all. What do programmers really care about in 2024? For the 100th episode of the podcast “Software Unscripted,” Lattner shared his insights from a career spent designing programming languages and compilers, along with lots of the infrastructure that goes around it.

Podcast host Richard Feldman — creator of the Roc programming language — began with the biggest question of all: Why? In a world with so many choices, why make a brand-new programming language at all? And Lattner had a quick answer: “It’s basically just a way to solve a problem.”

But it turns out that the gritty details of the answer — not just the “why,” but the “what” and the “how” — give a panoramic perspective on the whole programming language ecosystem of today.

Evolving Replacement Parts

Lattner agreed with Feldman’s description that Mojo is accessing Python’s ecosystem while “evolving replacement parts” to improve performance. And that work is ongoing. “One of our goals that we’re building into for this fall is make it super easy to make a Python package from Mojo,” Lattner said, partly to bring to Python programmers the advantages of Mojo’s better performance.

Mojo will be “subtracting all the complexity of interoperating with C,” Lattner said, while providing “the same performance, or better, that you get for C or C++.”

But then Lattner calls it “a natural thing” that happens as successful language communities start to scale up. “Programmers want to bring their skill sets forward — and as they do this, they bring it into adjacent domains that they want to apply the technology to.”

Of course, there’s a simpler answer, Lattner said later. “We’re building Mojo because we care about a lot of AI and GPU and accelerator stuff.”

“There’s so much stuff in the Python community that’s been about, like, ‘Let’s make Python unmodified go fast, and you can get 20x speed-ups,’ and stuff like this. But Mojo is saying, ‘Let’s not work forward from Python and try to make Python a little bit better.’ We’re saying, ‘Let’s work backwards from the speed of light of hardware!’ Unlock the full power of hardware — which isn’t just, you know, int being fast… but it’s also like accelerators and SIMD [single instruction/multiple data support for parallel processing] and like all these kinds of things…

“It depends on your workload, but we have a blog post showing that Mojo can be 65,000 times faster than Python.”

“And the usual pushback on that is… ‘Well, you would never write numeric code that’s doing math and dense arithmetic in Python.’ But that’s literally the point of Mojo — is to make it so all that code you would never write in Python. You can write in a language that’s coherent and consistent with Python. So you don’t have to switch languages!”

SIMD Support — and Second Syntaxes

To offer first-class support of parallel processing, Mojo’s SIMD-supporting syntax includes elements for all of the different number types.

Screenshot from Mojo SIMD syntax documentation

Here Lattner paused for a pointed aside about programming languages today. “And oh, by the way, all processors have had SIMD since like the late ’90s — and so why is it that no languages have embraced modern computers? It’s unclear to me.” (Later he finds himself marveling again that “so much code is still single-threaded.”)

Mojo also found another way to improve its performance over Python. “Python’s integers are big integers,” Lattner said, “like you can make an arbitrary-sized integer, and it’s a heap-allocated thing, and it’s reference semantics — all this stuff.” Mojo kept the name — (lowercase) int — in its syntax but while also including its own alternate type in the standard library — Int (with an uppercase I). And this Int is a struct, greatly easing the work of Mojo’s compiler.

So while Mojo still supports Python’s original syntax, if you switch to Mojo’s version of int “you get way better performance. You get better predictability. It will run on a GPU, etc., etc. And it’s not about one being better than the other. It’s a tradeoff.”

Getting Complex — and Unlocking Superpowers

There’s another new feature in our modern world. As Lattner describes it, “Some of these chip people” decided it’s important to fully support math with complex numbers (which include so-called “imaginary” numbers, which are widely used in technical applications including engineering and physics formulas). “And so once somebody puts something into hardware and said, ‘Wow, this is 10x faster than doing individual multiplies and adds,’ you kind of have to say, ‘Okay, well, 10x improvement — because they put into silicon… How do we expose that and then make it so people can use this stuff without having to know about it?”

So Mojo allows the defining of structs using complex numbers, with simple behavior and “a bunch of methods — including multiply.” And then good things can happen if the compiler detects the presence of complex number-accelerating hardware with a special speedy instruction for multiplication. “Boom! Everybody that uses complex numbers can be accelerated. They don’t have to worry about it.”

With Mojo, Lattner did keep Python’s operator overloading — the ability to write your own customizations for a symbol’s default behavior — even using Python’s syntax to preserve compatibility. But in the end, a lot of that extra complexity has been outsourced to library developers.

At one point Lattner said he knows a lot of compiler engineers but wants to take the “ecosystem of talent” that exists higher up the stack where the library developers live — those programmers who deeply understand their domain, along with things like performance-enhancing GPU tricks. “My quest with Mojo is really about unlocking those people and giving them superpowers.”

Later he said this is in contrast to “a trend that I’ve seen over the last five or 10 years in this space… ‘Put sophistication into the compiler, lock it up, throw away the key and trust us — us compiler people have got it’… Because what I’ve seen is that that’s not actually really that true. … A compiler is rarely going to give you a 10x improvement. But somebody working at the application domain, because they know the application — totally can, because they can use the right tool for the job.”

The end result? In a domain where even numbers come in over a dozen different types, “we can just have people define these things in libraries… That’s actually great — and it reduces pressure on the language from having to churn with all the hardware!”

Mojo’s Community

The interview ended with Lattner calling out to interested programmers, suggesting they check out Mojo’s web page and its “ton of documentation. The community is amazing! We have a Discord channel — I think we have 20,000-ish people on Discord, all talking about different stuff, building things.”

He also added a word of encouragement. “Mojo is not just an AI language. It’s also being used to build web servers and GUI libraries and all kinds of stuff by the community. And so we love for people to get involved. Mojo is still pretty early, and so we’re still adding core capabilities and building out the libraries.

“But we have a huge community of people that are really enthusiastic, and I’d love for people to get involved.”

Group Created with Sketch.
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.