Clean Code: A Handbook of Agile Software Craftsmanship (Robert C. Martin Series)
Rate it:
Open Preview
28%
Flag icon
This is sometimes called a data transfer object, or DTO.
28%
Flag icon
DTOs are very useful structures, especially when communicating with databases or parsing messa...
This highlight has been truncated due to consecutive passage length restrictions.
28%
Flag icon
They often become the first in a series of translation stages that convert raw data in a database into ob...
This highlight has been truncated due to consecutive passage length restrictions.
28%
Flag icon
Beans have private variables manipulated by getters and setters. The quasi-encapsulation of beans seems to make some OO purists feel better but usually provides no other benefit.
28%
Flag icon
Active Records are special forms of DTOs.
28%
Flag icon
They are data structures with public (or bean-accessed) variables; but they typically have navigational methods like save and find.
28%
Flag icon
Typically these Active Records are direct translations from database tables,...
This highlight has been truncated due to consecutive passage length restrictions.
28%
Flag icon
In any given system we will sometimes want the flexibility to add new data types, and so we prefer objects for that part of the system.
28%
Flag icon
Other times we will want the flexibility to add new behaviors, and so in that part of the system we prefer data types and procedures.
28%
Flag icon
Error handling is important, but if it obscures logic, it’s wrong.
28%
Flag icon
The problem with these approaches is that they clutter the caller.
28%
Flag icon
In a way, try blocks are like transactions.
29%
Flag icon
Try to write tests that force exceptions, and then add behavior to your handler to satisfy your tests.
29%
Flag icon
If you throw a checked exception from a method in your code and the catch is three levels above, you must declare that exception in the signature of each method between you and the catch.
29%
Flag icon
Each exception that you throw should provide enough context to determine the source and location of an error.
29%
Flag icon
Create informative error messages and pass them along with your exceptions. Mention the operation that failed and the type of failure.
29%
Flag icon
However, when we define exception classes in an application, our most important concern should be how they are caught.
29%
Flag icon
In most exception handling situations, the work that we do is relatively standard regardless of the actual cause.
29%
Flag icon
We have to record an error and make sure that we can proceed.
29%
Flag icon
Often a single exception class is fine for a particular area of code.
29%
Flag icon
The information sent with the exception can distinguish the errors.
29%
Flag icon
Use different classes only if there are times when you want to catch one exception and allow th...
This highlight has been truncated due to consecutive passage length restrictions.
30%
Flag icon
This is called the SPECIAL CASE PATTERN
30%
Flag icon
You create a class or configure an object so that it handles a special case for you.
30%
Flag icon
When we return null, we are essentially creating work for ourselves and foisting problems upon our callers.
30%
Flag icon
What exactly should you do in response to a NullPointerException thrown from the depths of your application?
30%
Flag icon
If you are tempted to return null from a method, consider throwing an exception or returning a SPECIAL CASE object instead.
30%
Flag icon
Unless you are working with an API which expects you to pass null, you should avoid passing null in your code whenever possible.
30%
Flag icon
In most programming languages there is no good way to deal with a null that is passed by a caller accidentally.
30%
Flag icon
Clean code is readable, but it must also be robust. These are not conflicting goals.
31%
Flag icon
There is a natural tension between the provider of an interface and the user of an interface.
31%
Flag icon
Third-party code helps us get more functionality delivered in less time.
31%
Flag icon
In learning tests we call the third-party API, as we expect to use it in our application.
32%
Flag icon
Learning tests verify that the third-party packages we are using work the way we expect them to.
32%
Flag icon
One good thing about writing the interface we wish we had is that it’s under our control.
32%
Flag icon
Good software designs accommodate change without huge investments and rework.
32%
Flag icon
We should avoid letting too much of our code know about the third-party particulars.
32%
Flag icon
We manage third-party boundaries by having very few places in the code that refer to them.
32%
Flag icon
First Law You may not write production code until you have written a failing unit test.
33%
Flag icon
Second Law You may not write more of a unit test than is sufficient to fail, and not compiling is failing.
33%
Flag icon
Third Law You may not write more production code than is sufficient to pass the...
This highlight has been truncated due to consecutive passage length restrictions.
33%
Flag icon
What this team did not realize was that having dirty tests is equivalent to, if not worse than, having no tests.
33%
Flag icon
The dirtier the tests, the harder they are to change.
33%
Flag icon
Test code is just as important as production code.
33%
Flag icon
It is unit tests that keep our code flexible, maintainable, and reusable.
33%
Flag icon
Without tests every change is a possible bug.
33%
Flag icon
Readability is perhaps even more important in unit tests than it is in production code.
34%
Flag icon
The first part builds up the test data, the second part operates on that test data, and the third part checks that the operation yielded the expected results.
34%
Flag icon
There are things that you might never do in a production environment that are perfectly fine in a test environment. Usually they involve issues of memory or CPU efficiency. But they never involve issues of cleanliness.
35%
Flag icon
One test should not set up the conditions for the next test.