Software Engineering in the Age of AI人工智能时代的软件工程

For those of you who don’t know, when I’m not writing novels, I spend my days as a software engineer, writing code. The software industry these days relies heavily on artificial intelligence. Because it has studied trillions of lines of publicly accessible source code, because code solves problems with testable right and wrong solutions, and because code is structured specifically to be understood by computers, AI has gotten very good at writing code.对于那些不了解我的人,当我不写小说时,我是一名软件工程师,编写代码。如今的软件行业严重依赖人工智能。由于人工智能研究了数万亿行可公开访问的源代码,由于代码通过可测试的对错解决方案来解决问题,并且由于代码的结构专门设计为计算机可理解,因此人工智能在编写代码方面已经变得非常擅长。

Before programmers started using AI, a typical workflow looked like this:在程序员开始使用人工智能之前,典型的工作流程如下:

  1. Someone asks you to add a feature to an existing program.有人要求你向现有程序添加一个功能。
  2. You write up a formal definition of that feature describing what it should (and should not) do, how users can access it and how to test that it’s working correctly.你编写该功能的正式定义,描述它应该(和不应该)做什么、用户如何访问它以及如何测试它是否正常工作。
  3. You spend time researching which data structures, algorithms, code libraries and external services might serve best to implement this feature.你花时间研究哪些数据结构、算法、代码库和外部服务最适合实现此功能。
  4. You write the code to build the new feature, the tests to make sure it works as expected, and the documentation telling users how to use it and telling other engineers what they’ll need to know to maintain and debug it.你编写代码来构建新功能,编写测试以确保其按预期工作,并编写文档告诉用户如何使用它,并告诉其他工程师维护和调试它所需了解的信息。
  5. You create a “pull request,” asking other engineers in your organization to review and comment on your new code, and ultimately to approve it for use in the product.你创建一个“拉取请求”,要求组织中的其他工程师审查和评论你的新代码,并最终批准其在产品中使用。

Now that AI can consistently produce pretty good code, the software developer’s workflow looks like this:既然人工智能能够持续生成相当不错的代码,软件开发人员的工作流程如下:

  1. You write a prompt asking AI to create the new feature.你编写一个提示,要求人工智能创建新功能。
  2. You review what the AI wrote, making changes as you see fit or asking the AI agent to make those changes for you.你审查人工智能编写的内容,根据需要进行修改,或要求人工智能代理为你进行这些修改。
  3. You either merge the new code into the existing codebase yourself, or you create a pull request for someone else to review and merge it.你要么自己将新代码合并到现有代码库中,要么创建一个拉取请求供其他人审查和合并。

In the old workflow, the creative process happened mostly in your mind. In the new process, you supervise the creative process that unfolds inside the AI’s internal machinations. You’ve put some effort into creating a concise, thoughtful, accurate prompt to get the AI started on its work, but you haven’t done any of the hard thinking you would normally do in writing the code yourself. When you get code back from the AI, you’re essentially acting as an editor because, while AI can write code, it cannot always see the big picture of your project the way you can, and you need to make sure this new code won’t cause problems.在旧的工作流程中,创造性过程主要在你的头脑中进行。在新的流程中,你监督在人工智能内部机制中展开的创造性过程。你付出了一些努力来创建一个简洁、周到、准确的提示,让人工智能开始工作,但你并没有像自己编写代码时那样进行任何艰苦的思考。当你从人工智能那里得到代码时,你基本上是在扮演编辑的角色,因为虽然人工智能可以编写代码,但它并不总能像你那样看到项目的全局,你需要确保这些新代码不会引起问题。

