or: “5569 Things You Can Learn About Python From This Guy On The Internet”
I like programming in Python, and sometimes (not more than a few times an hour) I get stuck and google my problem. When I do this it is very common to have Stack Overflow be the most useful result, and then it’s very common for some guy called Alex Martelli to have answered the question clearly and provided deeper insight into the whole area. Some examples:
What’s the difference between __repr__ and __str__ ?
Queues are awesome
Here’s his profile on Stack Overflow.
Here’s all of his answers.
It doesn’t take long following the links in his profile to find out that he wrote Python in a Nutshell and more recently cowrote Python Cookbook, works at Google, and had the Zen of Python read at his wedding. So well enough credentialed to tell us how to write Python I would say.
Explanation that there is no such thing as compiled vs interpreted and what do you mean by ‘python’ anyway?
Wherein he says that using True and False as list indices is a perfectly reasonable thing to do:
"""value should be a bool"""
return [‘No’, ‘Yes’][value]
and GVR chimes in to agree with him.
Where he explains that he’d choose a loop to write a list to a file, because why use the memory to materialize the whole list of strings?
Wherein he dispenses some advice from experience.
Queues are great (again), threading is most valuable for IO bound operations.
Windows is a weird OS.
You should know the standard library, especially itertools, collections.
There’s something called contextlib?
Helps you with your AI homework.
Shows you a factory pattern.
And there are many many more answers, more than 5000 in total. But wait! There are more people with things to teach us.
Like Martijn Pieters who is a Plone framework teams member and Plone Metrics Person of the Year 2012. He will:
Show you rsplit.
Show you dis and how to find the source for any bit of python.
Apparently there’s a psutil library? That looks very handy.
Or Greg Hewgill:
Talks about absolute and relative imports.
Or Ignacio Vazquez-Abrams:
A not at all incomprehensible one liner for generating random strings including upper case and digits. (Did you know there was a string module? I guess properly learning the standard library is moving to the top of my todo list.)
There are a lot of tools included in the python standard library.
I like reading Stack Overflow answers because I find the question and answer format puts information in my head with less friction than reading the docs. Something about there being a problem solved succinctly lets my brain engage with the information well. It’s also a less formal form than documentation so you get fun asides; example code snippets; backtracking and correcting mistakes. It’s much more human which makes it feel more accessible. It is broad, rather than deep, and the random seeming nature leads you to discovery, and also patterns across topics (learning the standard library more deeply seems like a good thing.)
And it goes perhaps without saying that learning more than you already know about your programming languages is a good thing. To think that you know it all, or you know enough to do what you do is a trap leading to stagnation. Becoming expert at your tools is a time saving, efficiency promoting endeavor, especially when writing code. Better understanding leads to better thought processes leads to better design leads to better software. Which snowballs into less maintenance, faster, more efficient programs, and a better world for everyone to live in.
Alex and others have given us something really amazing and it would be a shame to miss it. Happy reading.
Exploring Dependent Types in Idris
When I'm not coding the "impossible" at Art+Logic, I take a lot of interest in new programming technologies and paradigms; even if they're not yet viable for use in production, there can often be takeaways for improving your everyday code. My current...