Those SOLID principles many talk about are really helpful. But why? Because they were stated and tested by advanced programmers in real situations? I say this is an enforcement, a reason to trust them, but not the reason to jump on them. It’s actually about understanding the benefits of using them and being able to identify when you need them.
All of them help in the way of having clean code. But why would you need clean code? You can really have messy code which does the same thing as the clean one. Except when you aim for long term healthy business. Solid code makes solid business.
Each of the SOLID principles comes with its ideology, but does not guarantee a 100% benefit, because there could be other factors which more or less collide with them, the first one being when you play around the principles, but do not apply them properly.
While the benefits you get from these principles are well known, I’d like to state some of them which for me are more real, more close to the business side. Continue reading Real benefits of SOLID principles
One moment a project can get on an unwanted road is when new business rules pop in. Even more if this happens on a tight deadline. You just throw some innocent if statements, and that’s how hell can unleash…
Later, other rules will be requested by business. Each will have at least one if statement and maybe interactions with some services. Then one day you notice yourself tangled in the code you’d prefer to never see.
There are ways to implement these rules fast and efficient, avoiding most of those undesired if statements. This is my situation:
- I have a Song resource and a User resource
- A Song can be restricted to a User based on multiple conditions
- If a Song is restricted to a User, we have to let them know why, and this can be for reasons like:
- Song is not released yet
- Song was retired by the record company
- User is from a country where we don’t have rights to offer the Song
- User has a plan which doesn’t allow him to play the Song
- and so on
The “what” doesn’t matter, the “how” is the key. And business folks can change their mind any time. They want a new rule fast, or cancel one, or change it. Continue reading Avoiding IF statements for business rules