bestelbus22@lemmy.world to Programmer Humor@lemmy.mlEnglish · 3 days agoThe meaning of thislemmy.mlimagemessage-square67linkfedilinkarrow-up1535arrow-down114
arrow-up1521arrow-down1imageThe meaning of thislemmy.mlbestelbus22@lemmy.world to Programmer Humor@lemmy.mlEnglish · 3 days agomessage-square67linkfedilink
minus-squareWolfLink@sh.itjust.workslinkfedilinkarrow-up43·3 days agoIn Python, self is not a keyword, it’s a conventional variable name. You can replace all instances of “self” with “this” and your code will work the same.
minus-squarejsomae@lemmy.mllinkfedilinkarrow-up6·2 days agoLua might have been a better choice, since self is special in lua.
minus-squareDie Martin Die@sh.itjust.workslinkfedilinkarrow-up4·edit-217 hours agoKinda. Lua defines it implicitly only when you use the function foo:bar(a, b, c) -- note the colon syntactic sugar, which gets translated to function foo.bar(self, a, b, c) -- note the period In all cases, self is a regular variable name. You can even redeclare a new local with that name even when the old one is in scope. Edit: some typos
minus-squarejsomae@lemmy.mllinkfedilinkarrow-up3·2 days agoI don’t see how what you said is inconsistent with me saying “self” is special in lua. Note that I did not say it’s a keyword.
In Python, self is not a keyword, it’s a conventional variable name. You can replace all instances of “self” with “this” and your code will work the same.
Lua might have been a better choice, since
self
is special in lua.Kinda.
Lua defines it implicitly only when you use the
function foo:bar(a, b, c) -- note the colon
syntactic sugar, which gets translated to
function foo.bar(self, a, b, c) -- note the period
In all cases,
self
is a regular variable name. You can even redeclare a new local with that name even when the old one is in scope.Edit: some typos
I don’t see how what you said is inconsistent with me saying “self” is special in lua. Note that I did not say it’s a keyword.
Derp, I misread.
Python is just distancing itself from JS.