Forum Moderators: coopster
First, I think through manually performing the task and, where possible, work it once by hand.
Next, I think back through what I did, tiny step by tiny step and write it down as a long list of comments. If the concept you're writing down doesn't seem easily calculated by a computer, think through exactly and precisely how you execute the concept and write it down as multiple steps.
Finally, I turn the comments into code - normally one line of code per comment I'd written.
I don't believe in 'magic leaps of the human brain' when it comes to most tasks which can be expressed in numbers and words... when you break things down small enough they almost always result in small logical instructions.
Example:
Finding the coordinates of the row and column dividers of a table from an image of the table. Sound complex but it's actually simple. If I printed the table and gave you a ruler you could do it without a problem.
What are you doing? On the highest scale you're recognising row and column dividers and measuring their location.
Divide it into two: one set of recognising row dividers, one set of measuring column dividers.
To recognise row dividers, you are moving from the top to the bottom of the image.
//loop from y=0 to y=y_max
As your eye moves downward, you stop when you recognise a line which runs across the table. What does that mean? What is a line? A string of dark colours. So, find the longest string of dark colours.
//subloop from x=0 to x=x_max
// - if current location > threshold darkness then
// - - add to test_counter
// - else
// - - if test_counter>counter
// - - - set counter as test_counter
// - now reset test counter and try for another long string of dark on this row
//end subloop
//if counter > threshold * x_max then record this as a row, unless previous y value was also a row (to avoid multiple counts for thick lines)
//end loop on y
Column logic is the same, just with the loop parameters exchanged.
So - how do you work out your logic?
winging it gives me a creative solution
You could be getting a good creative solution at the expense of the best one you might have got by logically dividing the task at hand.
I don't believe many people do care about the long term maintenance expenses of the codes and how tough or easy it is going to be to add the smallest task possible.
You see it all the time.
I break it down in a similar way and then start at the beginning. Then step by step and piece by piece.
If something is more complicated then I do exactly as you laid out.