4 ms·
Yes, there is. If x = 1 Has been the source of many errors in many languages. Forcing assignment to be more than a 1 character difference from the equalit
by jimktrains2 7y ago
Yes, there is.
If x = 1
Has been the source of many errors in many languages. Forcing assignment to be more than a 1 character difference from the equality operator prevents this.
- jorams 7y agoI may be missing something, but := is still only a 1 character difference, isn't it?
- chungy 7y ago:= is basically the "yes, I really mean it" version, whereas bare = might just be a simple typo.
- chrisshroba 7y agoIt is, but many intro programmers (and non-intro programmers!) often forget to use == instead of = for comparison, because in the real world, = more often implies equality, rather than assignment. So a novice might mistakenly type `if x=1:` but they would be unlikely to accidentally type `if x:=1:`.
- madhadron 7y agoMakes you wonder why we switched from = is equality and := is assignment like it was in the ALGOL family.
- jimktrains2 7y agoI should have said single-character additions or deletions . == And = have a levenstein distance of 1, == and := is 2. You can't simply make a typo and change an equality check to assignment. So, wiki defines levenstein distance as including substitution, but I was taught or at least remember it only being additions and deletions?
- ulucs 7y agoIt's the same topology as long as string lengths are equal
- dragonwriter 7y agoIt depends on the definition of edit distance used; they both have a unweighted Levenshtein distance of 1 from “==” (# of inserts, deletions, or substitions), but “:=” has an LCS distance of 2 vs “=” with 1. Perhaps more importantly, “=” and “==” are more visually similar than “==” and “:=” and also easier to mistakenly type for each other.