4 ms·
__ is basically a namespace for official language extensions. How would you suggest they do it? Prevent "next()" from being a valid method name?
by sillysaurus2 13y ago
__ is basically a namespace for official language extensions. How would you suggest they do it? Prevent "next()" from being a valid method name?
- pmelendez 13y agoThat 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)
- deleted 13y ago[deleted]
- masklinn 13y agoEr... they are methods not functions. Tell me how does the C++ way namespace methods within an object?
- chilldream 13y agoThe 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)
- mhenr18 13y agoThere'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.
- xymostech 13y agoIn 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.
- ceol 13y agoThat'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.
- masklinn 13y ago> 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.