CWYAlpha

Just another WordPress.com site

Thought this was cool: programming languages – What are the drawbacks of Python? – Programmers

leave a comment »


Comments: “programming languages – What are the drawbacks of Python? – Programmers”

URL: http://programmers.stackexchange.com/questions/15468/what-are-the-drawbacks-of-python

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 when calling Module.method(x). Taking the functional List example above, why do i have to keep saying List over and over? It should know that it’s a List and 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

Written by cwyalpha

九月 9, 2012 在 1:23 下午

发表在 Uncategorized

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: