Python: as simple as possible but no simpler.

06 June 2009

When coding something in Python, it's said that your logic should be as simple as possible because the language does the heavy lifting for you. The nice thing about Python is that it makes it very easy to implement complex functionality because all the fiddly stuff that you normally spend ages coding and debugging (like linked lists and sorting algorithms) is already done for you. Also, the basic data types/objects that Python gives you are as orthogonal as you can get without throwing your hands up and using sticky notes instead.

In short, I spent two weeks debugging a loop that was supposed to take every sixth, fifth, fourth, and so on entry from a huge list of values that wasn't working and shortened it to zero = data[0::6]. Total time to rip out the loop that wasn't working and replace it with that: three minutes (counting looking it up in my copy of Learning Python).