27 Dec 2016
Since I've joined Google, I have been writing Python 2.7 intensely. I've found that the language is ugly. Here are some specific points:
Here's how Python 2.7 calls a super class' method:
class YourClass(BaseClass): def __init__(self): super(YourClass, self).__init__()
YourClass is repeated. This is prone to error. Someday, someone will make a mistake of writing
Python interpreter should have been smart enough to handle
Python interpreter should have been smart enough to figure this out without specifying
self as the first argument. This leads to confusion, in general, and a strange error message:
>>> class T(object): ... def test(self, a): ... print a >>> t = T() >>> t.test('a', 'b') Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: test() takes exactly 2 arguments (3 given)
test(..) is called with 2 arguments, but the error says 3 is given.
For some reason, a dynamic language like Python can't mock
datetime.date. We would get the error like below:
TypeError: can't set attributes of built-in/extension type 'datetime.date'
I am under the impression that Python wants to be terse and expressive. That's what people have been saying about Python. But, a while back, I encountered a problem where I wanted to get the first element of a list or get None. It turns out that there's no satisfied solution to solve this task.
This thread offers like 5 ways of getting first element or None. I have no idea why Python doesn't include a method like this in its standard library.
On this point, I do feel Ruby is much more expressive, terse, and beautiful.