back

by eatonphil·11y ago·view on hn ↗
Replicating class functionality using only closures is mundane? At the very least it's cute.

I didn't realize all beginning Python programmers knew what they could do with closures.

My point is, why have a class syntax at all? It's such a mess, "self" isn't even implicit. You don't even need to declare class methods inside the class. You just have to make sure you pass self to the class method.

This seems very loosely wrapped around what I did. Except class syntax is native. Why? I just really don't care for how sloppy the python class syntax is.

/rant

2 comments
It's mundane because there's nothing special about it. Everyone knows python has dictionaries. Everyone knows python has functional features. Everyone knows you can attach functions as properties of objects.

There's really nothing new or interesting about it. Except maybe for beginners. Which is fine. Nothing wrong with being a beginner. It's just not what I expect to see on the frontpage of HackerNews.

That's almost like someone saying: look wow, 2+2 and 2*2 and 2^2 all return the same result! Sure, amusing when you realize it for the first time, but hardly interesting for anyone but a first grader.

When have you seen this pattern shown in a Python beginners tutorial? ... or anywhere? I have never seen this pattern before and for that reason it is interesting.
Why would it show in beginner tutorials?

It's just not pythonic.

> There should be one-- and preferably only one --obvious way to do it.

Not to mention that the object['field'] syntax is rather annoying.

Self isn't implicit by design. One of the core python philosophies is that explicit is better than implicit.
Then isn't this pattern the epitome of the philosophy?

At some point you trade an api for being explicit. Why isn't memory management explicit in python? I just don't agree with the (seemingly arbitrary) choice of making self explicit. It really does not feel like the "Python" way.

Here's a link from Guido's blog back in '08 why he explains why he rejected a proposal on removing explicit self from the language. I feel he's more qualified to argue this than I.

http://neopythonic.blogspot.com/2008/10/why-explicit-self-ha...