02 - Short units Flashcards
What is the maximum amount of lines for a unit?
15 lines
What are the main benefits of short units in our code?
- Easy to test
- Easy to analyze
- Easy to reuse
Say, we have a situation in which we have a unit of code that has 25 lines. We have the opportunity to split this up into three units of code. However this increases the total lines of the file since new methods need to be created. Should we do this?
Yes!
Although there are also guidelines saying that we shouldn’t add unncecessary lines of code, the maximum of 15 lines for each units rule always trumps this.
What counts as a unit of code?
Everything between opening and closing curly braces of the method.
Let’s say I have a unit of 15 lines. I can split this up into three methods. These methods ofcourse all have their own headers so the lines of code in the entire file will increase. Should I do this?
Yes. The advantages of short units far outweigh the increase in overall volume.