###How to think like a progammer
####First
Lets dispense with the idea of a 'programming genius'. A good talk on the topic is The Myth of the Genius Programmer
Programming well is about methodology.....not sparks of brillant insight( though these occasionally occur )
Before we actually formalize our methodology, lets learn the most important single thing to be a great Programmer:
####Discipline!.....taking the time to do it right. This stuff is hard, but sticking to a process helps to stay on track.
Forget about becoming a 'ninja' or a 'rockstar'. Become disciplined.
And remember, the programming world is a vast space
"you need to become comfortable with uncertainty, no programmer knows everything, and things are changing all the time"-Meridith
###The Methodology
####First, You must understand the problem
What is the unknown?, What is the data?, What is the condition?
Is it possible to satisfy the condition? Is the condition sufficient to determine the unknown? Is the condition redundant or contradictiory?
####Second, Devise a Plan
Have you seen it before?, Do you know a related problem?, Can you find an example of a related problem someone else has solved.....can you use it?
Can you restate the problem? Could you restate it still differently?
Better yet...can I break it down into a smaller problem, or solve a smaller part of the problem?
Analogy
What might be an analogy?
Auxillary Elements
Can I introduce a concept or structure that will simplify the problem?
####Third, Carry out your plan
Check each step. Can you see clearly that the step is correct? Can you prove that it is correct?
####Fourth, Examine the solution obtained
Can you check the result?
Can you derive the result differently? Can you use the result, or the method, for some other problem?
####Application, Lets look at a real world example
Problem: Sort 6 people by height, from shortest to tallest.
Step 1
Do I understand the problem?
It seems obvious, but ask more questions. What type of data is it? Are there performance limitations?
Step 2
Devise a plan
Is there a related problem here....an analogy?
Lets look at a coinstar machine...can we draw any inspiration?
Notice that if a coin doesn't fit in a slot it is cast aside....in other words it is moved to another slot...where the machine can check again if it fits in that slot.
The key idea we can take away from this is check to see if something fits in a slot, and if not, move it to a different slot and see if it fits.
#####The process
The Setup -What is the number of items we are going to sort? - In this case it is 6 -As we examine each item in the group, we will keep track of where its position is. -We will start with the first item...and go through the group until we have reached the end.
The Sort -Start with the first item in the list, compare it to the next. -Which one is taller? -Move the taller one down the list -STOP, Do we notice anything interesting happening to the list? -Knock the last item off the list....repeat again until done
Step 3
How do we check that this result is correct? Better yet...how in General Do we check if our programs are correct.
This is a topic that has been heavily researched, but to break it down..do this
At each step...before you perform the action, define a precondition, after you do the step, define a post-condition, both the pre and post condition must be true. There is a lot more to discuss here, but this is a more advanced topic surrounding program verification.
Step 4
Examine the result...is it absolutely correct? Can you think of a counter example that would show that your process is wrong or will produce an incorrect result in some case? Will this process of sorting ever break?
####Some general concepts
Measurement - Am I working in an environment that allows me to take a measurement at each point of my program? Do I have a window into the running of my program so I can see what's going on? If not...how do I get one...fast
Logic - When your code doesn't work, there is a reason why. You will find the reason why it doesn't, but you must be patient.
Learning - In this field you will never stop learning...EVER