There are two fun acronyms that you can use to describe different ways of writing code:
WET code means that you have duplicate blocks which provide similar or the same functionality, and DRY enforces the opposite. Many developers love to preach for DRY code because in many large codebases, having duplicate code can be really messy to maintain later.
So should you really be striving for DRY code? Well, not from the start.
I didn’t create this title just for convenience, it truly helps to start off with having some duplicate code.
Imagine that you’re starting on a new project or feature and expect the scope to change for either business or technical reasons. Attempting to follow the DRY concept and thus creating abstractions early on to prevent duplicate code will decrease the flexibility of your code. This is not to say that the right abstraction cannot be made, but it’s too easy to make the wrong one early on when you don’t have a full understanding of what you’re creating.
This also makes it a lot simpler to focus on the project or feature at hand, and not have to make architectural decisions.
It’s crucial that you factor in the time that will be required to refactor your code. Please don’t skip this! Once you have a much fuller understanding of how everything should be functioning, you can create the necessary abstractions that may also be flexible enough for changes because you already had experience with that happening.
I wasn’t able to create any video content this week, but I did share a lot of tweets!
See you next Sunday, same inbox? π