Just another 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”


I find python’s combination of object-oriented this.method() and procedural/functional method(this) syntax very unsettling:

x = [0, 1, 2, 3, 4]

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:

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:


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 function on it! Using the 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:

Written by cwyalpha

九月 9, 2012 在 1:23 下午

发表在 Uncategorized


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

You are commenting using your 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 博主赞过: