Synopses & Reviews
As programmers, weve all seen source code thats so ugly and buggy it makes our brain ache. Over the past five years, authors Dustin Boswell and Trevor Foucher have analyzed hundreds of examples of "bad code" (much of it their own) to determine why theyre bad and how they could be improved. Their conclusion? You need to write code that minimizes the time it would take someone else to understand it—even if that someone else is you.
This book focuses on basic principles and practical techniques you can apply every time you write code. Using easy-to-digest code examples from different languages, each chapter dives into a different aspect of coding, and demonstrates how you can make your code easy to understand.
- Simplify naming, commenting, and formatting with tips that apply to every line of code
- Refine your programs loops, logic, and variables to reduce complexity and confusion
- Attack problems at the function level, such as reorganizing blocks of code to do one task at a time
- Write effective test code that is thorough and concise—as well as readable
"Being aware of how the code you create affects those who look at it later is an important part of developing software. The authors did a great job in taking you through the different aspects of this challenge, explaining the details with instructive examples."
—Michael Hunger, passionate Software Developer
Synopsis
As programmers, we've all seen source code that's so ugly and buggy it makes our brain ache. And let's be honest, we've all written code like that. With this book, you'll learn to write code that's easy to read and understand. You'll have more fun and your coworkers will love you.
The Art of Readable Code focuses on the nuts and bolts of programming, with simple and practical techniques you can use every time you sit down to write code. You'll find tips throughout the book, with easy-to-digest code examples, helpful illustrations, and cartoons for fun.
- Learn to pick variable names that are "dense with information"
- Organize your loops and conditionals so they're easy to understand
- Make your comments short and sweet
- Recognize when your code is doing too many things at once
- Write tests that are concise, but thorough
- Master the art of breaking hard problems into many smaller ones
Synopsis
In this unique work, leading computer scientists discuss how they found unusual, carefully designed solutions to difficult problems. This book lets the reader look over the shoulder of major coding and design experts to see problems through their eyes.
Synopsis
How do the experts solve difficult problems in software development? In this unique and insightful book, leading computer scientists offer case studies
About the Author
Andy Oram is an editor at O'Reilly Media, a highly respected book publisher and technology information provider. An employee of the company since 1992, Andy currently specializes in free software and open source technologies. His work for O'Reilly includes the first books ever published commercially in the United States on Linux, and the 2001 title Peer-to-Peer. His modest programming and system administration skills are mostly self-taught.
Greg Wilson holds a Ph.D. in Computer Science from the University of Edinburgh, and has worked on high-performance scientific computing, data visualization, and computer security. He is the author of Data Crunching and Practical Parallel Programming (MIT Press, 1995), and is a contributing editor at Doctor Dobb's Journal, and an adjunct professor in Computer Science at the University of Toronto.
Table of Contents
Dedication; Foreword; Preface; How This Book Is Organized; Conventions Used in This Book; Using Code Examples; How to Contact Us; Safari® Enabled; Chapter 1: A Regular Expression Matcher; 1.1 The Practice of Programming; 1.2 Implementation; 1.3 Discussion; 1.4 Alternatives; 1.5 Building on It; 1.6 Conclusion; Chapter 2: Subversion's Delta Editor: Interface As Ontology; 2.1 Version Control and Tree Transformation; 2.2 Expressing Tree Differences; 2.3 The Delta Editor Interface; 2.4 But Is It Art?; 2.5 Abstraction As a Spectator Sport; 2.6 Conclusions; Chapter 3: The Most Beautiful Code I Never Wrote; 3.1 The Most Beautiful Code I Ever Wrote; 3.2 More and More with Less and Less; 3.3 Perspective; 3.4 What Is Writing?; 3.5 Conclusion; 3.6 Acknowledgments; Chapter 4: Finding Things; 4.1 On Time; 4.2 Problem: Weblog Data; 4.3 Problem: Who Fetched What, When?; 4.4 Search in the Large; 4.5 Conclusion; Chapter 5: Correct, Beautiful, Fast (in That Order): Lessons from Designing XML Verifiers; 5.1 The Role of XML Validation; 5.2 The Problem; 5.3 Version 1: The Naïve Implementation; 5.4 Version 2: Imitating the BNF Grammar O(N); 5.5 Version 3: First Optimization O(log N); 5.6 Version 4: Second Optimization: Don't Check Twice; 5.7 Version 5: Third Optimization O(1); 5.8 Version 6: Fourth Optimization: Caching; 5.9 The Moral of the Story; Chapter 6: Framework for Integrated Test: Beauty Through Fragility; 6.1 An Acceptance Testing Framework in Three Classes; 6.2 The Challenge of Framework Design; 6.3 An Open Framework; 6.4 How Simple Can an HTML Parser Be?; 6.5 Conclusion; Chapter 7: Beautiful Tests; 7.1 That Pesky Binary Search; 7.2 Introducing JUnit; 7.3 Nailing Binary Search; 7.4 Conclusion; Chapter 8: On-the-Fly Code Generation for Image Processing; Chapter 9: Top Down Operator Precedence; 9.1 JavaScript; 9.2 Symbol Table; 9.3 Tokens; 9.4 Precedence; 9.5 Expressions; 9.6 Infix Operators; 9.7 Prefix Operators; 9.8 Assignment Operators; 9.9 Constants; 9.10 Scope; 9.11 Statements; 9.12 Functions; 9.13 Array and Object Literals; 9.14 Things to Do and Think About; Chapter 10: The Quest for an Accelerated Population Count; 10.1 Basic Methods; 10.2 Divide and Conquer; 10.3 Other Methods; 10.4 Sum and Difference of Population Counts of Two Words; 10.5 Comparing the Population Counts of Two Words; 10.6 Counting the 1-Bits in an Array; 10.7 Applications; Chapter 11: Secure Communication: The Technology Of Freedom; 11.1 The Heart of the Start; 11.2 Untangling the Complexity of Secure Messaging; 11.3 Usability Is the Key; 11.4 The Foundation; 11.5 The Test Suite; 11.6 The Functioning Prototype; 11.7 Clean Up, Plug In, Rock On
; 11.8 Hacking in the Himalayas; 11.9 The Invisible Hand Moves; 11.10 Speed Does Matter; 11.11 Communications Privacy for Individual Rights; 11.12 Hacking the Civilization; Chapter 12: Growing Beautiful Code in BioPerl; 12.1 BioPerl and the Bio::Graphics Module; 12.2 The Bio::Graphics Design Process; 12.3 Extending Bio::Graphics; 12.4 Conclusions and Lessons Learned; Chapter 13: The Design of the Gene Sorte; 13.1 The User Interface of the Gene Sorter; 13.2 Maintaining a Dialog with the User over the Web; 13.3 A Little Polymorphism Can Go a Long Way; 13.4 Filtering Down to Just the Relevant Genes; 13.5 Theory of Beautiful Code in the Large; 13.6 Conclusion; Chapter 14: How Elegant Code Evolves with Hardware The Case of Gaussian Elimination; 14.1 The Effects of Computer Architectures on Matrix Algorithms; 14.2 A Decompositional Approach; 14.3 A Simple Version; 14.4 LINPACK's DGEFA Subroutine; 14.5 LAPACK DGETRF; 14.6 Recursive LU; 14.7 ScaLAPACK PDGETRF; 14.8 Multithreading for Multi-Core Systems; 14.9 A Word About the Error Analysis and Operation Count; 14.10 Future Directions for Research; 14.11 Further Reading; Chapter 15: The Long-Term Benefits of Beautiful Design; 15.1 My Idea of Beautiful Code; 15.2 Introducing the CERN Library; 15.3 Outer Beauty; 15.4 Inner Beauty; 15.5 Conclusion; Chapter 16: The Linux Kernel Driver Model: The Benefits of Working Together; 16.1 Humble Beginnings; 16.2 Reduced to Even Smaller Bits; 16.3 Scaling Up to Thousands of Devices; 16.4 Small Objects Loosely Joined; Chapter 17: Another Level of Indirection; 17.1 From Code to Pointers; 17.2 From Function Arguments to Argument Pointers; 17.3 From Filesystems to Filesystem Layers; 17.4 From Code to a Domain-Specific Language; 17.5 Multiplexing and Demultiplexing; 17.6 Layers Forever?; Chapter 18: Python's Dictionary Implementation: Being All Things to All People; 18.1 Inside the Dictionary; 18.2 Special Accommodations; 18.3 Collisions; 18.4 Resizing; 18.5 Iterations and Dynamic Changes; 18.6 Conclusion; 18.7 Acknowledgments; Chapter 19: Multidimensional Iterators in NumPy; 19.1 Key Challennnnnnges in N-Dimensional Array Operations; 19.2 Memory Models for an N-Dimensional Array; 19.3 NumPy Iterator Origins; 19.4 Iterator Design; 19.5 Iterator Interface; 19.6 Iterator Use; 19.7 Conclusion; Chapter 20: A Highly Reliable Enterprise System for NASA's Mars Rover Mission; 20.1 The Mission and the Collaborative Information Portal; 20.2 Mission Needs; 20.3 System Architecture; 20.4 Case Study: The Streamer Service; 20.5 Reliability; 20.6 Robustness; 20.7 Conclusion; Chapter 21: ERP5: Designing for Maximum Adaptability; 21.1 General Goals of ERP; 21.2 ERP5; 21.3 The Underlying Zope Platform; 21.4 ERP5 Project Concepts; 21.5 Coding the ERP5 Project; 21.6 Conclusion; Chapter 22: A Spoonful of Sewage; Chapter 23: Distributed Programming with MapReduce; 23.1 A Motivating Example; 23.2 The MapReduce Programming Model; 23.3 Other MapReduce Examples; 23.4 A Distributed MapReduce Implementation; 23.5 Extensions to the Model; 23.6 Conclusion; 23.7 Further Reading; 23.8 Acknowledgments; 23.9 Appendix: Word Count Solution; Chapter 24: Beautiful Concurrency; 24.1 A Simple Example: Bank Accounts; 24.2 Software Transactional Memory; 24.3 The Santa Claus Problem; 24.4 Reflections on Haskell; 24.5 Conclusion; 24.6 Acknowledgments; Chapter 25: Syntactic Abstraction: The syntax-case Expander; 25.1 Brief Introduction to syntax-case; 25.2 Expansion Algorithm; 25.3 Example; 25.4 Conclusion; Chapter 26: Labor-Saving Architecture: An Object-Oriented Framework for Networked Software; 26.1 Sample Application: Logging Service; 26.2 Object-Oriented Design of the Logging Server Framework; 26.3 Implementing Sequential Logging Servers; 26.4 Implementing Concurrent Logging Servers; 26.5 Conclusion; Chapter 27: Integrating Business Partners the RESTful Way; 27.1 Project Background; 27.2 Exposing Services to External Clients; 27.3 Routing the Service Using the Factory Pattern; 27.4 Exchanging Data Using E-Business Protocols; 27.5 Conclusion; Chapter 28: Beautiful Debugging; 28.1 Debugging a Debugger; 28.2 A Systematic Process; 28.3 A Search Problem; 28.4 Finding the Failure Cause Automatically; 28.5 Delta Debugging; 28.6 Minimizing Input; 28.7 Hunting the Defect; 28.8 A Prototype Problem; 28.9 Conclusion; 28.10 Acknowledgments; 28.11 Further Reading; Chapter 29: Treating Code As an Essay; Chapter 30: When a Button Is All That Connects You to the World; 30.1 Basic Design Model; 30.2 Input Interface; 30.3 Efficiency of the User Interface; 30.4 Download; 30.5 Future Directions; Chapter 31: Emacspeak: The Complete Audio Desktop; 31.1 Producing Spoken Output; 31.2 Speech-Enabling Emacs; 31.3 Painless Access to Online Information; 31.4 Summary; 31.5 Acknowledgments; Chapter 32: Code in Motion; 32.1 On Being "Bookish"; 32.2 Alike Looking Alike; 32.3 The Perils of Indentation; 32.4 Navigating Code; 32.5 The Tools We Use; 32.6 DiffMerge's Checkered Past; 32.7 Conclusion; 32.8 Acknowledgments; 32.9 Further Reading; Chapter 33: Writing Programs for "The Book"; 33.1 The Nonroyal Road; 33.2 Warning to Parenthophobes; 33.3 Three in a Row; 33.4 The Slippery Slope; 33.5 The Triangle Inequality; 33.6 Meandering On; 33.7 "Duh!"I Mean "Aha!"; 33.8 Conclusion; 33.9 Further Reading; Afterword; Contributors; Colophon;