AI does not know whether the code it just added violates some legal requirement to which your product is subject. It does not know if the request it makes to an external system is going to take ten milliseconds or ten minutes to fulfill. It does not know whether the actions of its code will conflict with some new feature that you know your teammates will be adding three weeks from now. It does not know whether the function it just wrote might introduce a new security problem when interacting with another function you wrote last month that handles sensitive information.人工智能不知道它刚刚添加的代码是否违反了你的产品所遵守的某些法律要求。它不知道它对外部系统的请求需要十毫秒还是十分钟才能完成。它不知道其代码的行为是否会与你所知你的队友将在三周后添加的某个新功能冲突。它不知道它刚刚编写的函数在与你上个月编写的处理敏感信息的另一个函数交互时,是否可能引入新的安全问题。

A senior developer does know these things, and this is why he or she needs to vet and often correct the AI code that appears to “just work.” To a senior developer, AI is a competent, fast-working junior or mid-level developer that, when properly directed, produces mostly solid work but lacks the institutional knowledge and the deep and broad systems-level knowledge that you have developed over the past twenty years.高级开发人员确实知道这些事情,这就是为什么他或她需要审查并经常纠正那些看似“正常工作”的人工智能代码。对于高级开发人员来说,人工智能是一个能干、工作快速的初级或中级开发人员,在适当指导下,能产生大部分可靠的工作,但缺乏你过去二十年积累的制度知识和深厚广泛的系统级知识。

Now, let’s back up for a second and make an analogy. Let’s say you’re a writer of historical novels. What does your workflow look like? Probably something like this:现在,让我们退一步,做一个类比。假设你是一位历史小说作家。你的工作流程是什么样的?可能如下:

  1. You picture a scene in which two statesmen are arguing outside St. Paul’s Cathedral in London in 1760. You consider what you need to know to write this scene accurately, including clothing, the atmosphere on the street and the political situation.你想象一个场景,两位政治家于1760年在伦敦圣保罗大教堂外争论。你考虑准确写出这个场景需要了解的内容,包括服装、街道氛围和政治局势。
  2. You crack open a number of books and start taking notes on the following, among other things:
    1. Based on their socioeconomic positions and their roles in society, what would your characters be wearing?根据他们的社会经济地位和社会角色,你的角色会穿什么?
    2. Who else is on the street with them? Vendors? Cabbies in horse-drawn carriages? What did those look like? Were the chimney sweeps out at that time of day? What about prostitutes and law officers?还有谁和他们一起在街上?小贩?马车车夫?那些看起来是什么样子的?那个时间扫烟囱的人出来了吗?妓女和执法人员呢?
    3. Who are the primary political figures about whom your characters argue, and what are their positions at the moment?你的角色争论的主要政治人物是谁,他们目前的立场是什么?
    4. What historical events from recent weeks or months are relevant, and how will they influence your characters’ argument?最近几周或几个月有哪些历史事件是相关的,它们将如何影响你的角色的争论?
  3. You go back to your writing, weaving the historical facts into a scene that you spin from imagination.你回到写作中,将历史事实编织成一个由想象力编织的场景。

The novelist and the software developer have a lot in common here. In reality, the novelist will have done much of her historical research before she begins writing, just as the software developer already knows from years of prior work which data structures and algorithms and which types of caches and databases will be suitable for the new feature he’s about to write.小说家和软件开发人员在这里有很多共同点。实际上,小说家在开始写作之前已经做了很多历史研究,就像软件开发人员从多年的先前工作中已经知道哪些数据结构、算法以及哪些类型的缓存和数据库适合他即将编写的新功能一样。

What both workers have in common is a deep feeling of engagement with the material they’re creating. They are entirely immersed in their work, to the point where they often lose track of time. In both novel writing and software development, it’s common for me and many of my peers to check the clock, dive into a problem, and then look at the clock ten minutes later to discover that four hours have passed.这两个工作者共同点是对他们正在创作的材料有深深的投入感。他们完全沉浸在工作中,以至于经常忘记时间。在小说写作和软件开发中,我和许多同行经常查看时间,然后投入一个问题,十分钟后再看时间,发现已经过去了四个小时。

