Thought this was cool: programming languages – What are the drawbacks of Python? – Programmers
I find python’s combination of object-oriented
this.method() and procedural/functional
method(this) syntax very unsettling:
x = [0, 1, 2, 3, 4] x.count(1) len(x) any(x) x.reverse() reversed(x) x.sort() sorted(x)
This is particularly bad because a large number of the functions (rather than methods) are just dumped into the global namespace: methods relating to lists, strings, numbers, constructors, metaprogramming, all mixed up in one big alphabetically-sorted list.
At the very least, functional languages like F# have all the functions properly namespaced in modules:
List.map(x) List.reversed(x) List.any(x)
So they aren’t all together. Furthermore, this is a standard followed throughout the library, so at least it’s consistent.
I understand the reasons for doing the function vs method thing, but i still think it’s a bad idea to mix them up like this. I would be much happier if the method-syntax was followed, at least for the common operations:
x.count(1) x.len() x.any() x.reverse() x.reversed() x.sort() x.sorted()
Whether the methods are mutating or not, having them as methods on the object has several advantages:
- Single place to look up the “common” operations on a data-type: other libraries/etc. may have other fancy things they can do to the datatypes but the “default” operations are all in the object’s methods.
- No need to keep repeating the
Module.method(x). Taking the functional List example above, why do i have to keep saying
Listover and over? It should know that it’s a
Listand I don’t want to call the
Navigation.map()function on it! Using the
x.map()syntax keeps it DRY and still unambiguous.
And of course it has advantages over the put-everything-in-global-namespace way of doing it. It’s not that the current way is incapable of getting things done. It’s even pretty terse (
len(lst)), since nothing is namespaced! I understand the advantages in using functions (default behavior, etc.) over methods, but I still don’t like it.
It’s just messy. And in big projects, messiness is your worst enemy.
from Hacker News 50: http://programmers.stackexchange.com/questions/15468/what-are-the-drawbacks-of-python?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+hacker-news-feed-50+%28Hacker+News+50%29