Learn in Public: My First Time Writing Code
Two weeks ago, I had a wonderful opportunity to write my very first code.
The opportunity came in form of a series of exercises I had to complete during my application to participate in a free online class on programming.
What Is This Online Class About?
The online class has learning materials from the first half of Stanford’s established introductory course, CS106A. CS106A is one of the most popular courses at Stanford University. It teaches the fundamentals of computer programming using the widely-used Python language.
The class is for those with no prior programming experience (like me), who want to learn introductory coding. Participants would not receive a grade in the course, nor would completing the class earn us a university credit. However, by the end of the course, we would have acquired a new and invaluable skill – how to program.
When I heard about this opportunity, I was excited because earlier that week, I had just made the decision to learn to code so I knew that class was going to be my starting point. So off I went, to register my interest.
Little bit about Karel
Karel was designed in the 80s as an introductory programming environment in which students teach a robot (Karel) to solve simple problems. He lives in a world consisting of a grid of streets (left-right) and avenues (up-down) and understands 4 basic commands:
– Karel moves by 1 square in the direction he is facing;
– Karel turns 90° left;
– Karel puts a beeper on the square he is standing at; and
– Karel lifts a beeper from the square he is standing at.
I went through the required chapters of Karel Reader (an eBook containing detailed information about Karel) and gained amazing knowledge on:
- Code blocks.
- Defining new functions.
- Basic For loops and Nested loops.
- Matching postconditions with preconditions.
- and a bunch of other stuff.
There were 3 coding exercises to be completed and each task was to be done in an Integrated Development Environment (IDE). The IDE had a code editor and an area titled ‘World’ to run the code already written. For each task, we were to write a program that made Karel accurately carry out a particular action.
One of the exercises, Shelter-in-Place, involve writing a program in which Karel collect some food (represented by an object called beeper), right outside his door and he then returns to his initial position inside the house. Apparently as people around the world are staying home to reduce the spread of COVID-19, Karel is playing his part by sheltering in place.
‘Everyone in this country should learn how to program a computer, because it teaches you to think.’
In my solution, I defined functions (from the 4 basic commands highlighted above) for Karel to move to the food package and return to his starting point.
Here’s the code I wrote:
And here’s Karel before, during and after the execution of my code:
(I couldn’t upload a short video of the program)
What a delightful experience.
PS: Two days after the deadline, I received a mail that I was admitted into the online class!