A Philosophy of Software Design
Rate it:
Open Preview
54%
Flag icon
In his book Clean Code, Robert Martin takes a more negative view of comments: ... comments are, at best, a necessary evil. If our programming languages were expressive enough, or if we had the talent to subtly wield those languages to express our intent, we would not need comments very much — perhaps not at all. The proper use of comments is to compensate for our failure to express ourselves in code.... Comments are always failures. We must have them because we can’t always figure out how to express ourselves without them, but their use is not a cause for celebration.
55%
Flag icon
This results in long names such as isLeastRelevantMultipleOfNextLargerPrimeFactor. Even with all these words, names like this are cryptic and provide less information than a well-written comment.
55%
Flag icon
I worry that Martin’s philosophy encourages a bad attitude in programmers, where they avoid comments so as not to seem like failures. This could even result in good designers coming under false criticism: “What’s wrong with your code that it requires comments?”
55%
Flag icon
Well-written comments are not failures. They increase the value of code and serve a fundamental role in defining abstractions and managing system complexity.
55%
Flag icon
The reason for writing comments is that statements in a programming language can’t capture all of the important information that was in the mind of the developer when the code was written.
58%
Flag icon
Comments augment the code by providing information at a different level of detail.
59%
Flag icon
When documenting a variable, think nouns, not verbs. In other words, focus on what the variable represents, not how it is manipulated.
61%
Flag icon
If you want code that presents good abstractions, you must document those abstractions with comments.
61%
Flag icon
The first step in documenting abstractions is to separate interface comments from implementation comments.
61%
Flag icon
Interface comments provide information that someone needs to know in order to use a class or method; they define the abstraction. Implementation comments describe how a class or method work...
This highlight has been truncated due to consecutive passage length restrictions.
67%
Flag icon
When documenting variables, focus on what the variable represents, not how it is manipulated in the code.
69%
Flag icon
The goal of comments is to ensure that the structure and behavior of the system is obvious to readers, so they can quickly find the information they need and make modifications to the system with confidence that they will work.
70%
Flag icon
Good names are a form of documentation:
71%
Flag icon
Good names have two properties: precision and consistency.
75%
Flag icon
Overall, I would argue that readability must be determined by readers, not writers.
75%
Flag icon
Many developers put off writing documentation until the end of the development process, after coding and unit testing are complete. This is one of the surest ways to produce poor quality documentation.
76%
Flag icon
When the code is done, the comments are also done. There is never a backlog of unwritten comments.
76%
Flag icon
Comments serve as a canary in the coal mine of complexity. If a method or variable requires a long comment, it is a red flag that you don’t have a good abstraction.
77%
Flag icon
in tactical programming, the primary goal is to get something working quickly, even if that results in additional complexity; in strategic programming, the most important goal is to produce a great system design.
78%
Flag icon
If you want to maintain a clean design for a system, you must take a strategic approach when modifying existing code.
78%
Flag icon
To achieve this goal, you must resist the temptation to make a quick fix. Instead, think about whether the current system design is still the best one, in light of the desired change.
81%
Flag icon
Code reviews provide another opportunity for enforcing conventions and for educating new developers about the conventions.
81%
Flag icon
When in Rome ... The most important convention of all is that every developer should follow the old adage “When in Rome, do as the Romans do.”
82%
Flag icon
Don’t change existing conventions. Resist the urge to “improve” on existing conventions.
82%
Flag icon
Your new idea may indeed be better, but the value of consistency over inconsistency is almost always greater than the value of one approach over another.
82%
Flag icon
Obscurity occurs when important information about a system is not obvious to new developers.
86%
Flag icon
To make code obvious, you must ensure that readers always have the information they need to understand it.
87%
Flag icon
Before using implementation inheritance, consider whether an approach based on composition can provide the same benefits.
88%
Flag icon
Tests, particularly unit tests, play an important role in software design because they facilitate refactoring.
88%
Flag icon
Although I am a strong advocate of unit testing, I am not a fan of test-driven development. The problem with test-driven development is that it focuses attention on getting specific features working, rather than finding the best design.
89%
Flag icon
One place where it makes sense to write the tests first is when fixing bugs. Before fixing a bug, write a unit test that fails because of the bug.
89%
Flag icon
so they add clutter to the class’s interface without providing much functionality. It’s better to avoid getters and setters (or any exposure of implementation data) as much as possible.
91%
Flag icon
This is true even for experienced developers. If you start making changes based on intuition, you’ll waste time on things that don’t actually improve performance, and you’ll probably make the system more complicated in the process.
91%
Flag icon
The key idea is to design the code around the critical path.
92%
Flag icon
try to minimize the number of special cases you must check.
94%
Flag icon
The most important overall lesson from this chapter is that clean design and high performance are compatible.
94%
Flag icon
Complicated code tends to be slow because it does extraneous or redundant work.
95%
Flag icon
Shallow classes are often the result of treating too many things as important.
95%
Flag icon
This mistake leads to situations where important information is hidden, or important functionality is not available so developers must continually recreate it. This kind of mistake impedes developer productivity and leads to unknown unknowns.
« Prev 1 2 Next »