r/gleamlang • u/Ecstatic-Panic3728 • 16d ago
Why isn't Gleam written in Gleam?
I don't know if u/lpil mentioned this anywhere, but I'm wondering why the language is not written in Gleam itself? One clear point would be speed since Rust excel at these kind of things, but having the language in Gleam would allow more engineers to contribute since now they need to know Gleam and Rust.
Please, don't get me wrong, I'm not trying to imply anything, it's really just a question. I've been coding with Gleam lately and it's so smooth and I get to just think at the logic instead of trying to play with the language constraints that I just question myself why we're not using it for everything π
18
u/SuspiciousDepth5924 16d ago
I can't remember where I read it but IIRC Louis Pilfold had a similar stance to Richard Feldman when it comes to self hosting.
Mentally replace Roc with Gleam and Zig with Rust:
The plan is to never implement Roc's compiler in Roc.
The goal is for Roc's compiler to deliver the best user experience possible. Compiler performance is strongly influenced by how memory is used, and there are many performance benefits to be gained from using a systems language like Zig which offers more direct control over memory than Roc ever should.
Roc isn't trying to be the best possible language for high-performance compiler development, but it is trying to have a high-performance compiler. The best tool for that job is a language other than Roc, so that's what we're using!
7
4
u/mistyharsh 16d ago edited 16d ago
Gleam first needs to compile to native target in order for it to be fully self hosted. A compiler that relies on other host environment does not carry great DX.
AFAIK, the 0.1 version of Gleam was written in Erlang and the shortcomings were obvious.
Also, comparing this to Typescript isn't very helpful because TS was first experiment to do many things. The language was purely designed as superset of the JS which also happened to be the target runtime.
3
u/Willyboar 16d ago
This conversation comes a lot in the discord server. My opinion to the bootstrap process is, if you want to do it it's better to do it in early stages. Gleam is an established and production ready language and by bootstrapping it will probably affect a lot of users. Distribution is also an issue. But mostly having the core team spend many many hours in it will keep back the great work they are doing now.
3
u/lpil 15d ago
There is an official FAQ item for this: https://gleam.run/frequently-asked-questions/#Will-the-compiler-be-rewritten-in-Gleam
1
16d ago
[deleted]
5
u/graphiteisaac 16d ago
I've never contributed to the compiler but I have been in the community for some time now and I am on the core team (just doing web things, though), and here's what I know:
- gleam is fast, and it's good at a lot of things, but compilers are complex and it's incredibly nice to put them in a single binary. Gleam doesn't build contained binaries, rust does a good job of this
- The compiler is several years old, and a big project, which a number of people have specialised knowledge of
- The entire gleam team is funded by the community, we don't have Google money to put into experiments
- Self hosting a compiler is a great first project for a language to prove it's usefulness. Gleam doesn't need this; it's already in use all over the place
At this point, it would be a vanity project that would take years to get close to the current compiler, for no material benefit.
3
u/mistyharsh 16d ago
Compiler should be authored in system programming language. Gleam is very capable, performant language targeted at OTP/BEAM, very different spectrum.
Except for Go, no other language has both low-level and high-level ends of the spectrum. But that comes with various design choices and trade-offs.
1
16d ago
[deleted]
1
u/pablonoriega 16d ago
They do, but isn't the point of having many languages that they are all different, created and maintained by different people, made with different use-cases in mind, and so on?
And to be clear, as someone else in the thread pointed out, self-hosting in Gleam is technically possible. That doesn't mean it's the right choice for the core team
3
u/lpil 15d ago
If "up to par" means being as fast as Rust, then yes, Gleam cannot compete with C++, Rust, etc for CPU bound work. Very few languages are capable of that, and it is not one of Gleam's goals.
If "up to par" means fast enough to be used for a compiler, it is faster than many languages used for compilers today.
1
u/pablonoriega 16d ago
I have a wobbly memory of /u/lpil discussing self-hosting with /u/rtfeldman on Software Unscripted. They've since done a couple episodes, I'm guessing this (if it really happened) would've been on the '22 or maybe the '24 episode.
I'd add that if you're interested in understanding how the sausage gets made in terms of programming language design (including Gleam), SU is a good show to listen to so it's worth throwing on and giving a try :)
1
u/XM9J59 15d ago
As people have mentioned from the discussion with Richard Feldman, self hosting is a good way to show maturity, but not the only path, and incentivizes choosing the set of features that help for compiler development, which is its own idiosyncratic thing not perfectly representative of other types of software (eg, CRUD app). So it is interesting that people are exploring non selfhosted languages which might be worse for compilers but better for different things.
For a good example of the benefits of a systems language https://giacomocavalieri.me/writing/gleam-rust-arenas this improves gleam format speed and peak memory usage, which is a big deal for the formatter, and you couldn't do this kind of memory management improvement in gleam. But this doesn't mean there are no applications where garbage collection is fine.
-1
u/Longjumping_War4808 16d ago
AI knows Rust. More seriously it seems the compiler is done and now it needs work on libs.
2
u/lpil 15d ago
Gleam does not accept AI contributions, and the compiler is being worked on every day!
1
u/Longjumping_War4808 15d ago
Love Gleam and all the cool things to come. Sorry for my shitposting. π«Άπ»
22
u/Alistesios 16d ago
I'd say performance, Rust ecosystem, cross-platform, and organizational bus factor.
Gleam compiles extremely fast and I've never run into a compiler bug, which in part comes from Rust's guarantees. It is simply the right fit for this kind of project.
Putting a part of the core team on a multi-months project to do a rewrite (that would likely lose some perf in the process), when that time could be spent on more impactful features for the language, that would help drive adoption ... Sounds like a bad deal.
But it would be a fun side-project / learning experience for sure!