Let's start with the beginning. Before starting anything, make sure you really understand the problem you are trying to solve. Make sure you dedicate enough time for it because otherwise you might end up solving the wrong problem which is bad for everybody.
So, assuming you are very intimate with your problem, it's time to start working on a solution, right? This usually proves to be waaaaay more difficult than expected, but you can make your life easier by applying Decomposition.
No, we are not talking about the rot process by which dead organic substances are broken down into simpler organic or inorganic matter such as carbon dioxide, water, simple sugars and mineral salts :). Let's focus on decomposition in software engineering, which is the process of breaking down a large problem into more manageable sub-problems.
Ok, but what does this mean. Let's take an example.
Any example works, this is the beauty of decomposition as it can be applied in every day problems, not only programming. So, let's take a simple problem such as cleaning your car. Let's break it down in several more manageable sub-problems and we can end up with:
cleaning car exterior.
cleaning car interior.
Pretty straight forward, right? Ok, now what? Next, we apply decomposition again to the sub-problems.
We will continue to apply decomposition until we are left with sub-problems which are so simple it doesn't make sense to go deeper.
For this example we will continue with cleaning the car interior, and we can end up with the following:
vacuum it.
clean floor mats.
clean dashboard dust.
clean glass elements (windows + mirror).
spray dust-prevention solutions on dashboard.
Next, let's go deeper with the vacuum part, we get to vacuum the following:
floor.
seats.
door pockets.
hard to reach places (e.g. between seats).
trunk.
Pretty straight forward, right? Now, for efficiency, you could think about doing these steps in a certain order. For example you might want to start with the interior and then the exterior.
Also, there are some other steps you can consider which could help you lower the cleaning time. For example, have a vacuum cleaner nearby, ready to go and ensuring you remove all your items from the car (e.g. floor mats, things in the trunk, baby seats etc.) before starting to vacuum it.
With decomposition, we managed to decompose the initial problem (cleaning the car) into several sub-problems which are now so clear and easy to do that it doesn't make sense to go deeper with decomposition. So now we can start just start the vacuum cleaner and start working.
If we go through all the identified sub-problems and follow-up on them, we will end up with having resolved the initial, more complex problem: cleaning the car.
Decomposition is a critical skill to have and the more you apply it, the easier it gets to use it. As we've seen, it can be applied in anything, not just in coding. It's an universal principle.
Also, there is no right or wrong answer, which makes this even more valuable as several people can come up with different solutions for the same problem, which is totally fine.
Then you just need to pick the better solution which requires different analysis, we'll talk about in a future post. However, as best practice, you can choose the simplest solution and you can't go wrong with it.
Now, as an exercise, let's go into the software world and start thinking about how would you break down a blog. Again, no coding skills required, think about how a blog could be created and by using decomposition split it in several sub-problems until everything is so clear and easy to do that it does not make sense to go further.
Looking forward to hearing your decomposition ideas. Feel free to use the social media channels to let us know how you did and ask for feedback.
Photo by Barn Images
Comments