少点错误 09月03日
软件工程中的“地基”:为何重要及如何构建
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

文章以房屋建造中的地基问题类比软件工程。指出直接在“裸土”上建造软件(即无良好基础)会导致“差异沉降”般的严重问题,表现为难以维护、易引入bug。文章强调了自动化测试和良好日志记录作为构建稳固软件“地基”的重要性。同时,也探讨了类型系统(如TypeScript)对增强地基的作用,以及项目规模、失败成本、代码复杂性等因素如何影响地基的投入程度,并提及了开发者动机和愉悦感在“过度建设”地基时的考量。

🏗️ 软件开发的“地基”至关重要,如同房屋的根基,直接影响着软件的稳定性和长期可维护性。忽视地基建设,即不重视基础的质量和工程实践,就好比在不稳定的土壤上建造房屋,最终会导致“差异沉降”,表现为代码易出错、维护困难,甚至项目失败。因此,理解并构建稳固的软件地基是成功的关键。

✅ 自动化测试和良好的日志记录是构建稳固软件“地基”的两个核心支柱。自动化测试能够捕获潜在的“裂缝”(bug),防止它们影响整个结构,提供一种“基础”来确保代码的稳定性。而详细的日志记录则有助于诊断和修复已经出现的“裂缝”,尽管它更多是“修复”而非“预防”,但也同样是整体地基的重要组成部分,帮助我们理解和解决问题。

⚖️ 构建软件地基的投入程度需要权衡,与房屋建造类似,需要考虑项目规模、预期寿命、失败成本以及代码的“重量”和“灵活性”。对于MVP或概念验证项目,过度投入地基可能不划算;但对于处理敏感数据或需要长期运行的项目,则应投入更多资源。TypeScript等类型系统可以增强地基的稳固性,但最终的决策应基于具体的项目需求和风险评估。

💡 在软件工程中,开发者自身的动机和工作愉悦感也是构建“地基”时不可忽视的因素。如果“过度建设”地基能够激发开发者的热情,让他们更愿意投入和构建,那么这种投入可能就是值得的。这表明,在技术决策之外,也应关注如何让开发过程本身更具吸引力和成就感。

Published on September 2, 2025 7:07 PM GMT

Suppose you have an empty plot of land and want to build a house. To someone without a civil engineering background, it may be tempting to just start building right on top of the bare soil.

However, this isn't The Sims. If you build your house on top of bare soil, you will likely face serious problems within a few years.

Why? Well, the short answer is "differential movement". But to explain what that means, let me first take a step back.

The goal for structural engineers: when you put something on the ground it should not move. In everyday life this is easy; objects are small and time horizons are short. If I'm at the park and I put my phone on the ground next to a tree, the soil isn't going to shift and cause a massive crack in my phone. But if I build a 200,000 pound house directly on the ground and wait a few months, I might not be so lucky.

The first thing to understand is that the ground isn't a solid, contiguous piece of matter. It's actually more like this:

Or maybe this:

This was an aha moment for me. Before watching this video, which I'm basing a lot of this section of the post on, my naive model of the ground was more like this:

That model serves me well when I put my cell phone down on the ground at the park, but it wouldn't serve me well in my hypothetical future as a home builder. The whole is composed of parts, and those parts can move independently of one another.

So what, exactly, actually causes the movement of these soil particles? Well, the weight of the home is part of it, but in practice, a lot of the issue is related to water. Soil expands when wet and shrinks when dry. Freeze-thaw cycles are especially bad. Tree roots can be a pain.

Anyway, why is this soil movement a problem? Well, take a look at this:

I don't know how to explain it well, but such differential movement can cause cracks.

To mitigate these risks, instead of building houses directly on soil, we build them on foundations. Something like this:

Or this:

When the soil moves beneath the foundation, the foundation will hopefully remain in tact. This allows us to accomplish our goal: when you put something on the ground it should not move.

Of course, even with a foundation, your luck will only last so long. Father Time and Mother Nature are a formidable duo.

If you want your foundation to last you 500 or 1,000 years instead of 75 years, that's probably doable — you can build something deeper and more solid — it's just going to cost you. Like most things, you'll need to make decisions about trade-offs. These decisions will depend on considerations like project size, time horizons, and budget.

Software engineering

What about software engineering? What would it mean to start building on top of "bare soil"? What sorts of "cracks" might form? After how long? How damaging would they be? What would a proper foundation look like? Which types of foundations are appropriate for which types of projects? And how long can a foundation realistically last?

As the idea for this post was brewing in my mind, I was hoping to discuss all of these questions in depth and say a bunch of smart and insightful things about them. But to be honest, that would be a bit beyond my pay grade. I'm a solid software engineer but I'm no John Carmack.

So then, I am pivoting to a more How To Write Quickly While Maintaining Epistemic Rigor type of approach. I'll describe some thoughts I have on some of these questions, and I'll leave it to people in the comments to continue the conversation. I know a lot of people here have software engineering backgrounds.



Discuss

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

软件工程 自动化测试 日志记录 TypeScript 技术债务 软件架构 Software Engineering Automated Testing Logging TypeScript Technical Debt Software Architecture
相关文章