Code Reading: The Open Source Perspective

If you are a programmer, you need this book.

  • You've got a day to add a new feature in a 34,000-line program: Where do you start? Page 333
  • How can you understand and simplify an inscrutable piece of code? Page 39
  • Where do you start when disentangling a complicated build process? Page 167
  • How do you comprehend code that appears to be doing five things in parallel? Page 132

You may read code because you have to--to fix it, inspect it, or improve it. You may read code the way an engineer examines a machine--to discover what makes it tick. Or you may read code because you are scavenging--looking for material to reuse.

Code-reading requires its own set of skills, and the ability to determine which technique you use when is crucial. In this indispensable book, Diomidis Spinellis uses more than 600 real-world examples to show you how to identify good (and bad) code: how to read it, what to look for, and how to use this knowledge to improve your own code.

Fact: If you make a habit of reading good code, you will write better code yourself.

1137590401
Code Reading: The Open Source Perspective

If you are a programmer, you need this book.

  • You've got a day to add a new feature in a 34,000-line program: Where do you start? Page 333
  • How can you understand and simplify an inscrutable piece of code? Page 39
  • Where do you start when disentangling a complicated build process? Page 167
  • How do you comprehend code that appears to be doing five things in parallel? Page 132

You may read code because you have to--to fix it, inspect it, or improve it. You may read code the way an engineer examines a machine--to discover what makes it tick. Or you may read code because you are scavenging--looking for material to reuse.

Code-reading requires its own set of skills, and the ability to determine which technique you use when is crucial. In this indispensable book, Diomidis Spinellis uses more than 600 real-world examples to show you how to identify good (and bad) code: how to read it, what to look for, and how to use this knowledge to improve your own code.

Fact: If you make a habit of reading good code, you will write better code yourself.

66.99 In Stock
Code Reading: The Open Source Perspective

Code Reading: The Open Source Perspective

by Diomidis Spinellis
Code Reading: The Open Source Perspective

Code Reading: The Open Source Perspective

by Diomidis Spinellis

eBook

$66.99 

Available on Compatible NOOK devices, the free NOOK App and in My Digital Library.
WANT A NOOK?  Explore Now

Related collections and offers


Overview

If you are a programmer, you need this book.

  • You've got a day to add a new feature in a 34,000-line program: Where do you start? Page 333
  • How can you understand and simplify an inscrutable piece of code? Page 39
  • Where do you start when disentangling a complicated build process? Page 167
  • How do you comprehend code that appears to be doing five things in parallel? Page 132

You may read code because you have to--to fix it, inspect it, or improve it. You may read code the way an engineer examines a machine--to discover what makes it tick. Or you may read code because you are scavenging--looking for material to reuse.

Code-reading requires its own set of skills, and the ability to determine which technique you use when is crucial. In this indispensable book, Diomidis Spinellis uses more than 600 real-world examples to show you how to identify good (and bad) code: how to read it, what to look for, and how to use this knowledge to improve your own code.

Fact: If you make a habit of reading good code, you will write better code yourself.


Product Details

ISBN-13: 9780672333705
Publisher: Pearson Education
Publication date: 05/27/2003
Series: Effective Software Development Series
Sold by: Barnes & Noble
Format: eBook
Pages: 528
File size: 10 MB
Age Range: 18 Years

About the Author

Diomidis Spinellis has been developing the concepts presented in this book since 1985, while also writing groundbreaking software applications and working on multimillion-line code bases. Spinellis holds an M.Eng. degree in software engineering and a Ph.D. in computer science from Imperial College London. Currently he is an associate professor in the Department of Management Science and Technology at the Athens University of Economics and Business.

Table of Contents



Foreword.


Preface.


1. Introduction.

Why and How to Read Code.

Code as Literature.

Code as Exemplar.

Maintenance.

Evolution.

Reuse.

Inspections.

How to Read this Book.

Typographical Conventions.

