编写智能体时,哪种编程语言最合适?
Key Highlights
As AI coding assistants sweep through developer workflows, a seemingly basic but intuition-dominated question resurfaces: when writing AI agents, should you use dynamic languages like Python and JavaScript, or static languages like Go, Rust, and TypeScript? A widely cited rule of thumb claims dynamic languages save more AI model tokens, and are therefore naturally cheaper in LLM-driven coding. But does that claim really survive a real test? The experiment in this article gives a counterintuitive answer that should make engineering teams reconsider the defaults they have adopted without evidence. The headline finding is that the advantage flips depending on how much effort the model is allowed to spend, which is a dimension most prior discussions ignored entirely.
What Happened
To verify the claim, the author designed a controlled experiment: using GPT-5.6 Sol to drive an AI agent, they implemented a zstd decompressor in both dynamic and static languages. zstd, an efficient compression algorithm open-sourced by Meta, demands careful memory layout, bit manipulation, and boundary handling, making it a good way to expose differences in expressiveness and rigor between languages. The experiment did not stop at a single successful run; it observed model behavior across different effort tiers, which is essential because agent coding quality is known to vary sharply with how much effort the model is allowed to spend on a task. Treating effort as a variable rather than a constant is what makes this study more honest than the casual comparisons circulating online.
The results were surprisingly non-linear. At medium effort, dynamic languages, with less boilerplate and more flexible type systems, did let the agent produce working results faster and consume fewer tokens. But once effort was pushed to ultra, the situation reversed: static languages, with the strong constraints of a compiler and explicit types, actually made the model more stable on complex boundary handling, and overall performance overtook dynamic languages. More importantly, the author re-examined several widely cited earlier benchmarks and found hard flaws such as incorrect test paths, making some of their conclusions unreliable and suggesting the popular "dynamic saves tokens" narrative rested on weak evidence gathered from the wrong test setups.
Technical Details
Two technical points are worth unpacking. First, token economics: dynamic-language code is shorter and prompts are leaner, giving an inherent edge on shallow tasks where the model mostly needs to produce a small, self-contained routine. Second, the role of the type system as an "implicit constraint": static languages offload many invariants to the compiler, reducing the burden on the model to reason about correctness inside the context window. When tasks are small, the former dominates; when tasks reach system-level complexity, the latter kicks in, because the model struggles to uphold every boundary condition across a long context where attention can drift and earlier facts get buried.
Versus Competitors
Horizontally, this discussion aligns with observations from Anthropic, OpenAI, and others about "which language models are better at": no single language wins at every tier. Claude and GPT families have the thickest training corpus in Python, yet on tasks needing strict memory safety like C or Rust, strong typing becomes the model's safety net, reducing out-of-bounds and null-pointer style errors. This explains why large production systems still favor static languages despite the model's familiarity with Python, and why the "best language" question has no single answer across the full spectrum of agent workloads that range from quick scripts to long-lived infrastructure.
Industry Impact and Use Cases
Put simply, choosing a language cannot be reduced to "does it save tokens." For prototyping, scripting, and one-off data processing, dynamic languages remain efficient and pleasant to work with. For production-grade agents that need long-term maintenance and involve concurrency and memory safety, the stability advantage of static languages at ultra effort gets amplified, lowering the odds of silent corruption in edge cases. The author's conclusion is restrained: leading on trivial benchmarks does not generalize to real, large problems. Teams should pick languages by task complexity and maintenance horizon, not by a popular saying, and should never infer production behavior from toy-task scores that were measured under the wrong assumptions. The broader lesson for the community is humility: a benchmark is only as trustworthy as the harness behind it, and a number that looks decisive may rest on a test path the model was never meant to traverse, so always read the setup before quoting the score to colleagues or clients.