This is the state of “optimal experience” that psychologist Mihaly Csikszentmihalyi described in his bestselling 1990 book, Flow. Writers, software developers, painters, musicians and all other creative types enter this state when time and circumstances permit. Many software engineers work after hours at home precisely because the lack of meetings and other interruptions outside normal business hours permit them to enter this state.这就是心理学家米哈里·契克森米哈赖在他1990年的畅销书《心流》中描述的“最优体验”状态。作家、软件开发人员、画家、音乐家和所有其他创意型人才在时间和环境允许时进入这种状态。许多软件工程师在家加班,正是因为正常工作时间之外没有会议和其他干扰,使他们能够进入这种状态。

Now, let’s put the historical novelist in the position of the software developer. She gets a call from her publisher saying they’ve found a way for her to bring four books to market each year instead of one book every two years. They’ve recruited a bunch of top-notch high school and college students who can each crank out five pages a day of competent writing for dirt cheap. The publisher wants the historical novels to maintain the original writer’s level of excellence, or to at least be close, so they’re retaining her services as an editor.现在,让我们把历史小说家放在软件开发人员的位置上。她接到出版商的电话,说他们找到了一种方法,让她每年推出四本书,而不是每两年一本。他们招募了一批顶尖的高中生和大学生,每个人都能以极低的价格每天写出五页像样的文字。出版商希望历史小说保持原作者的高水平,或者至少接近,所以他们保留她作为编辑的服务。

The novelist’s job is now to edit the work of the students, each of whom has been carefully prompted to write pages that should, with a little work, be stitched together into coherent chapters.小说家现在的工作是编辑学生们的作品,每个学生都经过精心提示,写出应该经过一些工作就能拼接成连贯章节的页面。

Anyone who has ever graded the work of high school and college kids knows that this is generally not rewarding work. If you’ve ever had to grade a hundred papers in a week, you know what a grind that is.任何曾经批改过高中生和大学生作业的人都知道,这通常不是一项有回报的工作。如果你曾经在一周内批改过一百篇论文,你就知道那是多么枯燥。

The novelist, like the software engineer, is no longer deeply engaged in her work. Editing is not creating. You do not give yourself over to your imagination. You do not immerse your mind and feelings in the process of invention. Instead, you’re rooting out problems, trying to clean up clumsy wording and redundant descriptions instead. The flow state is gone. You are now a cog in a larger process that doesn’t really value your creativity or your need to exercise it.小说家,像软件工程师一样,不再深度投入她的工作。编辑不是创造。你不会沉浸在自己的想象力中。你不会将你的思想和情感沉浸在发明过程中。相反,你在找出问题,试图清理笨拙的措辞和重复的描述。心流状态消失了。你现在是一个更大过程中的齿轮,这个过程并不真正重视你的创造力或你锻炼它的需求。

Worse still–and I have felt this personally after months of reviewing AI-generated code–your skills drop off sharply. When a new issue arises–a feature to be implemented, or a tricky bug to fix–the idea of wasting several hours on it feels insulting. Why should I dig through all that code when Claude can locate the bug in five minutes and start drafting a fix?更糟糕的是——在审查了几个月的人工智能生成代码后,我个人感受到了这一点——你的技能急剧下降。当出现新问题时——一个要实现的功能,或一个要修复的棘手错误——花几个小时处理它的想法感觉是侮辱性的。当Claude能在五分钟内定位错误并开始起草修复方案时,我为什么要翻遍所有代码?

Why indeed? Why should you or I invest mental energy in something we used to actually like doing, something that now feels like a chore, when the bot can do it for us?确实为什么?当机器人可以为我们做时,为什么你或我应该投入脑力去做我们曾经真正喜欢做、现在感觉像苦差事的事情?

