Python is a very inelegant language. Here are some things I dislike.
# 1. Clunky lambda syntax | |
numbers = [1, 2, 3] | |
# don't do this... | |
doubled = list(map(lambda n: n * 2, numbers)) | |
# There's no way to define the end of the block except that comma. What about wrapping lines? | |
# better for this case | |
doubled = [n * 2 for n in numbers] | |
# 2. Confusing ways to call base method | |
def do_something(self): | |
super(MyClass, self).do_something() # MyClass not ParentClass | |
super().do_something() # is the same I think??? | |
# you can call it on self if it's not overridden | |
# shouldn't this just be super() ??? | |
# 3. Import abbreviation inconsistency | |
import numpy as np | |
# it's 5 letters, why does everybody abbreviate!!! | |
# ALSO: WHY DO I HAVE TO IMPORT EVERYTHING ALL THE TIME?? | |
# 4. confusing magic functions len() __len__, str(), __len__ what are the other ones? I DON'T KNOW. | |
# Why can not do | |
[1,2,3].length() | |
# There are a handful of magic global functions (like len) that depend | |
# on an internal definition of the correct format | |
# it's an OO language, why doesn't list implement .length()?? | |
# 5. libraries that use camel case (unitest setUp) | |
# More inconsistencies | |
# 6. Why must self be passed to every instance method? It's inside a class | |
class MyClass: | |
def member_method(self): # WTF! | |
# 6b. This is minor, but many @classmethods could probably be @staticmethods | |
>>> class Foo: | |
... @classmethod | |
... def bar(cls, **kwargs): | |
... print(kwargs) | |
... | |
>>> Foo.bar(1) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
TypeError: bar() takes 1 positional argument but 2 were given | |
# 7. similiarly, why must we use @staticmethod decorators to declare static methods? | |
# (it’s like OO was an afterthought) | |
# 8. Can’t initialize a dictionary with symbolized keys like you can in Javascript and Ruby | |
d = { a: "b" } # will evaluate a as if it is a variable | |
# in ruby, you can d = { key: value } where key is converted to the symbol "key" | |
# 9. Tuple initialization makes me want to cry | |
(1) != (1,) | |
# oh, and by the way you don't need parens | |
t = 1, # hanging comma same as t = (1,) | |
# and yet you can't do... | |
tuple(1) | |
This comment has been minimized.
This comment has been minimized.
also: "inheritance" in python -- super() only returns a proxy object, which doesn't support __set__ -- so you can't use property setters from descendents |
This comment has been minimized.
This comment has been minimized.
See also https://github.com/quantifiedcode/python-anti-patterns (via @robmcdan) |
This comment has been minimized.
This comment has been minimized.
@robmcdan Multiline anonymous functions are unnessecary. Just define a function before you die of the horrible code stench that will inevitably rise when you have tons of multiline lambdas instead of functions. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
and also no multi-line anonymous functions, not for good reasons but "just because"🤔