Suffering-oriented programming

本文介绍了一种减少大型项目风险的开发风格——痛苦导向编程。通过先解决眼前问题再逐步完善优化的方法,确保工作始终聚焦于重要任务,降低项目的不确定性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Suffering-oriented programming

Someone asked me an interesting question the other day: "How did you justify taking such a huge risk on building Storm while working on a startup?" (Storm is a realtime computation system). I can see how from an outsider's perspective investing in such a massive project seems extremely risky for a startup. From my perspective, though, building Storm wasn't risky at all. It was challenging, but not risky.

I follow a style of development that greatly reduces the risk of big projects like Storm. I call this style "suffering-oriented programming." Suffering-oriented programming can be summarized like so: don't build technology unless you feel the pain of not having it. It applies to the big, architectural decisions as well as the smaller everyday programming decisions. Suffering-oriented programming greatly reduces risk by ensuring that you're always working on something important, and it ensures that you are well-versed in a problem space before attempting a large investment.

I have a mantra for suffering-oriented programming: "First make it possible. Then make it beautiful. Then make it fast."

First make it possible

When encountering a problem domain with which you're unfamiliar, it's a mistake to try to build a "general" or "extensible" solution right off the bat. You just don't understand the problem domain well enough to anticipate what your needs will be in the future. You'll make things generic that needn't be, adding complexity and wasting time.

It's better to just "hack things out" and be very direct about solving the problems you have at hand. This allows you to get done what you need to get done and avoid wasted work. As you're hacking things out, you'll learn more and more about the intricacies of the problem space.

The "make it possible" phase for Storm was one year of hacking out a stream processing system using queues and workers. We learned about guaranteeing data processing using an "ack" protocol. We learned to scale our realtime computations with clusters of queues and workers. We learned that sometimes you need to partition a message stream in different ways, sometimes randomly and sometimes using a hash/mod technique that makes sure the same entity always goes to the same worker.

We didn't even know we were in the "make it possible" phase. We were just focused on building our products. The pain of the queues and workers system became acute very quickly though. Scaling the queues and workers system was tedious, and the fault-tolerance was nowhere near what we wanted. It was evident that the queues and workers paradigm was not at the right level of abstraction, as most of our code had to do with routing messages and serialization and not the actual business logic we cared about.

At the same time, developing our product drove us to discover new use cases in the "realtime computation" problem space. We built a feature for our product that would compute the reach of a URL on Twitter. Reach is the number of unique people exposed to a URL on Twitter. It's a difficult computation that can require hundreds of database calls and tens of millions of impressions to distinct just for one computation. Our original implementation that ran on a single machine would take over a minute for hard URLs, and it was clear that we needed a distributed system of some sort to parallelize the computation to make it fast.

One of the key realizations that sparked Storm was that the "reach problem" and the "stream processing" problem could be unified by a simple abstraction.

Then make it beautiful

You develop a "map" of the problem space as you explore it by hacking things out. Over time, you acquire more and more use cases within the problem domain and develop a deep understanding of the intricacies of building these systems. This deep understanding can guide the creation of "beautiful" technology to replace your existing systems, alleviate your suffering, and enable new systems/features that were too hard to build before.

The key to developing the "beautiful" solution is figuring out the simplest set of abstractions that solve the concrete use cases you already have. It's a mistake to try to anticipate use cases you don't actually have or else you'll end up overengineering your solution. As a rule of thumb, the bigger the investment you're trying to make, the deeper you need to understand the problem domain and the more diverse your use cases need to be. Otherwise you risk the second-system effect.

"Making it beautiful" is where you use your design and abstraction skills to distill the problem space into simple abstractions that can be composed together. I view the development of beautiful abstractions as similar to statistical regression: you have a set of points on a graph (your use cases) and you're looking for the simplest curve that fits those points (a set of abstractions).

The more use cases you have, the better you'll be able to find the right curve to fit those points. If you don't have enough points, you're likely to either overfit or underfit the graph, leading to wasted work and overengineering.

A big part of making it beautiful is understanding the performance and resource characteristics of the problem space. This is one of the intricacies you learn in the "making it possible" phase, and you should take advantage of that learning when designing your beautiful solution.