Months of working with AI have made me noticeably lazier and stupider, at least when it comes to coding. (I don’t use AI when I write, for the very reason that writing itself is the act of organizing and clarifying my own thought. Letting the bot write for me would be like paying someone else to exercise for me and hoping that gets me in shape.)与人工智能合作几个月让我明显变得更懒、更笨,至少在编码方面是这样。(我写作时不使用人工智能,正是因为写作本身就是组织和澄清自己思想的行为。让机器人替我写作就像花钱请别人替我锻炼,却希望这能让我保持身材。)

I’ve also become more impatient at work, particularly when I get emails from coworkers that are clearly AI-written. The emails often ask me to review longer documents that were also written by AI. That always leaves me thinking, “If you couldn’t be bothered to write this, why should I bother reading it?”我在工作中也变得更加不耐烦,尤其是当我收到同事明显由人工智能写的电子邮件时。这些邮件经常要求我审查同样由人工智能写的更长的文档。这总是让我想,“如果你不费心写这个,我为什么要费心读它?”

I do use AI to answer basic questions. Want to know how Amazon’s managed databases compare to the offerings from Microsoft and Digital Ocean? Claude’s chatbot is a good place to get a high-level overview. From there, you can go to the sources to get more detail.我确实使用人工智能来回答基本问题。想知道亚马逊的托管数据库与微软和Digital Ocean的产品相比如何?Claude的聊天机器人是获取高层次概述的好地方。从那里,你可以去来源获取更多细节。

But I think that creative people choosing to hand over their most imaginative, flow-state thinking to an army of bots will be a mistake in the long run. Those AI bots got all their knowledge from us–from our code, our white papers, our poems and novels and news stories, our biographies and all the Stack Overflow answers that thousands of people spent decades writing from hard-won knowledge.但我认为,创意人士选择将他们最具想象力、心流状态的思考交给一群机器人,从长远来看将是一个错误。那些人工智能机器人从我们这里获得了所有知识——从我们的代码、白皮书、诗歌、小说、新闻故事、传记,以及成千上万的人花费数十年从来之不易的知识中编写的所有Stack Overflow答案。

The bots ate up all the data, which used to be free, and now they sell it back to us. No one answers questions on Stack Overflow anymore because people take their questions to Claude and ChatGPT. The publicly available knowledge that used to accumulate in free-to-use services like Stack Overflow is drying up, leaving the AI bots less to feed on for answers to future technical questions.机器人吞噬了所有曾经免费的数据,现在它们将其卖回给我们。再也没有人在Stack Overflow上回答问题,因为人们把问题带到Claude和ChatGPT。曾经在Stack Overflow等免费服务中积累的公开可用知识正在枯竭,留给人工智能机器人用于回答未来技术问题的食物越来越少。

The software companies fired all their junior developers because the AI bots are cheaper, as long as you have skilled senior developers to manage them. But with no junior developers in the pipeline, learning the hard way how to solve the truly complex, broad and deep problems–problems whose scope is simply too large for AI to handle–where will tomorrow’s senior developers come from? Who will be qualified to manage the bots in five years?软件公司解雇了所有初级开发人员,因为人工智能机器人更便宜,只要你有熟练的高级开发人员来管理它们。但是,没有初级开发人员在管道中,以艰难的方式学习如何解决真正复杂、广泛和深入的问题——那些范围太大以至于人工智能无法处理的问题——明天的资深开发人员将从哪里来?五年后,谁将有资格管理机器人?

The complex, broad and deep problems I speak of are too big to fit into AI’s “context windows” which describe the full scope of questions to be answered. You cannot now and may never be able to feed into AI a full understanding of every law that governs your product across a hundred different countries, every nuance of every related codebase with which your product must interact, every business rule embedded in the millions of lines of code that make up your product. A team of developers and managers can understand and apply this legal and institutional knowledge. It takes work, naturally, and is expensive. Complexity always is.我所说的复杂、广泛和深入的问题太大,无法放入人工智能的“上下文窗口”中,这些窗口描述了要回答的问题的全部范围。你现在不能,也许永远不能,向人工智能输入对管理你产品在100个不同国家的每项法律的全面理解、你的产品必须与之交互的每个相关代码库的每个细微差别、构成你产品的数百万行代码中嵌入的每个业务规则。一个由开发人员和管理人员组成的团队可以理解并应用这些法律和制度知识。这当然需要工作,而且成本高昂。复杂性总是如此。

