Week 6 Notes — Python

Saturday, Feb. 19 to Friday, Feb. 26

Week 6 Video (duration 2:40:45)

You have spent five weeks on C. Malan is trying to introduce Python in one long lecture by just comparing the way things are done in C with the way they are done in Python. This only kind of works pedagogically. Give it a go, but don’t be surprised if you start feeling like you are at sea in both languages. First, it is not always simply translation. The way you do things in the languages are sometimes more different than line-by-line translations.

Second, even if it are simply doing line-by-line translation, keeping two syntaxes in your head is non-trivial. For example, I have had to switch back and forth between C, Java, Swift, Python, Perl, and PHP to do various projects. Each of them is a little different syntactically, and I have never been good with the syntax at more than one language at a time. After five weeks of C, I’m going to be accidentally typing semicolons and using ‘//’ for comments as we switch to Python. Go easy on yourself if neither language is at all natural yet.

Third and finally, this one-lecture tour of Python is unsystematic. It should be followed by a systematic introduction of Python’s language features. Malan is doing what he can in the amount of time he has.

It is also worth noting that some of the comparisons between C and Python Malan makes are unfair. C has practically endless helpful libraries to allow you to avoid writing things from scratch. We were of course not using those because the idea was specifically to learn how things are written from scratch. So showing how easy Python is compared to C when you are allowed to tap into libraries like PIL (the Python Imaging Library) is an apples-to-oranges comparison.

Of course, Python is on balance substantially easier. The main reason for teaching you C before Python is that Python hides so much behind higher-level features that people who know Python and not C usually have no picture of what the computer is actually doing. You have that picture! Celebrate! Understanding memory, pointers, and buffers is the insight you need to structure programs efficiently even when working in a language that hides them.

Problem Set 6

Five Python programs to write! Hello, Mario, Cash or Credit (your choice), Readability, and DNA.