The meaning of this
The meaning of this
The meaning of this
Partially unrelated to the meme, but I find it almost malicious how some python keywords are named differently from the nearly universal counterpart of other languagues.
This/self, continue/pass, catch/except and they couldn't find a different word for switch so they just didn't implement it.
It's as if the original designers purposefully wanted to be different for the sake of it.
pass and continue are absolutely not equal (pass is a noop, and python has a continue keyword that does what you think), and switch is called match like in many other languages. except is weird though.
"except" is also used in Pascal (or at least the main derivatives of it), but not sure if that's older than its use in Python or not.
I read that self
as a keyword also has quite a history. It was already used in Smalltalk, an OOP language from the early 80's.
PHP naming "::" a Paamayim Nekudotayim is also pretty infamous.
When I'm designing shit, I'm pretty zealous about borrowing terminology from anything even vaguely related to avoid this.
PHP weirdness and inconsintencies never fail to amaze me.
On the bright side, I found my first StackOverflow answer that would fit exactly the same on Linguistic Stack Exchange.
Python does have a switch
statement now, actually. And yes, they went out of their way to call it something different - match
.
https://docs.python.org/3/tutorial/controlflow.html#match-statements
match
isn't just equivalent to switch
though, so in this case it actually makes sense to call it something different.
Iv come to loathe the "pythonic way" because of this. They claim they wanted to make programming easier, but they sure went out of their way to not follow conventions and make it difficult to relearn. For example, for me not having lambdas makes python even more complex to work with. List operations are incredibly easy with map and filter, but they decided lambdas weren't "pythonic" and so we have these big cumbersome things instead with wildly different syntax.
Maybe I'm missing something, but:
If the conventions suck you have to break them. How else can you improve things?
map and filter are almost always inferior to generators and comprehension expressions in terms of readability. If you prefer the former, it’s just because you got used to it, not because it’s better.
List instead of array, dict instead on object (tho it also has objects)
List and Array terminology also bothers me ... Why not just call it an array?
TBF the last two bullet points are verbose descriptions of the thing it means in C++, Java, and Python too. It's just that in JS, "this" can also be used in other places.
But yeah, in practice, every time I write JS I want to throw my hands in the air and shout "this is bullshit", but never know what "this" refers to... :D
Yeah that's fair, though it also discusses that whole prototype thing that JS has going on
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.
Python is just distancing itself from JS.
Lua might have been a better choice, since self
is special in lua.
Kinda.
Lua defines it implicitly only when you use the
lua
function foo:bar(a, b, c) -- note the colon
syntactic sugar, which gets translated to
lua
function foo.bar(self, a, b, c)` -- note the period
In all other 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.
Rust: Borrow handler got mad at you for asking
(I'd assume)
It's either a reference to an object instance, or the instance itself (depending on whether you specified &mut self
, &self
or just self
).
Don't forget Self
, the type of self
.
Sweet dreams are made of this
Alternative image for C: Mr. Incredible: "A PARAMETER IS A PARAMETER!"
My JS:
Ah, you mean that
?
In Python you can use this as a variable name
In Python you can use 🍆 as a variable name.
Edit: oops, guess I was mistaken, you can use most Unicode but emojis are not valid.
You can use anything that doesn't start with a digit or punctuation as a variable name (underscore beginning also allowed) unless it's a keyword.
Not much experience, but quickly learned .bind() in JS after it switched me to window instead of object.
The last bullet point is not really that common anymore.
I was working on a C code base with classes, inheritance, and polymorphism, all done by hands and macros.
Something like
typedef struct s_some_class { void (*method)(this *s_some_class); } t_some_class;
Overall, learning C was the best enabler in my whole career. For instance I was learning Python by tinkering with CPython VM, so when I see these ‘WAT’ quircks I know exactly what’s up.
Interesting, how did they do inheritance? Something like void *super
? Also why not switch to CPP if you wanna do OOP?