5 ms·
It's to avoid typos. Imagine there is no colon. When you type foo = 3 fooo = foo + 1 Did you mean to create a new variable called `fooo` or was it a t
by sacado2 7y ago
It's to avoid typos. Imagine there is no colon. When you type
foo = 3
fooo = foo + 1
Did you mean to create a new variable called `fooo` or was it a typo? Did you mean this:
foo := 3
fooo = foo + 1 // oops, typo found at compile-time
or that:
foo := 3
fooo := foo + 1 // Yep, new var, everything is ok
- philliphaydon 7y agoWhy not just have var foo = 1
- deleted 7y ago[deleted]
- masklinn 7y agoThat works actually. The weirdness is that ":=" allows redeclaration (within a scope) but only partial, whereas `var` completely forbids redeclaration. That is: var a, b = f() var a, b = f() // NO var a, b = f() a, b := f() // NO // note that the second declaration only partially overlaps with the first var a, b = f() var a, c = f() // NO var a, b = f() a, c := f() // yes