Stanford CS106A Lecture 3

Haha… I should have watched this Lecture before completing the first assignment (at least for the last two problems from it)!

Here are my takeaways from this Lesson, which I wish I would have applied earlier:

  • Add in comments: I was so focused on making sure the program worked, I didn’t really write out comments of what I was doing. If you have a few lines of comments, you can comment by starting with “/*” adding the comments and ending with “*/”. Or if you just have a one line comment, you can just start the line with “//”. I will keep this in mind and add in more detailed notes to my future assignments.
  • Pre and Post Conditions: For each method, the professor recommended adding a “Pre-Condition” and a “Post-Condition” in the comment section, to clarify in what circumstances this command should be used and what to expect after Karel is done executing this command.
  • Top-down Processing: The idea is to start by listing out the higher-level steps Karel needs to execute and then write out the more detailed commands. I’ve kind of realized that on my own while going through the first assignment, but would have been useful to know to do this initially.
  • Rules of Decomposition: These sound like pretty good guidelines for decompositions – solve 1 problem, methods should be 1-15 lines, have a good name, explain what you’re doing in a comment.
I will write much better documented code from now on!

Enjoy the article? Join over 17,500+ Swift developers and enthusiasts who get my weekly updates.

  • Olivier

    I agree!

    I also started the 1st Karel assignment without watching lecture 3 and it helps a lot!