今日已更新 339 条资讯 | 累计 19899 条内容
关于我们

The 3-line discipline

Hideki Mori 2026年06月29日 21:00 1 次阅读 来源:Dev.to

When I write code in unfamiliar territory, I write three lines, then I run it. Then I write three more lines, and I run it again. I've been doing this for twenty-four years. It's the most specific habit I have. I almost didn't write this article, because the habit feels too small to be worth describing — but then I noticed that it's the part of my way of working that I can never seem to explain to someone in real time. It needs writing down. Three principles The discipline rests on three things I believe about writing code. They're not deep. They've just stayed with me. 1. Trust nothing but your own code. If you can't trust the code you wrote yourself, what can you trust? Not a library, not a vendor's documentation, not your own assumption from yesterday. The only thing in the system whose behavior you can fully verify is the code you just typed, by running it. 2. Write in code, not in language. If you're describing what the code should do in Japanese or English, you're spending the same time you could have spent writing the code itself. By the time the code runs, the description is already done — by the code, in a more precise form than any language could give it. 3. Make three lines complete. The three lines you just wrote should be complete. Error handling included. Validation included. Logging included. Not "I'll add validation later." Not "I'll wrap it in a try-catch later." Three lines, complete, then run. (There's a small exception to this. Sometimes you do want to ignore every error and move on — for instance, when you're trying to understand whether the happy path works at all before you care about anything else. That's a different mode, used deliberately. It's not the same as "I'll handle errors later.") Why three lines Three lines is roughly the unit of thought I can hold completely. Five lines, and I start guessing what the third line did. Ten lines, and I'm reading the code as if it were someone else's. Three lines is the size that stays mine. When thre

本文内容来源于互联网,版权归原作者所有
查看原文