A Philosophy of Software Design
Rate it:
Kindle Notes & Highlights
61%
Flag icon
If interface comments must also describe the implementation, then the class or method is shallow.
62%
Flag icon
The interface comment for a method includes both higher-level information for abstraction and lower-level details for precision:
62%
Flag icon
If the method has any side effects, these must be documented in the interface comment.
62%
Flag icon
A method’s interface comment must describe any exceptions that can emanate from the method.
62%
Flag icon
If there are any preconditions that must be satisfied before a method is invoked, these must be described
66%
Flag icon
Implementation comments: what and why, not how
66%
Flag icon
The main goal of implementation comments is to help readers understand what the code is doing
66%
Flag icon
Add a comment before each of the major blocks to provide a high-level (more abstract) description of what that block does.
67%
Flag icon
In addition to describing what the code is doing, implementation comments are also useful to explain why.
67%
Flag icon
When documenting variables, focus on what the variable represents,
69%
Flag icon
The goal of comments is to ensure that the structure and behavior of the system is obvious to readers,
70%
Flag icon
Choosing Names
70%
Flag icon
Good names are a form of documentation:
70%
Flag icon
However, I consider any unsolved bug to be an intolerable personal insult, so I decided to track it down.
71%
Flag icon
Take a bit of extra time to choose great names, which are precise, unambiguous, and intuitive.
71%
Flag icon
Good names have two properties: precision and consistency.
72%
Flag icon
If a variable or method name is broad enough to refer to many different things, then it doesn’t convey much information to the developer and the underlying entity is more likely to be misused.
73%
Flag icon
If you find it difficult to come up with a name for a particular variable that is precise, intuitive, and not too long, this is a red flag. It suggests that the variable may not have a clear definition or purpose.
73%
Flag icon
If it’s hard to find a simple name for a variable or method that creates a clear image of the underlying object, that’s a hint that the underlying object may not have a clean design.
73%
Flag icon
first, always use the common name for the given purpose;
73%
Flag icon
second, never use the common name for anything other than the given purpose;
73%
Flag icon
make sure that the purpose is narrow enough that all variables with the name ...
This highlight has been truncated due to consecutive passage length restrictions.
75%
Flag icon
“The greater the distance between a name’s declaration and its uses, the longer the name should be.”
75%
Flag icon
The best time to write comments is at the beginning of the process,
75%
Flag icon
Not only does this produce better documentation, but it also produces better designs and it makes the process of writing documentation more enjoyable.
76%
Flag icon
By now, it’s been a while since you designed the code, so your memories of the design process are becoming fuzzy. You look at the code as you are writing the comments, so the comments repeat the code.
76%
Flag icon
For a new class, I start by writing the class interface comment.
76%
Flag icon
I iterate a bit over these comments until the basic structure feels about right.
76%
Flag icon
At this point I write declarations and comments for the most important class instance variables in the class.
76%
Flag icon
Finally, I fill in the bodies of the methods, adding implementatio...
This highlight has been truncated due to consecutive passage length restrictions.
76%
Flag icon
First, it produces better comments. If you write the comments as you are designing the class, the key design issues will be fresh in your mind, so it’s easy to record them.
76%
Flag icon
It’s better to write the interface comment for each method before its body, so you can focus on the method’s abstraction and interface without being distracted by its implementation.
76%
Flag icon
During the coding and testing process you will notice and fix proble...
This highlight has been truncated due to consecutive passage length restrictions.
76%
Flag icon
Comments provide the only way to fully capture abstractions, and good abstractions are fundamental to good system design.
76%
Flag icon
If the interface comment for a method provides all the information needed to use the method and is also short and simple, that indicates that the method has a simple interface. Conversely, if there’s no way to describe a method completely without a long and complicated comment, then the method has a complex interface.
76%
Flag icon
if it takes a long comment to fully describe a variable, it’s a red flag that suggests you may not have chosen the right variable decomposition.
76%
Flag icon
The comment that describes a method or variable should be simple and yet complete. If you find it difficult to write such a comment, that’s an indicator that there may be a problem with the design of the thing you are describing.
77%
Flag icon
I’m looking for the design that can be expressed completely and clearly in the fewest words.
77%
Flag icon
in strategic programming, the most important goal is to produce a great system design.
78%
Flag icon
As a result, the system design gets just a bit worse, and the problems accumulate with each step in the system’s evolution.
78%
Flag icon
Ideally, when you have finished with each change, the system will have the structure it would have had if you had designed it from the start with that change in mind.
78%
Flag icon
If you’re not making the design better, you are probably making it worse.
78%
Flag icon
“Is this the best I can possibly do to create a clean system design, given my current constraints?”
78%
Flag icon
Every development organization should plan to spend a small fraction of its total effort on cleanup and refactoring;
78%
Flag icon
The best way to ensure that comments get updated is to position them close to the code they describe,
78%
Flag icon
don’t put all the comments for an entire method at the top of the method. Spread them out, pushing each comment down to the narrowest scope that includes all of the code referred to by the comment.
79%
Flag icon
In general, the farther a comment is from the code it describes, the more abstract it should be (this reduces the likelihood that the comment will be invalidated by code changes).
79%
Flag icon
Comments belong in the code, not the commit log
79%
Flag icon
Maintaining comments: avoid duplication
79%
Flag icon
Instead, try to document each design decision exactly once.