But what happens when we resign all this work to the bots? What person anywhere will have the knowledge to verify that the work the bots are producing is correct?但是,当我们把所有这项工作交给机器人时,会发生什么?世界上还有谁有知识来验证机器人产生的工作是否正确?

A few years ago, I read an article, which I can no longer locate [1], about how the US Navy convinced Congress to fund the construction of an aircraft carrier that the Navy didn’t immediately need. “Why should we pay for that?” asked the senators and representatives.几年前,我读了一篇文章,我现在找不到了[1],关于美国海军如何说服国会资助建造一艘海军并不急需的航空母舰。“我们为什么要为此买单?”参议员和众议员问道。

The Navy replied, “Because the skills required to build an aircraft carrier were so hard won over so many decades that if we don’t build one now, we’ll forget how to do it in ten years.”海军回答说:“因为建造航空母舰所需的技能是经过几十年艰难获得的,如果我们现在不建造一艘,十年后我们就会忘记如何做。”

The Navy wanted the old hands, the engineers and craftsmen who had built the world-class ships no other country could match, to pass down to the younger generation the skills they would need to build what no one else on earth could build. The only way to do that was by actually doing it, to actually put the team through every step of designing and assembling the ship.海军希望老手们,那些建造了其他国家无法匹敌的世界级舰船的工程师和工匠,将建造地球上其他人都无法建造的东西所需的技能传授给年轻一代。做到这一点的唯一方法是实际去做,实际让团队经历设计和组装舰船的每一步。

Congress funded the project because, despite all our complaints about their inefficiency, partisan bickering, and general ineffectiveness, they had more foresight than most of our corporations. Instead of looking at the next earnings report, they were looking decades into the future.国会资助了这个项目,因为尽管我们抱怨他们的低效、党派争吵和普遍无效,但他们比我们大多数公司更有远见。他们没有看下一份收益报告,而是展望了几十年后的未来。

Companies in the software industry, from the largest corporations to the smallest start-ups, are off-loading creative work to bots because the short-term payoff is immense. Why pay ten developers to crank out one product per year when you can pay four people to crank out ten products with the help of Claude or Codex?软件行业的公司,从最大的公司到最小的初创公司,都在将创造性工作卸载给机器人,因为短期回报巨大。为什么付钱给十个开发人员每年生产一个产品,而你可以付钱给四个人,在Claude或Codex的帮助下每年生产十个产品?

For managers and investors, this looks like an obvious win. But the bill will come due soon enough. The cost of maintaining millions of lines of code is enormous, especially when no one fully understands the code because no one actually wrote it. Fixing bugs, adding features, and integrating new technologies into existing code is hard work. That work also will go to the bots, and in the long run, society will come to rely on systems that people did not create and people do not understand.对于管理者和投资者来说,这看起来是一个明显的胜利。但账单很快就会到期。维护数百万行代码的成本是巨大的,尤其是当没有人完全理解代码,因为没有人真正编写它时。修复错误、添加功能以及将新技术集成到现有代码中是艰苦的工作。这些工作也将交给机器人,从长远来看,社会将依赖人类没有创造、人类也不理解的系统。

As for me, a once-creative developer who worked hard to block out uninterrupted time each day so I could get deep into that creative flow state, the process of software development is no longer so rewarding. I am no longer so deeply immersed in my work. I don’t learn on the job the way I once did. I respond to the bot’s code suggestions and pull requests the same way most people answer their email and Slack queues. My job is to react, not to create.至于我,一个曾经富有创造力的开发人员,曾努力每天留出不间断的时间,以便深入那种创造性的心流状态,软件开发过程不再那么有回报。我不再像以前那样深度投入工作。我不再像以前那样在工作中学习。我对机器人的代码建议和拉取请求的反应,就像大多数人回复电子邮件和Slack队列一样。我的工作是反应,而不是创造。

