单线程之美学
Aesthetics of single threading

原始链接: https://ta.fo/aesthetics-of-single-threading/

## 单线程的美学 本文认为,我们对“多任务处理”的现代痴迷从根本上来说是低效的,这反映了一种有缺陷的计算机系统。就像单核处理器因持续的上下文切换而导致性能下降一样,我们的大脑在快速切换任务之间消耗大量能量,导致疲惫和倦怠——一种类似于计算机“颠簸”的状态。 作者将此与*单线程*的优雅形成对比——全神贯注于一次一项任务。就像高效的异步编程一样,真正的生产力和满足感来自于*阻塞*——完全沉浸而不被打断。 品味浓缩咖啡或真正倾听他人等深刻的满足感,都源于这种专注的状态。虽然承认持续连接的吸引力以及效率的错觉,但作者渴望一种更简单的精神状态:一个闪烁的光标一次处理一件事,按顺序处理输入和输出,并在专注、不匆忙的注意力中找到美。

黑客新闻 新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 单线程的美学 (ta.fo) 7 分,by todsacerdoti 1小时前 | 隐藏 | 过去 | 收藏 | 1 评论 帮助 01HNNWZ0MV43FF 5分钟前 [–] 阻塞就像躺在床上等发工资才能起床。多线程就像把一个简单的任务交给别人,他们会做得很慢,而且需要不断解释,这样看起来我就不那么忙了。单线程就像写完并发送一封邮件后回到工作。回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请YC | 联系 搜索:
相关文章

原文
Aesthetics of Single Threading | ta.fo Journal

Code is on the right monitor, and Slack is on the left. A YouTube playlist flows through my noise-canceling earphones. My fingers hit Alt+Tab before I even make a conscious decision, moving back and forth between the browser and the terminal.

We call this multitasking. we mistake it for a skill representing the capable modern person handling multiple things simultaneously. However, from an engineering perspective, this is a clear error. The human brain is not a state-of-the-art multi-core processor. It is closer to an old single-core chip from the 90s. The tasks we believe we are doing at the same time are actually just switching so fast that the transitions are invisible to the eye.

Stopping one task to move to another in an operating system is called context switching. The problem is that this switch is never free. If a CPU wants to stop task A to work on task B, it must save the state of A and load the new state of B. This inevitably generates overhead. When a brain deeply immersed in coding checks a single messenger notification and tries to return to the code, it wastes a massive amount of energy just trying to restore the context.

You have likely felt exhausted on your way home from work despite feeling like you accomplished nothing. That is not because the total volume of work was high. It is because your CPU usage hit 100% all day just from changing contexts. In computer science, we call this thrashing. It describes a phenomenon where a process cannot do actual work and pours all its resources into swapping pages until it eventually freezes. While burnout often looks like an emotional issue, it is often closer to systemic heat caused by excessive context switching.

Developers prefer asynchronous methods for efficiency. We make a data request and process other tasks without waiting for the response. Our lives have come to resemble this asynchronous processing. We watch the news while eating, text while walking, and calculate our next schedule while having a conversation. We consider waiting a waste and pack every gap tight.

Paradoxically, the most beautiful moments in life come from complete blocking.

You do not move to the next line until the function returns a value, waiting with the process completely stopped. This is not inefficiency. It is a state of immersion where a single object monopolizes every resource of the system called “me.” On weekend mornings, I become a single thread for a moment in front of my espresso machine.

I tamp the finely ground beans horizontally and lock the portafilter tightly into the group head. As the machine hums and reaches its peak pressure, I watch the high-density liquid struggle through the resistance of the coffee grounds and drop heavily. During those thirty seconds while the timer counts up and the golden crema fills the cup, every bit of computing power in my brain is allocated to the single process of extraction. There is no room for smartphones, worries, or yesterday’s unfinished work to intrude.

It is the same when listening to someone. I stop “asynchronous listening,” where I prepare my reply before the other person is finished speaking. I simply listen. I hold off on output until the input is fully complete. This allows the other person’s words to enter as temperature rather than just content. Simple blocking creates the depth of a relationship.

Of course, I know the truth. The moment I finish writing this, I will turn on my smartphone again. I will turn on YouTube while replying to messages and write code while shoving down my food. I am a helpless legacy system after all. I will inevitably be dragged by the gravity of efficiency back into the swamp of multitasking.

But sometimes I long for that perfect logic. On days that are hopelessly tangled, I imagine terminating all background processes. I want to leave just one main() function to handle just one thing at a time. I want to process when input arrives and output when processing ends.

That simple and elegant single-thread cursor is quietly blinking inside my complex head.

#Daily #Dev #Philosophy

联系我们 contact @ memedata.com