You are previewing The Practice of Programming.
O'Reilly logo
The Practice of Programming

Book Description

With the same insight and authority that made their book The Unix Programming Environment a classic, Brian Kernighan and Rob Pike have written The Practice of Programming to help make individual programmers more effective and productive.

The practice of programming is more than just writing code. Programmers must also assess tradeoffs, choose among design alternatives, debug and test, improve performance, and maintain software written by themselves and others. At the same time, they must be concerned with issues like compatibility, robustness, and reliability, while meeting specifications.

The Practice of Programming covers all these topics, and more. This book is full of practical advice and real-world examples in C, C++, Java, and a variety of special-purpose languages. It includes chapters on:

  • debugging: finding bugs quickly and methodically

  • testing: guaranteeing that software works correctly and reliably

  • performance: making programs faster and more compact

  • portability: ensuring that programs run everywhere without change

  • design: balancing goals and constraints to decide which algorithms and data structures are best

  • interfaces: using abstraction and information hiding to control the interactions between components

  • style: writing code that works well and is a pleasure to read

  • notation: choosing languages and tools that let the machine do more of the work

Kernighan and Pike have distilled years of experience writing programs, teaching, and working with other programmers to create this book. Anyone who writes software will profit from the principles and guidance in The Practice of Programming.

Table of Contents

  1. About This eBook
  2. Title Page
  3. Copyright Page
  4. Contents
  5. Preface
  6. Chapter 1: Style
    1. 1.1. Names
    2. 1.2. Expressions and Statements
    3. 1.3. Consistency and Idioms
    4. 1.4. Function Macros
    5. 1.5. Magic Numbers
    6. 1.6. Comments
    7. 1.7. Why Bother?
    8. Supplementary Reading
  7. Chapter 2: Algorithms and Data Structures
    1. 2.1. Searching
    2. 2.2. Sorting
    3. 2.3. Libraries
    4. 2.4. A Java Quicksort
    5. 2.5. O-Notation
    6. 2.6. Growing Arrays
    7. 2.7. Lists
    8. 2.8. Trees
    9. 2.9. Hash Tables
    10. 2.10. Summary
    11. Supplementary Reading
  8. Chapter 3: Design and Implementation
    1. 3.1. The Markov Chain Algorithm
    2. 3.2. Data Structure Alternatives
    3. 3.3. Building the Data Structure in C
    4. 3.4. Generating Output
    5. 3.5. Java
    6. 3.6. C++
    7. 3.7. Awk and Perl
    8. 3.8. Performance
    9. 3.9. Lessons
    10. Supplementary Reading
  9. Chapter 4: Interfaces
    1. 4.1. Comma-Separated Values
    2. 4.2. A Prototype Library
    3. 4.3. A Library for Others
    4. 4.4. A C++ Implementation
    5. 4.5. Interface Principles
    6. 4.6. Resource Management
    7. 4.7. Abort, Retry, Fail?
    8. 4.8. User Interfaces
    9. Supplementary Reading
  10. Chapter 5: Debugging
    1. 5.1. Debuggers
    2. 5.2. Good Clues, Easy Bugs
    3. 5.3. No Clues, Hard Bugs
    4. 5.4. Last Resorts
    5. 5.5. Non-reproducible Bugs
    6. 5.6. Debugging Tools
    7. 5.7. Other People’s Bugs
    8. 5.8. Summary
    9. Supplementary Reading
  11. Chapter 6: Testing
    1. 6.1. Test as You Write the Code
    2. 6.2. Systematic Testing
    3. 6.3. Test Automation
    4. 6.4. Test Scaffolds
    5. 6.5. Stress Tests
    6. 6.6. Tips for Testing
    7. 6.7. Who Does the Testing?
    8. 6.8. Testing the Markov Program
    9. 6.9. Summary
    10. Supplementary Reading
  12. Chapter 7: Performance
    1. 7.1. A Bottleneck
    2. 7.2. Timing and Profiling
    3. 7.3. Strategies for Speed
    4. 7.4. Tuning the Code
    5. 7.5. Space Efficiency
    6. 7.6. Estimation
    7. 7.7. Summary
    8. Supplementary Reading
  13. Chapter 8: Portability
    1. 8.1. Language
    2. 8.2. Headers and Libraries
    3. 8.3. Program Organization
    4. 8.4. Isolation
    5. 8.5. Data Exchange
    6. 8.6. Byte Order
    7. 8.7. Portability and Upgrade
    8. 8.8. Internationalization
    9. 8.9. Summary
    10. Supplementary Reading
  14. Chapter 9: Notation
    1. 9.1. Formatting Data
    2. 9.2. Regular Expressions
    3. 9.3. Programmable Tools
    4. 9.4. Interpreters, Compilers, and Virtual Machines
    5. 9.5. Programs that Write Programs
    6. 9.6. Using Macros to Generate Code
    7. 9.7. Compiling on the Fly
    8. Supplementary Reading
  15. Epilogue
  16. Appendix: Collected Rules
    1. Style
    2. Interfaces
    3. Debugging
    4. Testing
    5. Performance
    6. Portability
  17. Index