Recently I took an online course about Refactoring to Patterns. Here are some keys lessons learned in that course:
1 - Avoid Comments
Use tests or README instead. If you’re involved in a project where comments are present, use your own code to show how you absorb those comments with code/tests.
2 - Options is an Object
If you’re passing options as a parameter, sometimes it’s a good idea to encapsulate those options into its own object.
3 - Switch off Switches
Just don’t use them.
4 - Null is never a message
Don’t use Null to send a message in your method.
5 - Encapsulate Collections
Collections are like Pokemons, they always evolve…
6 - Thesaurus is your Friend
We know naming is hard… That’s why Thesaurus will help you out to find better names either with synonyms or antonyms.
7 - Services don’t return ‘Alien Objects’
A service must be distributed. It only can use primitives or DTOs.
8 - Services don’t raise exceptions
Instead they should return an error message.
9 - Null Object
Always try to use the Null Object pattern.
10 - For needs a Break
Don’t return
inside a for
loop to halt its execution. Use break
instead.