As I wind down my career in software engineering, I think of the artisans of the mid-twentieth century, the woodworkers and metal craftsman who watched as the advent of plastic manufacturing undercut their work in ways from which they could not and would not recover. Sure, the toys and tools and instruments the craftsmen made showed a level of dedication that the factory-produced plastic models couldn’t match. But so what? To the public, a good-enough plastic toy was good enough. And if it broke in six months, it was so cheap they could buy another.随着我逐渐结束软件工程职业生涯,我想起了二十世纪中期的工匠,木匠和金属工匠,他们目睹了塑料制造业的出现以他们无法也无法恢复的方式削弱了他们的工作。当然,工匠制作的玩具、工具和仪器所展现的奉献精神是工厂生产的塑料模型无法比拟的。但那又怎样?对公众来说,一个足够好的塑料玩具就足够了。如果它在六个月内坏了,它太便宜了,他们可以再买一个。

Those millions of plastic products now pollute our oceans. The Great Pacific Garbage Patch is now three times the size of France.[2]那些数百万的塑料产品现在污染了我们的海洋。大太平洋垃圾带现在有法国面积的三倍大。[2]

This is where our internet is going now as AI, in the process of doing other useful work, cranks out the digital equivalent of a million tons of plastic debris each day.这就是我们的互联网现在的发展方向,人工智能在完成其他有用工作的过程中,每天产生相当于一百万吨塑料碎片的数字等价物。

And while computer programming, once a creative endeavor, has now been reduced to the task of minding the bots, remember that in your free time, your mind is still free and you may turn its energies to whatever you please. I still write as often as possible, and every time I emerge from that flow state, I feel like I’ve come back with something new from the depths of my own mind. Ideas that were once only vaguely felt are now more clearly articulated, and each becomes a step toward something higher, toward thoughts I could not have articulated at all, or even begun to think, without the practice of writing.虽然计算机编程曾经是一项创造性工作,现在已简化为照看机器人的任务,但请记住,在你的空闲时间,你的思想仍然是自由的,你可以将它的能量转向任何你喜欢的事情。我仍然尽可能多地写作,每次我从那种心流状态中出来时,我都感觉自己从自己思想的深处带回了新的东西。曾经只是模糊感受到的想法现在更加清晰地表达出来,每一个都成为通向更高境界的一步,通向那些没有写作实践我根本无法表达甚至开始思考的思想。

When choosing what to do with your time, choose wisely. Your library has more books than you could ever read. Your friends and family have hearts and desires the bots can never fathom. Your mind, once you remove the noise of the world at large, is still capable of imagination, creativity and flow.在选择如何利用你的时间时,要明智地选择。你的图书馆里有你永远读不完的书。你的朋友和家人有机器人永远无法理解的心灵和愿望。你的思想,一旦你移除世界的噪音,仍然能够想象、创造和进入心流。

Find it!找到它!


[1] The Rand corporation has published papers on the issue of the Navy losing critical engineering skills through atrophy and Defense News wrote a related summary of the problem at https://www.defensenews.com/opinion/2024/11/08/the-us-navy-is-at-risk-of-losing-vital-shipbuilding-skills/[1] 兰德公司发表了关于海军因萎缩而失去关键工程技能问题的论文,Defense News在https://www.defensenews.com/opinion/2024/11/08/the-us-navy-is-at-risk-of-losing-vital-shipbuilding-skills/上发布了相关的问题摘要。

[2] https://en.wikipedia.org/wiki/Great_Pacific_Garbage_Patch[2] https://en.wikipedia.org/wiki/Great_Pacific_Garbage_Patch