With Storm, I distilled the realtime computation problem domain into a small set of abstractions: streams, spouts, bolts, and topologies. I devised a new algorithm for guaranteeing data processing that eliminated the need for intermediate message brokers, the part of our system that caused the most complexity and suffering. That both stream processing and reach, two very different problems on the surface, mapped so elegantly to Storm was a strong indicator that I was onto something big.

I took additional steps to acquire more use cases for Storm and validate my designs. I canvassed other engineers to learn about the particulars of the realtime problems they were dealing with. I didn't just ask people I knew. I also tweeted out that I was working on a new realtime system and wanted to learn about other people's use cases. This led to a lot of interesting discussions that educated me more on the problem domain and validated my design ideas.

Then make it fast

Once you've built out your beautiful design, you can safely invest time in profiling and optimization. Doing optimization too early will just waste time, because you still might rethink the design. This is called premature optimization.

"Making it fast" isn't about the high level performance characteristics of a system. The understanding of those issues should have been acquired in the "make it possible" phase and designed for in the "make it beautiful" phase. "Making it fast" is about micro-optimizations and tightening up the code to be more resource efficient. So you might worry about things like asymptotic complexity in the "make it beautiful" phase and focus on the constant-time factors in the "make it fast" phase.

Rinse and repeat

Suffering-oriented programming is a continuous process. The beautiful systems you build give you new capabilities, which allow you to "make it possible" in new and deeper areas of the problem space. This feeds learning back to the technology. You often have to tweak or add to the abstractions you've already come up with to handle more and more use cases.

Storm has gone through many iterations like this. When we first started using Storm, we discovered that we needed the capability to emit multiple, independent streams from a single component. We discovered that the addition of a special kind of stream called the "direct stream" would allow Storm to process batches of tuples as a concrete unit. Recently I developed "transactional topologies" which go beyond Storm's at-least-once processing guarantee and allow exactly-once messaging semantics to be achieved for nearly arbitrary realtime computation.

By its nature, hacking things out in a problem domain you don't understand so well and constantly iterating can lead to some sloppy code. The most important characteristic of a suffering-oriented programmer is a relentless focus on refactoring. This is critical to prevent accidental complexity from sabotaging the codebase.

Conclusion

Use cases are everything in suffering-oriented programming. They're worth their weight in gold. The only way to acquire use cases is through gaining experience through hacking.

There's a certain evolution most programmers go through. You start off struggling to get things to work and have absolutely no structure to your code. Code is sloppy and copy/pasting is prevalent. Eventually you learn about the benefits of structured programming and sharing logic as much as possible. Then you learn about making generic abstractions and using encapsulation to make it easier to reason about systems. Then you become obsessed with making all your code generic, with making things extensible to future-proof your programs.

Suffering-oriented programming rejects that you can effectively anticipate needs you don't currently have. It recognizes that attempts to make things generic without a deep understanding of the problem domain will lead to complexity and waste. Designs must always be driven by real, tangible use cases.

转载自:http://nathanmarz.com/blog/suffering-oriented-programming.html


