Suffering-oriented programming

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

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


标题基于SpringBoot的学生读书笔记共享平台设计研究AI更换标题第1章引言介绍学生读书笔记共享平台的研究背景、意义、国内外研究现状、论文方法以及创新点。1.1研究背景与意义阐述学生读书笔记共享平台在当前教育环境下的重要性。1.2国内外研究现状分析国内外学生读书笔记共享平台的研究进展与现状。1.3研究方法及创新点概述本文的研究方法与平台设计的创新点。第2章相关理论总结和评述与SpringBoot及读书笔记共享平台相关的理论。2.1SpringBoot框架介绍阐述SpringBoot框架的特点、优势及其在Web开发中的应用。2.2读书笔记共享平台相关理论介绍读书笔记共享平台的设计原则、功能需求及用户体验理论。2.3数据库设计与优化理论简述数据库设计的基本原则及优化策略。第3章平台设计详细介绍基于SpringBoot的学生读书笔记共享平台的设计方案。3.1平台架构设计平台的整体架构,包括前端、后端及数据库的设计。3.2功能模块设计阐述平台的主要功能模块,如用户管理、笔记上传、笔记分享等。3.3数据库设计介绍数据库的设计方案,包括表结构、索引及关系设计。第4章平台实现详细描述平台的具体实现过程,包括技术选型、开发环境搭建等。4.1技术选型与开发环境介绍开发平台所采用的技术栈及开发环境配置。4.2关键代码实现展示平台实现过程中的关键代码片段,如用户登录、笔记上传等功能的实现。4.3平台测试与优化平台的测试过程及优化策略,确保平台的稳定性和性能。第5章平台应用与分析对平台的应用效果进行分析,包括用户反馈、使用数据等。5.1用户反馈收集与分析收集用户反馈,分析用户对平台的满意度及改进建议。5.2使用数据分析通过数据分析工具,分析平台的使用情况,如用户活跃度、笔记分享量等。5.3对比方法分析对比其他类似平台,分析本平台的优势与不足。第6章结论与展望总结本文的研究成果,并对未来研究方向
内容概要:本文针对多渗透率电动汽车接入对配电网的影响,开展承载能力评估研究,提出了一套融合多类型分布式资源的综合评估体系。研究构建了包含电动汽车、分布式光伏及静止无功补偿器(SVC)的配电网协同运行基础模型,建立了涵盖一次设备安全性、负荷平稳性、电能质量与系统运行效率的多维度评价指标体系,并采用熵权法与模糊综合评价相结合的双层模型实现指标客观赋权与系统承载能力的量化评分。通过Matlab仿真平台,系统分析了不同电动汽车渗透率下各项指标的演变规律与敏感性特征,揭示了高比例电动汽车接入对配电网的潜在压力,从而为电网的规划决策、扩容改造以及电动汽车的有序充电管理提供了科学、量化的技术支撑。; 适合人群:具备电力系统、电气工程或相关领域基础知识,从事新能源并网、智能配电网、电动汽车与电网互动(V2G)等方向研究的研究生、科研人员及电力系统工程技术人员。; 使用场景及目标:①评估大规模电动汽车无序或有序接入对配电网安全稳定运行的综合影响;②为配电网络的升级改造、设备选型及电动汽车充电基础设施布局提供决策依据;③学习并复现基于熵权-模糊综合评价法的多指标体系构建与量化评估方法,掌握其在复杂电力系统分析中的应用。; 阅读建议:建议结合文中提供的Matlab代码进行仿真复现,重点理解算例参数设置、多维指标体系的设计逻辑以及双层评价模型的具体实现步骤,通过调整渗透率等关键参数进行对比实验,以深化对评估方法原理与实际应用效果的理解。
内容概要:本文围绕电力系统状态估计问题,深入研究了加权最小二乘法(WLSM)与因子分解法(FDM)在状态估计中的应用,并提供了完整的Matlab代码实现。文章系统阐述了电力系统状态估计的基本原理、数学建模过程以及两种算法的核心流程,通过仿真实验全面对比了WLSM与FDM在估计精度、计算效率、收敛性等方面的表现。研究发现,FDM在处理大规模稀疏矩阵时展现出更高的计算效率,更适合实时性要求较高的场景;而WLSM在估计精度上更具优势,适用于对准确性要求严格的场合。两者各有侧重,可根据实际系统需求灵活选用。配套的Matlab代码有助于读者深入理解算法细节并进行实践复现。; 适合人群:具备电力系统分析基础知识和Matlab编程能力的高校研究生、科研人员,以及从事电力系统运行、调度与控制等相关领域的工程技术人员。; 使用场景及目标:①系统学习电力系统状态估计的理论基础与主流算法实现;②对比分析WLSM与FDM在不同电网规模下的性能差异;③借助Matlab代码进行算法仿真与优化,提升科研能力与工程实践水平。; 阅读建议:建议读者结合经典电力系统状态估计教材,按照文中所述理论推导与代码结构逐步实现算法,并在标准测试系统(如IEEE 14、30节点系统)上进行验证,以深入掌握算法特性及其适用边界。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值