←back to thread

317 points est | 2 comments | | HN request time: 0s | source
Show context
oooooof ◴[] No.17448560[source]
What is it? The link points to a discussion more deep than I’m willing to read.
replies(10): >>17448567 #>>17448570 #>>17448571 #>>17448572 #>>17448575 #>>17448579 #>>17448584 #>>17448591 #>>17448617 #>>17448638 #
kibibu ◴[] No.17448591[source]
High-level overview: it's an assignment operator that returns its value, similar to C's assignment operator.

The choice of := is to avoid accidentally using assignment where comparison is expected.

replies(2): >>17448770 #>>17453569 #
arketyp ◴[] No.17448770[source]
I feel the colon is unnecessary, especially considering how C deals with this. A plain '=' inside a conditional is already invalid syntax in Python.
replies(2): >>17448792 #>>17448811 #
detaro ◴[] No.17448811[source]
And it's a very well-known source of bugs in C, since it's to close to "==". I don't think new languages adopting that is a good idea.
replies(1): >>17448913 #
1. arketyp ◴[] No.17448913{3}[source]
Sure. But if fidelity to C style was not a concern then I don't see why the '==' syntax was adopted in the first place.
replies(1): >>17450177 #
2. detaro ◴[] No.17450177[source]
== is an incredibly common syntax for equality and stand-alone not a problem. only if you introduce = to expressions too it becomes a risk. (well, you could theoretically accidentally write == for a normal assignment, but that kind of error is caught more easily)