TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: How to Write Readable Code

10 点作者 marijnz0r超过 3 年前
Hi HN, I write code and unit tests for other departments in my company. For me, writing code in a programming language feels natural, so I like to use the notation of the language itself. A colleague likes to write code more like prose so someone from another (non-IT) department should be able to read it. How do you deal with this in your company? I think I read an article about this a few days ago, but I can't seem to find it anymore. Does someone still remember this?

6 条评论

me_me_mu_mu超过 3 年前
I’ve worked with “code like prose” people and found them pretty difficult to work with. I’ve also found most of them to be not that great technically or they have exclusively Ruby on Rails backgrounds and can’t seem to function on any other technology or approach.<p>I don’t think the sales guy needs to be able to read channel handling logic or care about how the react code is organized.<p>Engineers should write good code that can be easily understood and modified by other engineers. Are engineers going to cold call people or run the financials? No their job is to build systems and keep them running.
notadev超过 3 年前
I’ve always tried to use naming of variables and methods to make it obvious what the code is doing. Something like:<p>``` if service_is_disabled: start_service() else: send_notification(“Service is running”) ```
评论 #29824558 未加载
eslav超过 3 年前
What does “code like prose” look like? I had a group project in college with a guy who used MS Word to write code in paragraphs..formatted like an English paper (I’m not kidding); is this what you mean?<p>(Looking back I often wonder how long this guy wrote code like this before someone said “knock it off”..)
评论 #29824344 未加载
mvaliente2001超过 3 年前
I think it&#x27;s important to keep a consistent style in a repository. Ideally, the style should be kept _among_ repositories too, but given that different people like different thing, allowing them to explore the pros and cons might be a better strategy to achieve it.
100011_100001超过 3 年前
You might want to look at BDD. It&#x27;s a way to be able to discuss what has to happen and use code to make it happen.
评论 #29824412 未加载
gushogg-blake超过 3 年前
Literate programming maybe?