Diagrams.

Exercises.

Supplementary Material.

Tools.

Outline.

The Great Language Debate.



2. Basic Programming Elements.

A Complete Program.

Functions and Global Variables.

While, Conditions, Blocks.

Switch.

For.

Break, Continue.

Character and Boolean Expressions.

Goto.

Refactoring in the Small.

Do, Integer Expressions.

Control Structures Revisited.



3. Advanced C Data Types.

Pointers.

Linked Data Structures.

Dynamic Allocation of Data Structures.

Call by Reference.

Data Element Access.

Arrays as Arguments and Results.

Function Pointers.

Pointer as an Alias.

Pointers and Strings.

Direct Memory Access.

Structures.

Grouping Together Data Elements.

Returning Multiple Data Elements from a Function.

Mapping the Organization of Data.

Programming in an Object-Oriented Fashion.

Unions.

Efficient Use of Storage.

Implementing Polymorphism.

Accessing Different Internal Representations.

Dynamic Memory Allocation.

Managing Free Memory.

Structures with Dynamically-Allocated Arrays.

Typedef Declarations.



4. C Data Structures.

Vector.

Matrix and Table.

Stack.

Queue.

Map.

Hash Tables.

Set.

Linked List.

Tree.

Graph.

Node Storage.

Edge Representation.

Edge Storage.

Graph Properties.

Hidden Structures.

Other Representations.



5. Advanced Control Flow.

Recursion.

Exceptions.

Parallelism.

Hardware and Software Parallelism.

Control Models.

Thread Implementations.

Signals.

Nonlocal Jumps.

Macro Substitution.



6. Tackling Large Projects.

Design and Implementation Techniques.

Project Organization.

The Build Process and Makefiles.

Configuration.

Revision Control.

Project-Specific Tools.

Testing.



7. Coding Standards and Conventions.

File Names and Organization.

Indentation.

Formatting.

Naming Conventions.

Programming Practices.

Process Standards.



8. Documentation.

Documentation Types.

Reading Documentation.

Documentation Problems.

Additional Documentation Sources.

Common Open-Source Documentation Formats.



9. Architecture.

System Structures.

Centralized Repository and Distributed Approaches.

Data-Flow.

Object-Oriented.

Layered.

Hierarchies.

Slicing.

Control Models.

Event-Driven Systems.

System Manager.

State Transition.

Element Packaging.

Module.

Namespace.

Object.

Generic Implementation.

Abstract Data Type.

Library.

Process and Filter.

Component.

Data Repository.

Architecture Reuse.

Frameworks.

Code Wizards.

Design Patterns.

Domain-Specific Architectures.



10. Code-Reading Tools.

Regular Expressions.

The Editor as a Code Browser.

Code Searching With Grep.

Locating File Differences.

Roll your Own Tool.

The Compiler as a Code-Reading Tool.

Code Browsers and Beautifiers.

Run-Time Tools.

Non-software Tools.



11. A Complete Example.

Overview.

Attack Plan.

Code Reuse.

Testing and Debugging.

Documentation.

Observations.



Appendix A. Outline of the Code Provided.


Appendix B. Source Code Credits.


Appendix C. Referenced Source Files.


Appendix D. Source Code Licenses.

BSD.

X.

ACE.

Apache.

DemoGL.

OpenCL.

ArgoUML.

Perl.



Appendix E. Maxims for Reading Code.


Bibliography.


Index.


Author Index. 0201799405T01162003

Preface

What do we ever get nowadays from reading to equal the excitement and the revelation in those first fourteen years? -- Graham Greene

