Python WTF

Python is actually a pretty decent language, but from a design perspective, it’s fucked. Ok fucked is a bit strong, but Python could have been much neater and more concise if a little good design had been applied.

Take a look at this very small, very simple bit of code (a Sublime Text 3 example plugin).

import sublime
import sublime_plugin

class ExampleCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.insert(edit, 0, "Hello, World!")

It is certainly a trivial example and with so little code, there’s not much scope in which to find design issues.

Hold my beer.

Let’s start with the import declaratives. Not identifying the module with text means that it’s difficult to do so dynamically. Maybe Python thought of a way around this and you can actually import modules without knowing their names at the time of writing the code. But if they did, they missed the point. It could have been much simpler, just specify the module name as a string.

Then the class definition. Looks like the class is defined as a function of f(x), its superclass. Doesn’t seem very OO now does it?

Then the def run(self, edit):

Really, do we have to pass in self every fucking time? How about just make it an implicit part of the scope of the function’s code? And the :, that seems redundant too. What’s the indenting for?