Hacker News new | ask | show | jobs
by pmelendez 4603 days ago
This is my problem with Python: "Rename func_name —> __name__, etc Rename .next() —> .__next__()"

Too many ugly renames, too few alternatives of doing things. To be honest the only attractive thing to me is all the libraries that they support but I don't find the language itself interesting.

4 comments

What do you mean by "ugly renames?" How many times in using Python did you have to look at .__next__() or .func_name ?

I have been using Python full time for the last 7 years and I very rarely have to call either of those function.

> Too few alternatives of doing things.

Can you explain that as well? What do you mean by alternatives of doing things? Like say you want to read a file and you might want to use a wider variety of options when opening the file handle or say you want to parse JSON and you'd like standard library to have more parsers available?

Not having alternatives is python's greatest strength. The language is easy to read because as much as possible there is only one way to write a given concept.
> too few alternatives of doing things

That's what you want for maintainability. I'm not interested in maintaining a codebase where every programmer have their own idea of how something should be done. Of course, you have code reviews for this kind of thing. Except when the code is already written. And when it is not, arguing over minor points is an unnecessary timesink.

__ is basically a namespace for official language extensions. How would you suggest they do it? Prevent "next()" from being a valid method name?
That has been addressed in some many other ways by several languages that goes from the C++ way where you actually have namespaces to the C way where you don't worry about it and pick another name. From all of them I find this the most odd way to address it, specially when python was supposed to improve legibility by design (at least for me those underscores are very distracting)
The underscores are distracting on purpose; any method surrounded by double underscores is one that you're virtually never supposed to explicitly call (there's a builtin `next(foo)` in Python 3, for instance)
Er... they are methods not functions. Tell me how does the C++ way namespace methods within an object?
There's no need to make it not be valid. C++ uses begin() and end() for obtaining iterators to containers, but nothing's stopping you from using those method names for your own purposes.

It's just that if you want to use a few new language niceties like range-based for loops then you'll need to conform to that convention.

In C++ it's fairly common to be calling begin() and end() on containers, where in Python it's not common to call next(), you let the for loop handle it. It's reasonable to rename a function to something ugly when you're never going to be seeing it.
That's the best time, so that people don't think it's a function they should be calling without understanding exactly what they're doing.
> where in Python it's not common to call next()

In fact it should never happen, that's what the `iter` and `next` builtins are for. The only use case for calling __next__ by hand is iffy as hell, it's overloading it while inheriting from an iterator.