5 ms·
Without wanting to ignite a debate about the walrus operator (and having not read any of the arguments), I can guess why there was one. It's not clear to me wha
by sleavey 7y ago
Without wanting to ignite a debate about the walrus operator (and having not read any of the arguments), I can guess why there was one. It's not clear to me what it does just from reading it, which was always one of Python's beginner-friendlinesses.
- coldtea 7y ago>It's not clear to me what it does just from reading it How isn't it entirely obvious? := is the assignment operator in tons of languages, and there's no reason not to have assignment be an expression (as is also the case in many languages).
- sleavey 7y agoIt's not in a language I've ever used (furthermore, I explicitly mentioned beginners in my comment).
- coldtea 7y agoWell, beginners wont know generators, list comprehensions, asyncio, keyword arguments, and tons of other things either...
- txcwpalpha 7y ago> := is the assignment operator in tons of languages It is? Which ones? Other than Go, I can not think of a single language that has ":=" as an operator. Java does not, JavaScript does not, C/C++ do not, Ruby does not, I don't think PHP does, Erlang/Elixir do not, Rust does not... (I could be wrong on these, but I've personally never seen it in any of these languages and I can't find any mention of it in these languages' docs). I tried looking around the internet at various popular programming languages and the only ones I could find that use ":=" are: Pascal, Haskell (but it's used for something else than what Python uses it for), Perl (also used for something else), and Scala (but in Scala it isn't officially documented and doesn't have an 'official' use case). I don't have a strong opinion about ":=" in Python but I do agree that it's unintuitive and thus not very "Pythonic".
- abraae 7y agoOracle's PL/SQL uses it. I believe it was based on ADA... googles ... Yes ADA uses it as well.
- thestoicattack 7y agoIn Ada, = is equals and := is assignment.
- deleted 7y ago[deleted]
- hathawsh 7y agoSee: https://en.wikipedia.org/wiki/Assignment_(computer_science)#Notation https://en.wikipedia.org/wiki/Assignment_(computer_science)#... At least 18 prominent languages use that syntax.
- txcwpalpha 7y agoThat's more than I was aware of, but I would hardly call 90% of those "prominent". Sorry to any fans of those languages, but I doubt even most people here on HN have even heard about over half of the languages in that ":=" list.
- coldtea 7y agoIf someone is not, not a user, but familiar with ALGOL, Simula, Pascal, Modula, Ada, PL/M, Smalltalk, Eiffel, and Oberon, they should not really promote their programming language ideas as relevant... The fact that they use some "new languages" (e.g. whatever derivative stuff happens to be in fashion atm) and are not even aware of the debt of those languages to the list above, doesn't qualify them...
- Redoubts 7y ago> If someone is not, not a user, but familiar with ALGOL, Simula, Pascal, Modula, Ada, PL/M, Smalltalk, Eiffel, and Oberon, they should not really promote their programming language ideas as relevant... If programming is intellectual onanism for you, then sure you're free to entertain that idea.
- queensnake 7y agoIt looks to me like it could be an assignment to const, or, a copy vs a non-copy - it’s not obvious at all. I’m sure: ‘?=‘ was fought over and rejected, but that’s what I’d have expected conditional assignment to look like.
- xaedes 7y agoIt is not "conditional assignment" tho. It is an assignment which returns the assigned value. You can use it in conditions, but you can also use it elsewhere.