Code That Fits in Your Head offers indispensable, practical advice for writing code at a sustainable pace and controlling the complexity that causes projects to spin out of control.

Reflecting decades of experience helping software teams succeed, Mark Seemann guides you from zero (no code) to deployed features and shows how to maintain a good cruising speed as you add functionality, address cross-cutting concerns, troubleshoot, and optimize. You'll find valuable ideas, practices, and processes for key issues ranging from checklists to teamwork, encapsulation to decomposition, API design to unit testing.

Seemann illuminates his insights with code examples drawn from a complete sample project. Written in C#, they're designed to be clear and useful to anyone who uses any object-oriented language including Java , C++, and Python. To facilitate deeper exploration, all code and extensive commit messages are available for download.

If you've ever suffered through bad projects or had to cope with unmaintainable legacy code, this guide will help you make things better next time and every time.

Seemann M. Code that fits in your head: heuristics for software engineering / M. Seemann, 1-е изд., Boston: Addison-Wesley, 2021.

Программирование - наука или искусство?

Сопротивление абстракциям в коде говорит, что неверные абстракции могут затруднить выведение верных. Похожая ситуация возникает и с метафорами, неверные / неточные метафоры могут привести к неверным заключениям и неверному отношению.


Поскольку каждая строчка кода пишется один раз, а читается гораздо больше одного раза, то инвестиции в понятность кода окупаются прямо пропорционально этой разнице. К тому же в момент написания строчки кода программист обладает полным контекстом, а в моменты чтения - нет.

Поскольку в момент чтения кода высока вероятность работы Системы 1 по Канеману, то для правильного понимания нужно, чтобы весь релевантный контекст был активирован, т.е. находился перед глазами и помещался в человеческой оперативной памяти. Из этого явно следует ограничение на количество строк кода в одной функции, количество переменных и зависимостей, а также запрет на использование глобальных переменных и смешение уровней абстракции, особенно при наличии побочных эффектов.


Chapter 4 Vertical Slice 4.1 Start with Working Software 4.2 Walking Skeleton 4.3 Outside-in 4.4 Complete the Slice Chapter 5 Encapsulation 5.1 Save the Data 5.2 Validation 5.3 Protection of Invariants Chapter 6 Triangulation 6.1 Short-Term versus Long-Term Memory 6.2 Capacity Chapter 7 Decomposition 7.1 Code Rot 7.2 Code That Fits in Your Brain Chapter 8 API Design 8.1 Principles of API Design 8.2 API Design Example Chapter 9 Teamwork 9.1 Git 9.2 Collective Code Ownership

PART II Sustainability 201 Chapter 10 Augmenting Code 10.1 Feature Flags 10.2 The Strangler Pattern 10.3 Versioning Chapter 11 Editing Unit Tests 11.1 Refactoring Unit Tests 11.2 See Tests Fail Chapter 12 Troubleshooting 12.1 Understanding 12.2 Defects 12.3 Bisection Chapter 13 Separation of Concerns 13.1 Composition 13.2 Cross-Cutting Concerns Chapter 14 Rhythm 14.1 Personal Rhythm 14.2 Team Rhythm Chapter 15 The Usual Suspects 15.1 Performance 15.2 Security 15.3 Other Techniques Chapter 16 Tour 16.1 Navigation 16.2 Architecture 16.3 Usage