📒Coding Strategies
Last updated
Last updated
One of the biggest challenges when beginning a project is to know where to start.
There are two main aspects to this process:
Do you understand the problem from a programatic perspective?
Do you understand what its purpose is?
Do you understand the logic of the application itself?
Start with the beginning of the program first.
Start with the "Minimum Viable Product"
Leave aside the features of the overall program that are not core to its purpose.
Strategize about how you can fake other parts of the program. (Can you fake a random dice roll by starting with a value that is always 4?)
Processes and logic require control flow.
Does your program repeat itself? Maybe you need a loop.
Does your program have logic? If this then .... You might need a conditional.
Data requires variables and data types.
Does your program do math? You need number types.
Does your program have a set or list? Is that list ordered? You might need an array.
A program is a sum of its parts.
A modern computer system is incredibly complex and it's impossible to understand what goes on at every level.
(See this description of what happens when you search on google).
However the task of writing a program is to build a contextually complete mental model of what is happening when the program runs.
This means understanding things about the code and how it behaves in the system.
You need to understand what a loop does, but also that it won't run unless you click 'refresh' on the browser.
Strategies around how to methodically build and test your mental models are an important meta-skill when building a program and when learning a new system.
Run your code often.
Before you write any code strategize about what the next smallest bit you can write, in order to run it as soon as possible.
Write code with the purpose of testing your hypotheses.
Your mental model is one of the most important things you are building as you build the program. (Just as important if not more important than the program itself). You are the one using your personal knowledge to encode the behavior of the code. If you don't understand how it works, no one else will either.
Don't write code in order to fix your errors, write code to prove or disprove your hypotheses, then write correct code.
Use console.log
to understand your code's behaviour.
Use it to check control flow.
Use it to check values.
Mental models are the key to building your computational thinking skills.
Use each error as an opportunity to understand the system better. (But also know when to strategically move on - you won't achieve perfect knowledge - see "what happens when" link above).
Expect lots of errors.
Errors are the practice and process of programming. Use them to learn more. Be playful with the system and don't be afraid to break things.
Formulate questions
Practice asking questions when you are working on a problem.
What have you tried?
What is the context of the error? When do you see it, what is the incoming data and how does it affect the output?
What do you think is happening based on the facts?
(Note that this doesn't mean that during this course a question like- "I dunno what's happening." is not acceptable. Any question is acceptable).
Talk to yourself. -This is called rubber duck programming.
Optimize your programming and learning process by implementing some best practices.
Fluency at moving between the different dev tool applications means that you have a better chance of following a thought about the code all the way through.
Your goal should be to build a fluid, distraction free coding environment. Learn keyboard shortcuts. Be able to turn off notifications. Don't attempt to watch a movie while coding.
If you need to look at a different variable in the console, be able to switch back to the editor, save the change and be looking at it in the browser in only a few keystrokes. It gives the best chance that you move ahead through the process.
This also means that when you break something that you are not afraid you'll be able to put it back. Know how to use undo. Know how to use Git and GitHub to retrieve old versions in case you need to restore something.
The skill of finding contextually appropriate knowledge about something is a key skill in moving forward with programming. Some of these things are obvious but the subtleties of finding the correct information is a skill that takes some practice if you're no used to it.
The appropriate combination of keywords in the spectrum of general to specific.
Too few keywords and you won't find an exact match. Too many and there may not be enough results.
When to google an exact error message and when it's not helpful.
Similar to above, googling some types of error message will yield an exact solution. Some won't.
Which sites to look for in the results and which to discard.
Some sites deal in specific documentation. Others are how-to-guides for beginners.
Know exactly what level of detail you are looking for.
Google searches can quickly take you to the most verbose, complete technical documentation on a given subject. A lot of the times you need information that is more prescriptive than that.
Know when a solution that is not an exact match is adaptable or not.
Don't spend a lot of time on a result that is not relevant enough to your problem, but don't disregard a solution because it is not a perfect match to your problem.
Learning to code is less like learning things like English and history, and more like learning the piano. There is some theory involved but it also heavily involves practice.
Deliberate practice means quality of hours over quantity. (Although mastery also involves quantity of hours).
Many of the principles stated above have to do with your meta-awareness of your own process. We believe that the more awareness you have of your own process the more effective your learning will be.