The reading of code is likely to be one the most common activities of a computing professional, yet it is seldom taught as a subject, or formally used as a method for learning how to design and program. One reason for this sad situation may have been the lack of high-quality code to read. Companies often protect source code as a trade secret and rarely allow others to read, comment, experiment, and learn from it. In the few cases where important proprietary code was allowed out of a company's closet, it has spurred enormous interest and creative advancements. As an example, a generation of programmers benefited from John Lions' Commentary on the UNIX Operating System that listed and annotated the complete source code of the sixth edition UNIX kernel. Although Lions' book was originally written under a grant from AT&T for use in an operating system course and was not available to the general public, copies of it circulated for years as bootleg nth-generation photocopies.

In the last few years however, the popularity of open-source software has provided us with a large body of code that we can all freely read. Some of the most popular software systems used today, such as the Apache Web server, the Perl language, the gnu/Linux operating system, the BIND domain-name server, and the sendmail mail-transfer agent are in fact available in open-source form. I was thus fortunate to be able to use open-source software, such as the above to write this book as a primer and reader for software code. My goal was to provide background knowledgeand techniques for reading code written by others. By using real-life examples taken out of working, open-source projects I tried to cover most concepts related to code that are likely to appear before a software developer's eyes including programming constructs, data types, data structures, control flow, project organization, coding standards, documentation, and architectures. A companion title to this book will cover interfacing, and application-oriented code including the issues of internationalization and portability, the elements of commonly used libraries and operating systems, low-level code, domain-specific and declarative languages, scripting languages, and mixed language systems.

This book is--as far as I know--the first one to exclusively deal with code-reading as a distinct activity, one worthy on its own. As such I am sure that there will be inevitable shortcomings, better ways some of its contents could have been treated, and important material I have missed. I firmly believe that the reading of code should both be properly taught, and used as a method for improving one's programming abilities. I therefore hope that this book will spur interest to include code reading courses, activities, and exercises into the computing education curriculum so that in a few years our students will learn from existing open-source systems, just as their peers studying a language learn from the great literature.

Supplementary Material

Many of the source code examples provided come from the source distribution of NetBSD. NetBSD is a free, highly portable UNIX-like operating system available for many platforms, from 64-bit AlphaServers to handheld devices. Its clean design and advanced features make it an excellent choice for both production and research environments. I selected NetBSD over other similarly admirable and very popular free UNIX-like systems such as GNU/Linux, FreeBSD, and OpenBSD, because the primary goal of the NetBSD project is to emphasize correct design and well written code thus making it a superb choice for providing example source code. According to its developers, some systems seem to have the philosophy of "if it works, it's right" whereas NetBSD could be described as "it doesn't work unless it's right." In addition, some other NetBSD goals fitted particularly well with the objectives of this book. Specifically, the NetBSD project avoids encumbering licenses, provides a portable system running on many hardware platforms, interoperates well with other systems, and conforms to open systems standards as much as is practical. The code used in this book is a (now historic) export-19980407 snapshot. A few examples refer to errors I found in the code; as the NetBSD code continuously evolves, presenting examples from a more recent version would mean risking that those realistic gems would have been corrected.

I chose the rest of the systems I used in the book's examples for similar reasons: code quality, structure, design, utility, popularity, and a license that would not make my publisher nervous. I strived to balance the selection of languages, actively looking for suitable Java and C++ code. However, where similar concepts could be demonstrated using different languages I chose to use C as the least common denominator.

I sometimes used real code examples to illustrate unsafe, non-portable, unreadable, or otherwise condemnable coding practices. I appreciate that I can be accused of disparaging code that was contributed by its authors in good faith to further the open-source movement and to be improved upon rather than be merely criticized. I sincerely apologize in advance if my comments cause any offence to a source code author. In defense I argue that in most cases the comments do not target the particular code excerpt, but rather use it to illustrate a practice that should be avoided. Often the code I am using as a counter example is a lame duck, as it was written at a time where technological and other restrictions justified the particular coding practice, or the particular practice is criticized out of the context. In any case, I hope that the comments will be received good-humouredly, and openly admit that my own code contains similar, and probably worse, misdeeds.

From the B&N Reads Blog

Customer Reviews