内容概要:《中文大模型基准测评2025年上半年报告》由SuperCLUE团队发布,详细评估了2025年上半年中文大模型的发展状况。报告涵盖了大模型的关键进展、国内外大模型全景图及差距、专项测评基准介绍等。通过SuperCLUE基准,对45个国内外代表性大模型进行了六大任务(数学推理、科学推理、代码生成、智能体Agent、精确指令遵循、幻觉控制)的综合测评。结果显示,海外模型如o3、o4-mini(high)在推理任务上表现突出,而国内模型如Doubao-Seed-1.6-thinking-250715在智能体Agent和幻觉控制任务上表现出色。此外,报告还分析了模型性价比、效能区间分布,并对代表性模型如Doubao-Seed-1.6-thinking-250715、DeepSeek-R1-0528、GLM-4.5等进行了详细介绍。整体来看,国内大模型在特定任务上已接近国际顶尖水平,但在综合推理能力上仍有提升空间。 适用人群:对大模型技术感兴趣的科研人员、工程师、产品经理及投资者。 使用场景及目标:①了解2025年上半年中文大模型的发展现状与趋势;②评估国内外大模型在不同任务上的表现差异;③为技术选型和性能优化提供参考依据。 其他说明:报告提供了详细的测评方法、评分标准及结果分析,确保评估的科学性和公正性。此外,SuperCLUE团队还发布了多个专项测评基准,涵盖多模态、文本、推理等多个领域,为业界提供全面的测评服务。
资源下载链接为: https://pan.quark.cn/s/f989b9092fc5 单点定位是卫星导航技术的核心方法,通过接收卫星信号来确定接收器在地球上的位置。它主要涉及分析卫星发射的时间戳、伪距以及卫星轨道信息。MATLAB凭借其强大的数值计算和数据处理能力,可以用来编写程序实现单点定位。RINEX(Receiver Independent Exchange Format)观测文件是一种通用格式,用于存储各种接收机产生的观测数据,如伪距、载波相位和多普勒频移等,便于不同软件进行数据交换和处理。 在MATLAB中实现单点定位的程序通常包括以下步骤:首先,读取RINEX观测文件,解析卫星信号数据,包括处理文件头信息、识别有效观测时段以及提取卫星ID、伪距和时间戳等关键信息。其次,利用星历数据计算卫星在特定时间的位置。星历数据由卫星导航系统地面站提供,包含卫星的精确轨道参数。接下来,对原始伪距进行改正,考虑大气延迟、卫星钟偏和接收机钟偏等因素,这需要对大气折射率进行建模以及估计卫星和接收机的时钟误差。然后,基于改正后的伪距,利用三角定位原理计算接收机的位置,通常采用最小二乘法或其他优化算法来获得最佳解。最后,将计算出的接收机位置与已知点坐标进行比较,评估定位精度,并以经纬度、海拔高度等形式输出结果。 在MATLAB程序single_point_position.m中,可以看到上述步骤的具体实现。代码可能包含RINEX文件解析函数、卫星轨道计算模块、伪距改正函数以及定位计算和输出部分。通过学习和理解该源码,不仅可以深入掌握单点定位原理,还能提升MATLAB编程和处理导航数据的能力。单点定位在实际应用中常用于初步定位或作为更复杂定位方法的基础,如差分定位和动态定位。它在科学研究、导航设备测试和大地测量等领域具有重要价值。通过不断优化这些程序,可以提高定位精度,满足实际需求。
资源下载链接为: https://pan.quark.cn/s/67c535f75d4c Verilog-A是一种高级硬件描述语言,广泛应用于模拟和混合信号电路设计。它具备强大的数学运算能力,能够精确地描述电路的行为和特性。在“用Verilog-A编写的电路模块示例”压缩包中,包含了多种重要的电子电路元件模型,例如PLL(锁相环)、resistor(电阻)、bjt(双极型晶体管)、opamp(运算放大器)、psfet(P沟道金属氧化物半导体场效应晶体管)、deadband(死区)以及sinewave(正弦波)生成器。以下是对这些模块的详细说明。 PLL(锁相环):PLL是数字通信系统中的关键部件,主要用于使接收端的时钟频率与发送端的信号频率同步。通过Verilog-A,可以精确描述PLL的各个组成部分,如压控振荡器(VCO)、分频器、鉴相器和低通滤波器。设计者能够利用Verilog-A精确控制PLL的动态特性,例如环路带宽和锁定时间等。 Resistor(电阻):在Verilog-A中,电阻模型定义了电流与电压之间的关系,遵循欧姆定律。设计者可以指定电阻的温度系数和其他非线性特性,从而更真实地模拟实际电路中的电阻行为。 BJT(双极型晶体管):BJT是模拟电路中的基础元件,具有电流控制电流的特性。在Verilog-A中,BJT模型需要描述基极、发射极和集电极之间的电流关系,以及BJT的放大系数和非线性特性。 Opamp(运算放大器):运算放大器是模拟电路设计的核心元件,常用于信号放大或构建反馈电路。在Verilog-A中,opamp模型包括输入失调电压、增益、共模抑制比等关键参数,以及理想化特性,如无限输入阻抗和零输出阻抗。 Psfet(P沟道金属氧化物半导体场效应晶体管):P沟道MOSFET是数字和模拟电路中的常见开关元件。Verilog-A模型需要描述其阈值电压、亚阈值
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值