Stop being satisfied with your skills, and take them to a new level!
So here's my challenge for this week:
Keep method lengths below 9 lines.
It is very hard at first, because all those conditions and loops which make our methods long are in the way. But do they really have to be there? Can't they have a separate method in which they can run in isolation? Try and name concepts in your methods and get familiar with the "extract method" refactoring tool in your IDE (if it has one).
I don't say that you should go and modify every existing method there is in your codebase. I'm daring you to not to write methods longer than 9 lines for a week. Just one week! You can do it!
What good does this do?
Well first of all, you'll learn how to represent a feature, method in concepts.
You'll end up with small methods which are easy to understand and easy to test.
You'll find yourself re-using concepts rather than copy-pasting code snippets.
Oh, and don't forget to learn keyboard shortcuts for the IDE functions you use!
Here's what I dare you to do.
- Do the challenge
- Record your observations
- Blog about your experiences, and link it to this post
- Share your post in the comment section of this post.