Hacker News new | past | comments | ask | show | jobs | submit login

But why can't the interpreter/compiler implicitly add that argument to each instance method definition? There is no need for the programmer to type it. I understand that self plays also a role in the declaration of class methods but other languages found ways to do without method(self) and still have class methods. Java's static (coming from K&R) or Ruby's def self.method

Anyway, that is the way of Python. A lot of people is happy with that and will never be changed. It's beauty contest matter :-)




> But why can't the interpreter/compiler implicitly...

"Explicit is better than implicit" -- PEP 20

Python was the first language I ever learned and I just took it for granted that you had to manually specify "self" like that. When I see code with implicit self, it reads strangely to me. Like, "Where does 'this' come from? Oh yeah."


Or to quote Matz "No language can be perfect for everyone. I tried to make Ruby perfect for me, but maybe it's not perfect for you. The perfect language for Guido van Rossum is probably Python."

My first serious language was C, which is way more lower level than Python. Still Python has something that reminds me of C. Those wierd __xyz__ methods, looking like what we used sometimes in #define; the useless : instead of some { (I know where the : comes from but it should be deprecated or made optional) and that self, which is the pointer to the C struct we were using to implement OOP in C. It's a strange mix of low and high level constructs, not fully OO and definitely not functional. Being at midway on many axis maybe it's the reason why it appeals so many people: it's a little bit familiar to everybody and this is important for the success of a language. Think of Elixir which was designed to look similar to Ruby, even if they have nothing in common.


In a statically typed language you would have to constantly enter the type of the class as the first parameter.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: