代码的运行次数多于读取次数
Code is run more than read

原始链接: https://olano.dev/2023-11-30-code-is-run-more-than-read/

在编程中,人们经常听到“代码的运行多于阅读”,这强调了保持软件的易读性和易编辑性至关重要。 然而,仅仅专注于编写可维护的代码是不够的,因为最终,软件通过用户的频繁使用来达到其预期目的。 开发周期从设计和规划开始,经历创作、维护、部署、扩展、运营和调试等几个阶段。 此外,除了技术方面之外,还考虑成本、预算和时间表等运营角度,确保决策的平衡。 此外,业务目标的影响也不容忽视。 最终,开发提供卓越用户体验的软件必须仍然是重中之重,平衡利润和原则,而不是优先考虑短期收益而不是有意义的长期成果。

总的来说,本文讨论了考虑用户的重要性以及软件开发在构建软件之外的作用。 软件开发作为一门手艺的概念仅仅意味着开发“完美代码”,而不是专注于解决软件可以提供的问题,这是有局限性的。 作者强调了这样一个概念:在软件开发中,用户和业务可能并不总是重叠,尽管在实践中,业务和用户需求有相当多的交叉。 此外,作者认为“操作 > 用户”往往会低估用户的需求,并忽略维护和测试方面的考虑。 虽然对于标题的含义存在反驳和批评,但总的来说,本文提供的心理模型为软件开发从业者提供了宝贵的见解。 最终,目标仍然是为用户服务并确保可持续的解决方案。 代码应被视为一种工艺或服务,能够交付旨在满足最终用户需求的产品或解决方案。 总体而言,作者鼓励软件开发专业人员拥有更广阔的视野,认识到软件开发人员、业务代表、运营团队以及最终用户群体之间的相互作用。 这一认可为软件质量的潜在改进打开了大门,并确保解决方案符合最终用户不断变化的需求和不断变化的环境。
相关文章

原文


Code is read more than written

This phrase is, by now, common programmer knowledge, a reminder that the person first writing a piece of code shouldn’t buy convenience at the expense of the people who will have to read it and modify it in the future. More generally, code is read more than written conveys that it’s usually a good investment to make the code maintainable by keeping it simple, writing tests and documentation, etc. It’s about having perspective over the software development cycle.

Let me express this idea more succinctly:

I think this line of thought can be extended beyond code-writing and used as a rule of thumb to identify problems and make decisions.

Code is used more than read

Code is a means to an end. Software should have a purpose, it’s supposed to provide a service to some user. It doesn’t matter how well written or maintainable the code is, nor how sophisticated the technology it uses if it doesn’t fulfill its purpose and provides a good experience to the user:

user > maintainer > author

Or, since we won’t need to distinguish between developer roles anymore:

This is why, instead of guessing or asking what they need, it’s best to put the program in front of the users early and frequently and to incorporate what we learn from their feedback.

This is a strong mental model, just keeping the users in mind during development can get us quite far. It’s approximately how I learned the job and how I understood it for the first half of my career.

Code is run more than read

When I say “run” I don’t just mean executing a program; I mean operating it in production, with all that it entails: deploying, upgrading, observing, auditing, monitoring, fixing, decommissioning, etc. As Dan McKinley puts it:

It is basically always the case that the long-term costs of keeping a system working reliably vastly exceed any inconveniences you encounter while building it.

We can incorporate this idea into our little model:

It took me a while to fully grasp this because, in my experience, much of the software being built never really gets to production, at least not at a significant scale. Most software is built on assumptions that never get tested. But when you run your code in production, the KISS mantra takes on a new dimension. It’s not just about code anymore; it’s about reducing the moving parts and understanding their failure modes. It’s about shipping stuff and ensuring it works even when it fails.

Also, there’s business

I said that keeping the users in mind during development can get us very far. This works under the assumption that software that’s useful and works well, software of value to users, will be of value to the organization. It’s a convenient abstraction for developers: we produce good, working software, and the business deals with turning it into money. And it mostly works, especially for consumer and enterprise software. But, eventually, that abstraction proves to be an oversimplification, and we can benefit from incorporating some business perspective into our working process:

The most obvious example is budget: we don’t have infinite resources to satisfy the user needs, so we need to measure costs and benefits. There’s marketing, there’s deadlines. There are stakeholders and investors. There are personal interests and politics at play. Decisions that make sense for our software, our team or our users considered in isolation, but not when we consider the organization as a whole. Sometimes, we need to work on what generates revenue, not what pleases the user. I’ll get back to this.

Smells

We arrived at a little model that expresses the relative importance of various factors in software development, one that can perhaps help us see the bigger picture and focus on what matters. Now I want to look at some common software development dysfunctions and see how they map to the model.

Unmaintainable code

This is where we started. This is clever and lazy code that turns into spaghetti and haunted forests, this is premature optimizations, this is only-carlos-can-touch-that-module, etc.

Unusable software

Software from teams that don’t learn from their users or that put technology first. Over-engineered programs, “modernizations” that degrade the user experience, web apps that break the browser features, etc.

Works on my machine

Software that wasn’t designed with its operation in mind. This is overly complicated software with lots of moving parts, fancy databases for small data loads, microservice ecosystems managed by a single small team. Software prematurely architected for scale. Software designed by different people than the ones woken up at midnight when it breaks.

The right thing

Code considered as an end in itself. Software built by pretentious artisans, musicians of the Titanic, and Lisp Hackers.

Resume-driven development

Software produced when there’s nothing at stake and developers get to do whatever they want.

Imaginary software

This is software that’s built but rarely (or never) gets to production. I call this imaginary software. Charity Majors calls it living a lie.

Another kind of imaginary software is the one that doesn’t have users. (But scales). This is software that doesn’t solve a problem, or solves the wrong problem, perhaps nobody’s problem. Software that results from taking some hyped tech and hammering everything with it until something vaguely resembling a use case comes up.

Late capitalism

Venture-backed software without a business model or whose business model is grow-until-monopoly-then-exploit-users.

An elephant

If you didn’t rage-close the browser tab yet, let me wrap up by going back to this:

This one has ramifications that can be hard to swallow.

As I mentioned above, the way I learned the job, software was about solving problems for end users. This is summarized in one of the final tips of The Pragmatic Programmer, saying that our goal is to delight users, not just deliver code. But, since I started working as a programmer, and as software became ubiquitous, I’ve seen this assumption become increasingly hard to uphold.

There’s a lot of software being produced that just doesn’t care about its users, or that manipulates them, or that turns them into the product. And this isn’t limited to social media: as a user, I can’t even book a room, order food, or click on the Windows start button without popups trying to grab my attention; I can’t make a Google search without getting back a pile of garbage.

There’s a mismatch between what we thought doing a good job was and what a significant part of the industry considers profitable, and I think that explains the increasing discomfort of many software professionals. And while we can’t just go back to ignoring the economic realities of our discipline, perhaps we should take a stronger ethical stand not to harm users. Acknowledging that the user may not always come before the business, but that the business shouldn’t unconditionally come first, either:

user > ops > dev
biz > ops > dev
biz ≹ user

联系我们 contact @ memedata.com