3 ms·
Python is my favorite language, but I think that explicitly having to pass self to methods was a huge mistake. It's a gotcha that catches even experienced progr
by overgard 12y ago
Python is my favorite language, but I think that explicitly having to pass self to methods was a huge mistake. It's a gotcha that catches even experienced programmers, the error message is confusing and unhelpful, it's verbose, and the one case it allows (calling the class directly instead of the instance?) is not generally that useful. It makes some metaprogramming stuff slightly cleaner sometimes, but that's not a great justification.
- esailija 12y agoWell look at JavaScript where self (this) works exactly the same way (it's conceptually just another argument to a function) but is passed implicitly and declared as parameter implicitly. People are not very happy with that either...
- overgard 12y agoThe problem with javascript's "this" isn't that it's implicit, it's that it acts in a surprising way because of the prototype-based type system. Normally you wouldn't expect a closure inside a method to introduce a new "this" variable, but in javascript it does. Other languages with an implicit "this" variable don't have that issue. In a language with a more traditional type system it's not really a problem.
- aardvark179 12y agoMaking this an explicit argument would remove that ambiguity, and JS isn't the only language to have done things that way, and to have throughly confused people by doing so.
- agumonkey 12y agoThe asymmetry in python signature is the confusing part at first, you call a method with N arguments, but the error will complain about N+1 passed.