In some languages, like Python, we use self
, but in other languages such as Java, we use this
.
Is there any special reason for this difference in name for the same function?
In some languages, like Python, we use self
, but in other languages such as Java, we use this
.
Is there any special reason for this difference in name for the same function?
This may not be an answer to its full extent.
In PHP self
is used in static
class methods while $this
refers to instantiated object of a non-static class.
EDIT: In java this
similarly to PHP refers to current object. As for python this answer seems to explain self
very well: https://stackoverflow.com/a/2709832/4490187
There is nothing special about the name self
. It's the name preferred by convention by Pythonistas.
The same goes for Java this
, nothing special, just the name chosen by convention.