Hacker News new | ask | show | jobs
by subarctic 22 days ago
I have a web app i've been using regularly and develop regularly with gleam on the frontend and backend. I have written very little of the code by hand and use claude to implement everything, open PRs and stuff and it works well. I like that it's typesafe and you can share code between the frontend and backend so easily, and you don't have to get a bunch of config right like you do if you want an all-typescript application. If I was writing it by hand I think I would find there's an annoying amount of boilerplate, but since ai is writing the code for me it's not a big deal.

Overall, I recommend it.

3 comments

What framework did you use for Gleam? I feel the last time I looked that was one of the big absent libraries.
this is what grinds my gears with gleam. afaik its not really possible to interact with elixir libraries? A project exists to try to make this 'easier' but the fact that it was not baked-in as first class is a huge smell to me https://github.com/gleam-lang/mix_gleam/

Perfect example: Clojure. Clojure is the textbook esoteric programmers dream... but it's SUPER easy to sell and integrate in a typical Java shop. Why? Clojure is Java. You can use everything on Maven. You can interop with any Java tooling. No hacks or BS required... it's a native compatibility. The fact that the Gleam did not opt for this level of congruence is mind boggling to me.

I could be wrong btw so please correct me if I am. I am genuinely interested in using Gleam in place of Elixir (I think they nailed syntax and got rid of a lot of bullshit) but it is unfortunately not a drop-in replacement. It should be.

There are two sides to compatibility with Elixir: using Gleam in Elixir and using Elixir in Gleam. The former is harder, the latter is easier (with caveats).

Using Gleam in an Elixir project did/does rely on mix_gleam. I've used it some years ago and it worked then, but I haven't had recent experiences. There is a pull request[0] to Elixir to add built-in support for Gleam and as I understand it the Gleam team have made several changes to Gleam tooling to facilitate it, but it's unmerged as of now.

Using Elixir in a Gleam project is just an external function away, just like using Erlang or JavaScript (when using the JS target). E.g.

  @external(erlang, "Elixir.Some.Module", "my_fun")
  fn my_fun(some_arg: Wibble) -> Wobble
You can also write .ex files in your codebase and use functions from them as externals and they'll be compiled by Gleam.

The two main issues on that side are macros and structs. Since Gleam doesn't know about Elixir source or Elixir macros, you can't use them directly. But you can have an .ex file that uses macros and then you can call functions from that file. Structs are trickier, because they're just dynamic maps with a special key-value pair, and maps in Gleam (called Dict) have fixed types for the keys and values. That means you can't model a struct as a Dict. Gleam uses records for its own custom types, so what you can do is either use records on the Elixir side (with the Record module or by hand), or map the Elixir side data structures to be more palatable for Gleam (and vice versa) in your external functions --- which is what you generally do with externals anyway. Of course, if you only intend to pass the Elixir structs around and then back to Elixir, you can model them as external types that are then opaque to Gleam.

[0] https://github.com/elixir-lang/elixir/pull/14262

https://github.com/lustre-labs/lustre for the frontend. The backend uses wisp
if the ai is writing everything wouldn't it be better to choose a more popular language?
Exactly the opposite -- in a lot of ways, mainstream languages represent a compromise that gives the worst of all worlds for the benefit of popularity. With AI, you can take advantage of unpopular esoteric languages that have measurable advantages over mainstream languages. Before, the choice for a mainstream language was too strong because of network effects. Now with AI those effects don't matter as much, so being mainstream isn't as much of an advantage.

The copious training data on mainstream languages doesn't really translate as a network effect, and therefore is kind of a red herring because the AI can use all that training on new languages as well. e.g. if you use a esoteric language that is vaguely object oriented, the AI will use its vast training on object oriented programs and apply it to your language instead of falling over because your language isn't Python and it doesn't have training data on it.

Moreover, the AI is trained on copious amounts of PL research, so it's not like the ideas in a new language are completely new to it.

Another BEAM-based language, Elixir, came in first in a recent agentic coding study: https://dashbit.co/blog/why-elixir-best-language-for-ai
In that Tencent study less common languages got easier problems. Which explains why racket also performed suspiciously well in it. The authors recognize the problem themselves. I like elixir, but it's imo embarrassing how often elixir people cite that study despite it not actually supporting what they claim.

A much more recent and imo more realistic comparison of different languages with ai, is openai's study reimplementing sqlite in different languages: https://openai.com/index/low-resource-programming-languages/

That showed about what we expect, that popular languages like python, javascript, java, C#, etc do best, while less popular languages like Common Lisp, Ocaml, Zig, etc do slightly worse. But the difference is small enough I'd still just choose whatever language and ecosystem I know best that is appropriate for a project.

What they did is they gave the AI a huge pile of docs and said "implement this". But they didn't give the AI any tests as part of its objective. I was under the impression it's generally common practice to use a test-driven development approach with AI, so I think it would have been more representative for them to have split their test corpus in half: one half it could see during implementation, and then the could test on the other half.

Also, they restricted access from the internet, so I think this would have disadvantaged less popular languages.

I would definitely be skeptical of a study that finds using an LLM/agent to write sqlite in JS being better than writing in Zig, but it strongly depends on what “better” or “worse” mean.
It means how much of the sqlite test suite it passed. They were just measuring correctness, not performance or memory consumption, where of course Zig should win.

But the aim of that experiment was measuring correctness of llm written code in different languages, so used sqlite as a benchmark considering it's fairly complex software with a comprehensive test suite. It is not suggesting that because a language scores better on that benchmark it'd be better suited to writing the next sqlite, due to obvious other factors like performance...

A more popular language like what? The more popular choice that I could think of was typescript and the world around typescript and javascript is so big and fragmented I think you'd end up with it the ai doing things in different ways in different places. Gleam is a smaller ecosystem but it also just feels better organized and more consistent which helps for keeping things consistent in your app.
Why's that?
Lots and lots of production code to train AI models.
That mindset is a bit dated when models can pull up docs for a few years now. You can even have it write itself a little guide for lesser known languages within its own agents file.
Programming models have been sophisticated enough for some time to not be restricted to specific languages. It's rather like the difference between a junior developer (who knows how to use a specific language) and a mid developer (who knows who to program generally).
Thanks for creating Gleam!

Is there any research that supports what you are saying here? I agree it mostly works, but I’d expect more API hallucinations and test cycles at a minimum.

No problem!

I don't have anything formal to share, but in my testing I've found it works much the same in all languages now.

The entire gleam language tour fits comfortably in a modern LLM context window. You're one web search away from "training" it yourself.
I'm not sure how much that matters. I suspect and anecdotally hear/see that compiler errors and docs are as/more important.
Too much schlock in the manifold, IMHO.
What's the fuckin point of any language ergonomic if you're not reading or writing it.
Not sure why you're asking this? But i mean if a language is more readable and has good typesafety it's easier for llms to understand, plus a lot of times you want to read and understand it even if you're not typing it out yourself
More ergonomic languages burn fewer LLM tokens to get the same result.
That's also not true at all. The most efficient languages for an LLM are the ones that have the largest datasets to reference. It knows the shape of a billion lines of Python. There's no evidence to suggest that "a more ergonomic language" burns less tokens cause it probably has to do multiple sweeps to get it "right". Otherwise some "agent/token efficient" language would've already been built and we'd all be using it. The defacto are just the most popular languages and that's not a coincidence.
Only if they gain that ergonomic advantage without complicating flow of control. Metaprogramming is costly for example, in the past so have been operator overloading and lazy evaluation.