跳到主内容
@wquguru
精选72Hacker News Best(web_list)技巧与观点

Huzzah:用声明式伪代码替代自然语言提示的AI编程实验

Huzzah:一种利用AI辅助编程的新方法

原文
发到 X

If you’re a software engineer like me, the first few months of 2026 were incredible. Coding agents suddenly became good enough that we no longer needed to manually write code. But if you’re like me, then sometime later you hit a wall. The honeymoon period ended, and the novelty wore off. No more dopamine hits.

如果你和我一样是软件工程师,2026 年的头几个月简直不可思议。编码代理突然变得足够强大,我们不再需要手动编写代码。但如果你和我一样,那么过了一段时间后,你会撞上一堵墙。蜜月期结束了,新鲜感也消退了。不再有那种多巴胺激增的快感。

It’s August, and I feel utterly fatigued. To be honest, I’m sick to death of writing longform English to describe every change I want to my codebase. However, I also don’t want to go back to writing all my code manually. There was real tedium in that practice that I’d prefer to avoid for…well, the rest of my life.

现在是八月,我感到筋疲力尽。老实说,我已经厌倦了用长篇大论的英文来描述我对代码库的每一项更改。然而,我也不想回到手动编写所有代码的时代。那种做法充满了真正的枯燥乏味,我宁愿余生都避免……好吧,余生的大部分时间都避免。

And yet, I sense that I need to have better insight and control over what my code is doing. I want to know that my output is high quality, reliable software. I want to feel good about myself as a professional. So I’m trying to find a way to have my cake and eat it too.

尽管如此,我感觉到我需要对自己的代码在做什么有更好的洞察力和控制力。我希望知道我的输出是高质量、可靠的软件。我希望作为一名专业人士能对自己感到满意。所以我正在寻找一种既能拥有蛋糕又能吃掉它的方法(鱼与熊掌兼得)。

My problem with coding agents is that

我对编码代理的问题是

  • There’s no reliable record of human intent. Prompts are discarded, and the code may or may not have been generated by AI. We’ve lost the central authority that expresses what the human wants out of the machine, and I think it’s important to contend with that fact.
  • AI chats are imperative, step-by-step instructions that describe changes to the application, not the application itself. This means instructions are often repeated, and thus consume tokens, many times over the course of development. This is inefficient.
  • Much of natural language exists for social reasons, not informational. The average sentence is scarce in real information. Writing in this manner, to a machine, is cumbersome.
  • 没有可靠的人类意图记录。提示词会被丢弃,而代码可能由 AI 生成,也可能不是。我们失去了表达人类对机器期望的中心权威,我认为必须正视这一事实。
  • AI 聊天是命令式的、逐步的指令,用于描述对应用程序的更改,而非应用程序本身。这意味着指令经常被重复,从而消耗令牌,在整个开发过程中往往被多次消耗。这是低效的。
  • 自然语言的大部分存在是为了社交目的,而非信息传递。平均而言,句子中蕴含的真实信息寥寥无几。以这种方式向机器写作显得笨拙繁琐。

To address these problems, I’m building an experimental editor. I’m calling it Huzzah, and it poses an alternative paradigm for working with LLMs.

为了解决这些问题,我正在构建一个实验性编辑器。我将其命名为 Huzzah,它提出了一种与 LLM(大型语言模型)协作的替代范式。

With coding agents, prompts are (a) longform, (b) imperative, and (c) transient. With Huzzah, prompts are (a) pseudocode, (b) declarative, and (c) persistent.

使用编码代理时,提示词是 (a) 长篇大论的,(b) 命令式的,以及 (c) 瞬态的。使用 Huzzah 时,提示词是 (a) 伪代码形式的,(b) 声明式的,以及 (c) 持久的。

It’s easier if I just show you.

如果我直接展示给你看,会更容易理解。

Your browser does not support embedded video. You can

你的浏览器不支持嵌入视频。你可以

watch the Huzzah demonstration directly

直接观看 Huzzah 演示

.

.

Comparing fizz buzz

比较 fizz buzz

Let’s take a very simple example - say you want to use AI to create fizz buzz. We’ll do this twice - once with coding agents and another with Huzzah.

让我们举一个非常简单的例子——假设你想利用 AI 创建 fizz buzz(FizzBuzz 游戏)。我们将做两次——一次使用编码代理,另一次使用 Huzzah。

With coding agents

使用编码代理

You start a chat in your tool of choice, and type something like the following:

你在你选择的工具中启动一个聊天窗口,并输入类似以下内容:

Create a function that loops 100 times. If the number is divisible by 3, print “fizz”. If the number is divisible by 5, print “buzz”. If the number is divisible by both (like 15 for example), print “fizz buzz”.

创建一个循环 100 次的函数。如果数字能被 3 整除,打印“fizz”。如果数字能被 5 整除,打印“buzz”。如果数字能同时被两者整除(例如 15),则打印“fizz buzz”。

If you need to make an edit, you’d send a follow up message to the chat:

如果你需要进行编辑,你会发送一条跟进消息到聊天窗口:

Instead of looping 100 times, the function should take a number input and the function should loop that amount of times.

