Jeff Knupp: Keynote: Writing idiomatic Python

published May 09, 2014

Jeff Knupp gives the keynote at Pygrunn: Writing idiomatic Python.

See the PyGrunn website for more info about this one-day Python conference in Groningen, The Netherlands.

Towards comprehensible and maintainable code.

I am author of the Writing Idiomatic Python book.

Idiomatic Python is Pythonic code: code written in the way that the Python community has agreed it should be written.

Who decides this? Python developers, through the code that they write. Occasionally: Guido van Rossum.

The goals are: readability, maintainability and correctness.

"But I am a scientist, why should I write idiomatic code?" You want to be peer reviewed, right? If your code is eye-bleeding bad, you will get peer ignored.

"But I just write scripts." You program in Python.

"But I am coming from Java. Python programmers can still read all my class names that all have Factory in it, right?" Wrong.

Cognitive burden is the increased mental effort required to keep track of what is going on. Don't make me think.

Knuth said that our main task is not instructing computers, but explaining humans what a computer does.

Idiomatic code makes your intentions clear. It does not automatically make it correct. It let's others spot mistakes more easily.

Part of it, is staying up to date with changes in the language. Is there are better way to do it, with a new construct from the standard library or an extra package?

You are the most frequent reader of code you write. Have mercy on your future self. He may be a violent psychopath coming back to slap you in the past.