1

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?

macabeus
  • 4,156
  • 5
  • 37
  • 66
  • 2
    Is there any special reason for any of the differences between languages? It's just the preferences of the authors. Any language based on C/C++ syntax is going to use `this` but if you're creating your own syntax then you can use whatever you like. In VB it's `Me`. – jmcilhinney Mar 11 '15 at 04:12
  • 1
    A lot of them are conversions rather than standard. Self in python can be changed to anything else, as long as it's the first input argument of member method and return value of constructor. Actually, in some less known-to-be OO languages like Matlab, there are almost equal number of programmers that use "self" or "this", simply because half of them learned "self-style" first and others "this-style" first. – user3528438 Mar 11 '15 at 04:20

2 Answers2

2

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

Community
  • 1
  • 1
DeDee
  • 1,972
  • 21
  • 30
1

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.

JChris
  • 1,638
  • 5
  • 19
  • 37