I just got access to the mojo test environment and am reading their “HelloMojo” document.
I’m not quite through the document, but my takeaway so far is this: if your primary goal is to take the large amount of python ML models that are out there and make them as portable as possible, this seems like a great tool for constructing that type of system. Modular is in the business of running ML models across many architectures; this tool feels specifically oriented around that goal, and I imagine it’s achieving that quite well.
I am somewhat surprised that they didn’t use Swift or Rust for solving these problems. I suppose it will be seen whether this can resolve the two language problem for existing Python users, especially outside of this use-case, but I have my doubts. I do not believe that Python users will move en-masse toward a compiled, typed systems language simply because it looks more like Python than C.
It’s taken a lot from Swift. For instance, values can be declared immutable by using let
, or mutable by using var
. Mojo also introduces struct
, similar to that found in many languages.
where classes are extremely dynamic with dynamic dispatch, monkey-patching (or dynamic method “swizzling”), and dynamically bound instance properties, struct
s are static, bound at compile time, and are inlined into their container instead of being implicitly indirect and reference counted.
Another alteration is method declaration. A user can implement a method with def
just like in Python. But they can also implement the same method with fn
. The semantics of the method call are the same, but fn
calls must contain type signatures, and arguments are immutable by default. In other words, fn
is more amiable to strict memory and type constraints often required for systems programming, like Swift:
def
is defined by necessity to be very dynamic, flexible and generally compatible with Python: arguments are mutable, local variables are implicitly declared on first use, and scoping isn’t enforced. This is great for high level programming and scripting, but is not always great for systems programming. To complement this, Mojo provides an fn
declaration which is like a “strict mode” for def
.
fn
and def
are always interchangeable from an interface level: there is nothing a def
can provide that a fn
cannot (or vice versa). The difference is that a fn
is more limited and controlled on the inside of its body (alternatively: pedantic and strict). Specifically, fn
s have a number of limitations compared to def
s:
This, to me, looks like Python + systems programming features, tackling a different set of problems from Julia, and with a very different approach. Essentially as advertised! I have no doubt it will find use and success, and I think as a language it will have strengths and weaknesses similar to Swift. It will be interesting to see how the community receives it and develops it.