Live data from Hacker News

Which programming languages are most token-efficient?

martinalderson.com

11–20 of 96 posts

Re: Which programming languages are most token-efficient?

#11
It strikes me that more tokens likely give the LLM more time/space to "think". Also that more redundant tokens, like local type declarations instead of type inference from far away, likely often reduce the portion of the code LLMs (and humans) have to read.

So I'm not convinced this is either the right metric, or even if you got the right metric that it's a metric you want to minimize.

Re: Which programming languages are most token-efficient?

#12
post #11

It strikes me that more tokens likely give the LLM more time/space to "think". Also that more redundant tokens, like local type declarations instead of type inference from far away, likely often reduce the portion of the code LLMs (and humans) have to read. So I'm not convinced this is either the right metric, or even if you got the right metric that it's a metric you want to minimize.

I think separating thinking tokens from "representing" tokens might be a better approach, like what those thinking models does

Re: Which programming languages are most token-efficient?

#14
This is interesting research; thank you for doing it.

I am not sure token efficiency is an interesting problem in the long term, though.

And in the short term I wonder if prompts could be pre-compiled to “compressed tokens”; the idea would be to use a smaller number of tokens to represent a frequently needed concept; kind of like LZ compression. Or maybe token compression becomes a feature of future models optimized for specific tasks.

I was wondering last year if it would be worthwhile trying to create a language that was especially LLM-friendly, eg that embedded more context in the language structure. The idea is to make more of the program and the thinking behind it, explicit to the LLM but in a programming language style to eliminate the ambiguity of natural language (one could just use comments).

Then it occurred to me that with current LLM training methodology that there’s a chicken-and-egg problem; it doesn’t start to show rewards until there is a critical mass of good code in the language for LLMs to train on.

Re: Which programming languages are most token-efficient?

#15
post #2

Not surprisingly, it is J [1], an APL dialect. [1] https://www.jsoftware.com/

I knew it without the reading. But having each system call in 2 versions not even closely related to each other (monadic/diadic) requires me to have a hard time doing learning. I very appreciate this language for shortness but this kind of shortness might annoy.

Re: Which programming languages are most token-efficient?

#16
post #6

Realistically, it’s also a function of how many iterations it takes for an AI agent to correctly solve a problem with a given language. I’d imagine most AI agents would frequently have to redo J or F# code, as they are fairly uncommon languages with much smaller training set than JavaScript or Python.

I can say that for F# this has been mostly true up until quite recently. We use F# at work and were mostly unable to use agents like Claude Code up until the release of Opus 4.5, which seems to know F# quite well.

Re: Which programming languages are most token-efficient?

#17

I doubt this to be a meaningful metric for anything but code exploration in a larger codebase. E.g. when it comes to authoring code, C, which comes language, is by far one of the languages that LLMs excel most at.

I guess it also depends on which dataset LLM was trained on. Rare or niche languages get fragmented into more tokens even if the code itself is short. So two languages with the same number of characters can produce very different token counts because one aligns with what the model has seen millions of times and the other does not.

Re: Which programming languages are most token-efficient?

#20

This is kind of just a measurement of how representative a language is in the distribution of the tokenizer training. You could have a single token equal to “public static void main”.

You could, but you wouldn't when those keywords can all change in equivalent contexts.
Post reply on HN