+ 3
Decomposition method
Hello guys! I'm new in the app and python learner. I came here for a bit of help to understand better how to apply decomposition. In my course they ask this a lot and i seem to be more of "throw myself down into the code" then preparing a plan for it before. Thanks for your help!
4 ответов
+ 7
I'm the type of coder who dives into problems head-first aswell. Probably depends on the person :)
There's the old engineering saying that you need to build something 3 times: Once to understand the problem, once to understand the solution and once to make it right.
When planning the whole project in advance you inevitably are going to miss things and many problems don't cross your mind until you're implementing. So instead of a lot of planning I build some buggy code that barely holds together (trying to understand the problem) and then I'll refactor and re-do a lot of the project following proper clean coding principles.
Of course it helps to have a rough course of action in advance.
About decomposition: Functions can be too large but never too small. If you catch yourself thinking "...next, I need to swap these two array elements", write a function called `swapArrayElements` and call it, instead of putting it all in the same function. You'll thank yourself later.
+ 5
When I had first begun my coding journey, I couldn't make a single code apart from the basic ones. It wasn't that I was dyslexic or something, it was just that I was in a hurry to complete typing something and somehow make the code instead of thinking the problem over and over again and finally getting to the coding part. My only advice to you would be to NEVER start coding right away when you're working on a project. Use your brain first. Make a plan before touching the keyboard. Try to think of a way to solve it (or ways to solve it). It might take some practice but you'll get it once you focus enough on the matter at hand. Good luck pal!
+ 5
Schindlabua Yup, that's a valid point. So what I usually do for projects that take a few days to complete is to break it down into small fragments that I can handle and then do the coding. When writing code, I always tend to ask myself, "for what reason are you typing 'this'? Is there a better alternative?" Sometimes, the frustration and the urge to just type something out goes out of control and I end up backspacing whatever I had typed mindlessly and repeating the process again. Once I've run out, I tend to make comments including what I would have to do the next day. This works everytime.
+ 2
There are only three parts to a procedure:
1. Input
2. Processing
3. Output
Identify your input.
Know what output is expected.
Use analysis to reduce the problem and figure out what processing is needed to transform the input into the expected output. Then use synthesis to assemble the parts into the final output.