How to get started on a programming exercise
Scenario:
You're learning to code, learning syntax for a programming language, and working on thinking programatically. The lesson video or lecture is completed and now you're now facing a programming problem that is expecting you to understand and apply the new content.
How do you get started?
Here's your algorithm for getting started
-
With intent, read the curriculum and the code examples.
-
Go back and deliberately read the example code very closely and slowly.
-
Copy any example code into your editor.
-
Identify the pieces of syntax that you recognize.
-
Identify the code for the new concept that you're working with.
-
Ask yourself how the syntax or concepts you know already support and connect with the new topic or new syntax. Often, the new is relatable in terms of the old.
-
Ask yourself questions about the code example
- What is this entire code example supposed to do?
- What piece of the language is this new concept?
- Is the new code a new piece of syntax? Or is it an existing piece of syntax?
-
-
Run the example code
-
Observe results. Think about each piece of code. What is it doing, what did you expect it to do?
-
Try modifying the example code so that you change variables to see different results (one at a time...)
If the example code demonstrates how to make a loop from 0 to 9:
- Modify the code to make a loop that starts at 1 and ends at 10.
- Modify the code to make a loop that starts at 10 and counts down to 0. -
Try removing as many moving pieces from the code for the new concept as possible... try to isolate a unit of work that uses the new concept and test it in isolation
-
Read the first exercise problem. Read it slowly, with attention to detail.
-
Ask yourself questions about the exercise:
- Can you explain or restate the problem in plain English?
- Are you able to write down the steps from problem to solution in English, without using any code?
- Break the exercise down into pieces. Each piece is either something you've seen or it's new.
- Given the concept for this lesson, identify which part of the exercise uses the new topic
- For the new piece, what is similar between the exercise code and the example code for the lesson?
-
Work to write code for a smaller problem than the exercise asks.
If the exercise says:
- Prompt the user for a number between 1 and 50
- If the input is not numeric or out of that range, ask them again for a number. Repeat until they give a number between 1 and 50.
- Start by making sure you're able to prompt a user, then store the result of prompt to a variable for later.
- Go after the low-hanging fruit first. Momentum begets momentum. -
If you're still having problems and stuck, go to step 1.
-
If friction, confusion, and "writer's block" persist, then ask for help from another human being. Explain the steps you've already taken, and attempt to ask your question as clearly as possible. Here's a good resource on how to ask effective questions