Re:Don’t use C++ auto? Restricting auto is not the best deci...
by maxxxxx on Thursday November 09, 2017 @10:55AM
(#15663407)
I don't know Go. What does := do?
[ Parent
| on HN ]
Re:Don’t use C++ auto? Restricting auto is not the best deci...
by Nvorzula on Thursday November 09, 2017 @11:19AM
(#15663608)
x := some_code_here says "x is a NEW variable whose type is whatever the result of the expression on the right hand side is".
Say we have a function, GetInt64(), which...returns an int64. x := GetInt64() both declares x to be an int64 and places the resulting value of the right hand side into x. If x was already to declared to be an int64, E.G.:
var x int64
x := GetInt64()
Then the compiler complain that x is not new - it has already been declared. In this case you have to omit the colon to remove the fancy "auto" semantics.
var x int64
x = GetInt64()
Re:Don’t use C++ auto? Restricting auto is not the best deci...
by memsom on Monday November 13, 2017 @10:03AM
(#15686915)
That looks a lot like the old Pascal assignment vs equivalence operators. In Pascal (read Delphi) we had '=' for equality and ':=' for assignment. So:
x = 5 <-- a boolean statement, true if x equ 5
x := 5 <-- an assignment of the value 5 to the var x.
TBH, it's only like '=' vs '==' in C like languages. But it's easier to spot errors, as Pascal can never have a valid statement where the two are used in the wrong way.
Re:Don’t use C++ auto? Restricting auto is not the best deci...
by maxxxxx on Thursday November 09, 2017 @11:34AM
(#15663757)
Interesting. Seems I should take a look at Go.