The meaning of `this`
The meaning of `this`
The key is to not reassign function names to local variables.
const print = obj.toString print() // gives you a bad time_ (sic) as a variable name is often used when a function returns multiple outputs but you only want one
def my_function return 1, 2, 3 _, two, _ = my_function()_myvariable is typically use to indicate a “private” class variable or method (Python doesn’t have private so it’s just a convention).
_ can also be used in the python interactive terminal to mean ‘last return value’
Ie:
> 'string' 'string' > a = _ > print(a) stringEdit: oops, guess I was mistaken, you can use most Unicode but emojis are not valid.
That actually seems even more arbitrary. Like, do they just hate fun?
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
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, except/catch 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.
self as a keyword also has quite a history. It was already used in Smalltalk, an OOP language from the early 80’s.
Maybe I’m missing something, but:
And switch cases (called match cases) are there as well.
I use lambdas all the time to shovel GTK signal emitions from worker threads into GLib.idle_add in a single line, works as you’d expect.
Previous commenters probably didn’t look at Python in a really long time.
Your All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and more.
Speaking of big cumbersome things with wildly different syntax have you tried a ternary operation in python lately? Omg that thing is ugly. JavaScripts is hard to beat.
uglyTernary = True: if python_syntax == “shit” else: False prettyTernary = javascript_syntax == “pretty” ? true : false
That’s just because you’re used to it. The pythonic ternary is structured like spoken language, which makes it easier to read, especially if you nest them.
Is there an objective argument for the conventional ternary, other than „That’s how we’ve always done it!“?
I don’t read spoken language, but I do read written ones. The problem with python’s ternary is that it puts the condition in the middle, which means you have to visually parse the whole if-block just to see where the condition starts. Which makes it hard to read for anything but the most trivial examples.
The same goes for comprehensions and generators
The conventional ternary is structured like a normal if-else. In fact, in many languages with functional influence, they’re the same thing.
For example, you can write this in Rust:
let vegetable = if 3 > 4 { "Potato" } else { "Tomato" };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.
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.
Absolutely cursed, lol.
So not only did they decide to randomly include Hebrew in their language, because I guess they were feeling kabbalistic, but they got the Hebrew wrong. In what way does any of that increase usability or even make them look competent?
It reminds me of the INTERCAL manual, which was a joke:
This precedence (or lack thereof) may be overruled by grouping expressions between pairs of sparks (’) or rabbit-ears (").
include Hebrew in their language, because I guess they were feeling kabbalistic
... or because the developers were Israeli: https://en.wikipedia.org/wiki/Zend_(company)#History
Python does have a switch statement now, actually. And yes, they went out of their way to call it something different - match.
match isn’t just equivalent to switch though, so in this case it actually makes sense to call it something different.
This is very true. Match statements are much more powerful that switch statements in any other language.
For instance:
List<> or vector (C++ had to be special) and are named appropriately.
vector is an array.My JS:
Ah, you mean that?
Rust: Borrow handler got mad at you for asking
(I’d assume)
&mut self, &self or just self).
Self, the type of self.