DEV Community

Pavel Morava
Pavel Morava

Posted on

How to teach your programming language (or anything else)

When explaining, one should follow a simple principle:

  • One thing at a time.

It is quite obvious, isn't it?

Allow me to demonstrate how one can break the rule easily. Consider following text:

Now, we will write a recursive function to calculate factorial using reduce and lambda.

The relevant code in Python looks like this:

from functools import reduce

def factorial(x):
    return reduce (lambda y,z:y*z, range(1, x+1))

assert factorial(3) == 6, "3! = 2*3 = 6"
Enter fullscreen mode Exit fullscreen mode

To throw such code at newbies is the bulletproof method how to make them run away. In fact, there are several topics to discuss here:

  • mathematical definition of factorial,
  • import statement,
  • reduce function,
  • lambda,
  • range,
  • keywords such as
    • def,
    • assert,
    • and return.

No matter how skilled Pythonista you are, if at all, you should be able to recognize the problem. Not with the code itself, but with such approach, in which the lecturer tries to show too much.

Teachers often assume knowledges their students do not posses. In theory, the real challenges for advanced beginner stay with reduce and lambda. In practice, the question is whether or not our students, though well-versed in basics of Python, have similar firm grasp on math. What if they have absolutely no idea of what might be factorial or x! notation ?

Thus, my second advice for teachers would be:

  • Never assume anything.

But back to Python. I believe that under no circumstances one should teach together fairly complicated concepts like, for instance, lambda and reduce. Why? Because both of them deserve separated explanation and take a while to absorb them properly.

Typically, a good example deals with one unknown topic at a time, assuming that students understand the rest fairly well.

But what if some instructor objects, she has already explained everything before, including factorial and lambdas, so the reduce function remains the only subject to clarify?

Remember, when I told you not to assume anything? Be very careful when referring to previous topics; complicated abstractions need the time to settle down and expecting students, who have learned lambdas recently, to follow them effortlessly is simply too much.

Thus, my third and last advice is:

  • Simplify and repeat.

Rewriting intentionally our lambda to full function, no matter how redundant it is, may help listeners to focus more on subject in question.

lambda x,y: x+y

# changed to
def add(x,y):
    return x+y
Enter fullscreen mode Exit fullscreen mode

Even with danger you would appear like underestimating your audience, keep treating them like babies. More often than not, the instructors tend to take topics she understands for granted while the students think the opposite.

To conclude:

  • One thing at a time.
  • Never assume anything.
  • Simplify and repeat.

Discussion (0)