该函数不应循环 100 次,而应接受一个数字输入,并循环指定的次数。

You repeat this process until you’re satisfied.

你重复这个过程,直到满意为止。

With Huzzah

使用 Huzzah

You create a new file called fizz_buzz.hz. In it, you write a pseudocode representation, however you like. This is how I’d do it, personally:

你创建了一个名为 fizz_buzz.hz 的新文件。在其中,你可以随意编写伪代码表示。就我个人而言,我会这样做:

代码 · 5
fizz_buzz()
    loop 100
        modulo 3 ? "fizz"
        5 ? "buzz"
        both ? "fizz buzz"
代码 · 5
fizz_buzz()
    loop 100
        modulo 3 ? "fizz"
        5 ? "buzz"
        both ? "fizz buzz"

You save the file, and Huzzah automatically generates real code from it.

保存文件后,Huzzah 会自动从中生成真实代码。

If you need to make an edit, simply update your file:

如果你需要进行编辑,只需更新你的文件:

代码 · 5
fizz_buzz(n)
    loop n
        modulo 3 ? "fizz"
        5 ? "buzz"
        both ? "fizz buzz"
代码 · 5
fizz_buzz(n)
    loop n
        modulo 3 ? "fizz"
        5 ? "buzz"
        both ? "fizz buzz"

When you save the file, Huzzah captures the diff and uses it as the prompt to the LLM. The affected source code is thus regenerated.

当你保存文件时,Huzzah 会捕获差异(diff)并将其作为提示词发送给 LLM。受影响的源代码因此会被重新生成。

Some other examples

其他一些示例

To give you a better sense for what this could look like in other scenarios, here are some alternative examples.

为了让你更好地了解在其他场景下这可能是什么样子的,这里有一些替代示例。

1. Shopping cart

1. 购物车

代码 · 11
list cart
list inventory
mock_data = // include some mock data
init()
    inventory.fill(mock_data)
add_item(id)
    cart.add(item by id)
remove_item(id)
    cart.filter(item by id)
checkout()
    return cart.sum(item by price) and format as price
代码 · 11
list cart
list inventory
mock_data = // include some mock data
init()
    inventory.fill(mock_data)
add_item(id)
    cart.add(item by id)
remove_item(id)
    cart.filter(item by id)
checkout()
    return cart.sum(item by price) and format as price

2. Todo List

2. 待办事项列表

代码 · 12
Todo {
  id: int
  text: str
  completed: bool
}
add_todo(text)
    todos.add(text, completed = false)
toggle_todo(id)
    todo = todos.get by id
    todo.completed = NOT .completed
remove_todo(id)
    todos.filter by id
代码 · 12
Todo {
  id: int
  text: str
  completed: bool
}
add_todo(text)
    todos.add(text, completed = false)
toggle_todo(id)
    todo = todos.get by id
    todo.completed = NOT .completed
remove_todo(id)
    todos.filter by id

Benefits

优势

You should be able to see some benefits already. Notice how much more terse and readable the pseudocode is than the longform prompts? Here are some more:

你应该已经能看到一些好处了。注意伪代码相比冗长的提示词要简洁和易读得多吗?这里还有更多:

  • Writing prompts this way engages your mind, because it feels much more like you’re designing the shape of the code.
  • You can be as terse or as verbose as you like.
  • The pseudocode acts as developer documentation because a human wrote it to express their intent.
  • You could write a language agnostic pseudocode and use it as the basis for multiple language or environmental targets. Think complex algorithms, like a CRDT.
  • 以这种方式编写提示词能激发你的思维,因为这感觉更像是在设计代码的结构。
  • 你可以选择尽可能简洁或详尽的表达方式。
  • 伪代码充当了开发者文档的角色,因为它是人类为了表达意图而编写的。
  • 你可以编写与语言无关的伪代码,并将其作为多种语言或环境目标的基础。想想复杂的算法,比如 CRDT(无冲突复制数据类型)。

Caveats

注意事项

There are no silver bullets, of course. Some exceptions:

当然,没有银弹。以下是一些例外情况:

  • It’s entirely possible that there are issues with this approach at scale.
  • This is obviously more ideal for new codebases than existing ones.
  • If you lack domain expertise, natural language is probably the easier interaction method.
  • Some things may be more difficult to reliably express, like cross-file dependencies.
  • LSP-type features would not be available (though this could plausibly be generated).
  • 这种方法在大规模应用时完全可能存在一些问题。
  • 这显然比现有代码库更适合新的代码库。
  • 如果你缺乏领域专业知识,自然语言可能是更简单的交互方式。
  • 有些内容可能难以可靠地表达,例如跨文件依赖关系。
  • LSP 类型功能将不可用(尽管这可以合理地生成)。

Current state

当前状态

Huzzah is actively being developed, and exists only in an experimental state for now. You can find the source code and setup instructions here. Please give it a spin and let me know what you think!

Huzzah 正在积极开发中,目前仅处于实验阶段。你可以在这里找到源代码和设置说明。请试用一下并告诉我你的想法!

Cheers.

谢谢。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

另一事件,读法相近