News for hackers. Stuff that matters.
Re:Crystal: the programming language by gagege on Tuesday November 25, 2014 @02:20PM (#8659182)
I'm no language designer either, but I would guess that since Crystal wants to be 100% type inferred, they feel that having to type "var" or "let" is just boilerplate.
Re:Crystal: the programming language by axiomabsolute on Tuesday November 25, 2014 @02:47PM (#8659331)
Even in type inferred languages they serve some use, namely in avoiding mis-typed variable names. Languages which require "var" make a distinction between the intent of declaring a new variable vs setting the value of an existing variable, and so are able to catch instances where the programmer tries to set a non-existent variable.
Re:Crystal: the programming language by vorg on Tuesday November 25, 2014 @11:05PM (#8661072)
Or more tersely use := and = to distinguish them.
Re:Crystal: the programming language by eudox on Tuesday November 25, 2014 @02:33PM (#8659262)
That has nothing to do with the scoping. There's no way to know whether "left = right" means "Set 'left' to 'right'" or "Create a new variable 'left', with value 'right'".
Re:Crystal: the programming language by Igglyboo on Tuesday November 25, 2014 @02:35PM (#8659277)
How are they different? Both produce the same end result, Python manages this syntax just fine.
Re:Crystal: the programming language by exogen on Tuesday November 25, 2014 @02:52PM (#8659361)
"Just fine" is papering over the fact that people get tripped up by this in Python all the time – sometimes you need to use the `global` or `nonlocal` statements to resolve the ambiguity.

https://docs.python.org/3/reference/simple_stmts.html#global

https://docs.python.org/3/reference/simple_stmts.html#nonloc...

Classic example: http://stackoverflow.com/questions/9264763/unboundlocalerror...

If you search for UnboundLocalError on StackOverflow, there are 918 results. Not all of them are due to this particular scoping ambiguity, but many of them are.

Re:Crystal: the programming language by lmm on Tuesday November 25, 2014 @03:03PM (#8659399)
It's a mistake even in Python. It makes typos harder to catch. And a visible distinction between variables that change and values that don't makes code much easier to reason about.