4 ms·
You don't have to call it self. You can name the reference whatever you want, this works just as well. Though perhaps it's not as pythonic?
by c22 6y ago
You don't have to call it self. You can name the reference whatever you want, this works just as well. Though perhaps it's not as pythonic?
- freedomben 6y agoI think you are right, but the python guy in me from 10+ years ago has vague memories of people being burned at the stake for such heresy.
- MaxBarraclough 6y agoI hadn't wanted to get into the weeds of Python, but yes. You could use any identifier you want, but breaking with convention in this way is not a wise move. I consider it a mistake on the part of Python to go with self rather than this, but it's a really bad idea to write code that surprises other programmers in that way.
- masklinn 6y ago> I consider it a mistake on the part of Python to go with self rather than this self makes more sense though. And smalltalk used self. And so did (obviously) Self. The most important part is to not use both (which of course is what PHP does).
- m_t 6y agoYeah but to quote stackoverflow: > Use $this to refer to the current object. Use self to refer to the current class. In other words, use $this->member for non-static members, use self::$member for static members. This is a different way of doing things, yes, but it makes sense.