It amazes me every time how easy it is for our brains to do complex things. I am currently writing logic to draw out company processes on a visual canvas. At first this task seemed easy. I opened up the table and took a piece of paper and draw out a couple of these processes manually to get the hang of the underlying logic. This went pretty smoothly and after drawing 3 of these processes out I was ready to implement some algorithms that would do this work for me. Now a day later the logic that goes within this algorithm is mind blowing. What was a trivial thing for my brain to comprehend ended out in complex recursive algorithms.
How come my brain can come up with these algorithms so easily and use them in a fairly small amount of time, while when trying to materialize these algorithms it’s like it’s impossible to come up with the solution? Well without you knowing there are tons of rules in your head you apply to this logic. When implementing this into code you have to take account all the rules you have in your head and try to figure out what your brain does with these rules and in what order it applies them to reach a solution. Here are some quick tips that helped me reach my solution:
- Draw out the logic into a diagram while solving it manually with you brain
- When it seems too complex to draw it into a diagram then write all the rules that apply to this algorithm on a piece of paper
- Using the rules you’ve written down, try implementing it in loop and conditional statements still using a piece of paper!
- Start writing logic for a part of the algorithm first and then continue integrating extra bits to the algorithm to apply more rules.
- Now when you think you’ve mastered the logic on paper go implement it in you IDE
- Write the logic as easy as possible; don’t start refactoring like hell so you can make the code shorter, this is something you can do later on.
- When you have the logic start writing some tests against it. What I did for this one was the process I had drawn on paper, I converted this to objects I would use to draw. Then I would feed my test with the same data my brain used to draw the diagram and see if the outcome is the same.
- Then when the algorithm works, see if you can’t start refactoring it to make it more readable and shorter.
Geen opmerkingen:
Een reactie posten