swcarpentry / python-novice-gapminder

Plotting and Programming in Python
http://swcarpentry.github.io/python-novice-gapminder/
Other
163 stars 428 forks source link

Augmented assignment operator introduced without comment #582

Closed alex-ball closed 2 years ago

alex-ball commented 2 years ago

The solution to the "Cumulative Sum" challenge in Episode 12 uses the augmented assignment operator += without comment or explanation. In the rest of the episode, the more verbose total = total + whatever syntax is used. The only other occurrence of += is in Episode 18.

My feeling is that += is a useful shorthand but – given how similar it looks to comparisons like !=, >=, <= – deserves a little explanation for anyone who hasn't seen it before. How about having a callout just before "Cumulative Sum" that explains it, then converting "Identifying Variable Name Errors" to use it as well? That would help with retaining it for Episode 18.

Another solution would be to replace the instances in both episodes with the explicit, longer version, which would be less cognitive load but perhaps a bit of a shame.

alee commented 2 years ago

Thanks for catching this! I'm inclined to change it to total = total + number and skip the additional explanation as this lesson often receives feedback that it runs long...

Thoughts?

alex-ball commented 2 years ago

As I say, += is a useful keystroke saver, but only once you are comfortable with what it does.

Considering both the cognitive load and timing issues, yes, I'd be quite happy to see the instances of it replaced with total = total + number.