Your programming roadmap

Functions

functions, nested functions, call expressions

Functions are chunks of reusable code used to complete a specific task.

Consider using the apply first, study second approach with the resources below: try a problem or exercise from the Apply It section first. If you get stuck, then use a course, book, or lecture in the Reference section. Or if you’re completely new to a topic, then learn just enough and apply right away. The point is: the quicker you get to the “doing,” the better the learning. Make your learning active.

Apply It

Build confidence using functions by solving the exercises in Brian Hogan’s electronic book, Exercises for Programmers. I mention this book a few times in the Pyramid, and it’s worth another mention. This time the focus is on functions (see chapter 5). Once you complete an exercise, add a constraint or challenge, which Hogan provides. This is a great way to stretch your knowledge.

Tip: The challenges and constraints that Hogan provides are ways to “recycle” programming problems, as I like to think of it. That is, repeat a problem multiple times; each time with a new intent. Although new problems are always fun, there’s a lot to gain from repetition with a purpose.

If you’re feeling good with functions, then try the problems in chapter 6 in Reuven Lerner’s book, Python Workout. I’ve also mentioned Lerner’s book in previous Pyramid topics, but it’s useful here, too. You’ll not only get practice using functions. But you’ll also expand your knowledge base when you watch the accompanying screencasts, where Lerner shows you how he solved the problem.

Exercism is a free platform that you should check out. You’ll get plenty of practice using functions as you write solutions to problems. Create an account, then solve problems in the language of your choice. You can also filter problems by topic and by difficulty.

Homework 1: Variables & Functions, Control, from Berkeley’s course CS 61A: Structure and Interpretation of Computer Programs, is a great way to get practice with functions. I really like this homework: the problems are clear, the tests are provided, and it’s free! Plus, there’s a “hint” video if you get stuck. This short video will show you how to access the files and run the tests for Homework 1.

"Today I will do what others won't, so tomorrow I can accomplish what others can't."

-Jerry Rice

Reference

Reference the Functions lecture series from the Berkeley CS 61A course, which is free. You may also find John DeNero’s free electronic book, Composing Programs, useful. In particular, see these sections:

Tip: It’s easier to work with a few things than many. So if you get stuck on a problem, simplify your input. It makes the problem much more manageable.

Say a problem gives you a list of five dictionaries that you need to sort. Simplify the input: create a list of two dictionaries, and get that working. Then, gradually increase your input until you solve the problem.


← Back to Programmer's Pyramid