Clean Code: A Handbook of Agile Software Craftsmanship (Robert C. Martin Series)
Rate it:
Open Preview
5%
Flag icon
Remember that code is really the language in which we ultimately express the requirements. We may create languages that are closer to the requirements. We may create tools that help us parse and assemble those requirements into formal structures. But we will never eliminate necessary precision—so there will always be code.
6%
Flag icon
When others change bad code, they tend to make it worse.
6%
Flag icon
Bjarne closes with the assertion that clean code does one thing well. It
6%
Flag icon
Bad code tries to do too much, it has muddled intent and ambiguity
8%
Flag icon
If a name requires a comment, then the name does not reveal its intent.
9%
Flag icon
My personal preference is that single-letter names can ONLY be used as local variables inside short methods. The length of a name should correspond to the size of its scope [N5].
9%
Flag icon
Java programmers don’t need type encoding. Objects are strongly typed, and editing environments have
10%
Flag icon
One difference between a smart programmer and a professional programmer is that the professional understands that clarity is king. Professionals use their powers for good and write code that others can understand.
11%
Flag icon
The hardest thing about choosing good names is that it requires good descriptive skills and a shared cultural background. This is a teaching issue rather than a technical, business, or management issue.
12%
Flag icon
The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than that. This
12%
Flag icon
FUNCTIONS SHOULD DO ONE THING. THEY SHOULD DO IT WELL. THEY SHOULD DO IT ONLY.
13%
Flag icon
In order to make sure our functions are doing “one thing,” we need to make sure that the statements within our function are all at the same level of abstraction.
13%
Flag icon
Mixing levels of abstraction within a function is always confusing.
13%
Flag icon
Single Responsibility Principle7
13%
Flag icon
Open Closed Principle8
14%
Flag icon
The ideal number of arguments for a function is zero (niladic). Next comes one (monadic), followed closely by two (dyadic). Three arguments (triadic) should be avoided where possible. More than three (polyadic) requires very special justification—and then shouldn’t be used anyway.
14%
Flag icon
Output arguments are harder to understand than input arguments.
14%
Flag icon
we are used to the idea of information going in to the function through arguments and out through the return value. We don’t usually expect information to be going out through the arguments.
14%
Flag icon
Using an output argument instead of a return value for a transformation is confusing. If a function is going to transform its input argument, the transformation should appear as the return value.
14%
Flag icon
Flag arguments are ugly. Passing a boolean into a function is a truly terrible practice. It immediately complicates the signature of the method, loudly proclaiming that this function does more than one thing. It does one thing if the flag is true and another if the flag is false!
15%
Flag icon
Side effects are lies. Your function promises to do one thing, but it also does other hidden things.
15%
Flag icon
Anything that forces you to check the function signature is equivalent to a double-take. It’s a cognitive break and should be avoided.
15%
Flag icon
In general output arguments should be avoided. If your function must change the state of something, have it change the state of its owning object.
15%
Flag icon
Functions should either do something or answer something, but not both. Either your function should change the state of an object, or it should return some information about that object. Doing both often leads to confusion.
15%
Flag icon
The real solution is to separate the command from the query so that the ambiguity cannot occur.
15%
Flag icon
Prefer Exceptions to Returning Error Codes
16%
Flag icon
Open Closed Principle (OCP) [PPP02].
16%
Flag icon
Don’t Repeat Yourself13 13. The DRY principle. [PRAG
16%
Flag icon
Duplication may be the root of all evil in software.
16%
Flag icon
In the end, I wind up with functions that follow the rules I’ve laid down in this chapter. I don’t write them that way to start. I don’t think anyone could.
16%
Flag icon
The art of programming is, and has always been, the art of language design.
17%
Flag icon
“Don’t comment bad code—rewrite it.”
17%
Flag icon
Nothing can be quite so damaging as an old crufty comment that propagates lies and misinformation.
17%
Flag icon
Why am I so down on comments? Because they lie. Not always, and not intentionally, but too often. The older a comment is, and the farther away it is from the code it describes, the more likely it is to be just plain wrong. The reason is simple. Programmers can’t realistically maintain them.
17%
Flag icon
It is possible to make the point that programmers should be disciplined enough to keep the comments in a high state of repair, relevance, and accuracy. I agree, they should. But I would rather that energy go toward making the code so clear and expressive
17%
Flag icon
Inaccurate comments are far worse than no comments at all.
17%
Flag icon
Truth can only be found in one place: the code.
17%
Flag icon
however, that the only truly good comment is the comment you found a way not to write.
19%
Flag icon
Any comment that forces you to look in another module for the meaning of that comment has failed to communicate to you and is not worth the bits it consumes.
22%
Flag icon
What does that mean to us? It appears to be possible to build significant systems (FitNesse is close to 50,000 lines) out of files that are typically 200 lines long, with an upper limit of 500. Although this should not be a hard and fast rule, it should be considered very desirable.