News for hackers. Stuff that matters.
Re:Dynamic Languages Are Static Languages (2011) by snissn on Wednesday July 22, 2015 @06:58PM (#9932912)
For me the big difference between dynamic and statically typed languages is catching bugs like:

    foo = bar()
    if foo:
      fooo = baz()
in a static language, you'd have to write int foo = and the third line where you have an assignment fooo would be caught by the compiler. Of course there's advantages to dynamic languages, like being able to write something like

    mydata = {}
    mydata['foo'] = {}
    mydata['foo']['bar'] = MyObject()
without a lot of boilerplate
Re:Dynamic Languages Are Static Languages (2011) by niccaluim on Wednesday July 22, 2015 @07:08PM (#9932961)
I don't think your example has much to do with typing. The types of foo and fooo can be inferred from the return types of bar and baz, so in a language that supports type inference (e.g. Scala), no annotations are necessary.

As for whether "fooo" is a valid symbol, whether you can declare a variable without a keyword is unrelated to the type system. See, e.g., Go, which has different operators for declaration-with-assignment and reassignment (:= vs. =), but this is merely a syntactical safety net, not an outright necessity.

Re:Dynamic Languages Are Static Languages (2011) by gorena on Wednesday July 22, 2015 @07:06PM (#9932953)
In the first case, any sane static language will use type inference, so you won't have to write out "int foo", just "let foo" or equivalent. (I'd also argue that any sane static language would disallow or at least heavily discourage mutable variables, but that's neither here nor here).

The second case is easily handled by static languages, for example, in Swift:

    var mydata = ["foo": Dictionary<String, MyObject>()]
    mydata["foo"]["bar"] = MyObject()
This is only longer than it needs to be because of using two lines, you wouldn't need the explicit declaration to do it in one:

    let mydata = ["foo": ["bar": MyObject()]]
This also gets rid of mutable state!
Re:Dynamic Languages Are Static Languages (2011) by SomeCallMeTim on Wednesday July 22, 2015 @07:06PM (#9932948)
That's what linting is good for, at least in JavaScript where you have optional "var" declarations: You can set jshint to flag as an error any assignment that isn't part of a "var" declaration (or any reference that isn't explicitly defined), which will catch (at compile time) any variable name typos.

It won't catch this.fooo, though, so it's only a partial solution. My editor has great completion, though, so as long as the string is IN the file somewhere, I usually autocomplete it. Way fewer typos that way.

I see there's a PyLint, so MAYBE it has a way of spotting typos like the one you cite? Not sure how it would work in Python, though, other than on variable reads.

Re:Dynamic Languages Are Static Languages (2011) by dllthomas on Wednesday July 22, 2015 @07:47PM (#9933116)
Certianly lint handles this. Some lint checks are quite reasonably considered type constraints, even if they historically have been implemented seperately. In particular, uninitialized values and unused variables seem very much in the same theoretical space as linear types.
Re:Dynamic Languages Are Static Languages (2011) by marcosdumay on Wednesday July 22, 2015 @07:06PM (#9932951)
Static typing has no relation to explicit declaration of variables.
Re:Dynamic Languages Are Static Languages (2011) by chc on Wednesday July 22, 2015 @07:06PM (#9932947)
That's not really a difference between dynamic and statically typed languages — what makes the difference here is having different syntax for variable declaration and assignment. It so happens that most dynamic languages use the same syntax for both, but there's nothing about separating the two that requires static typing. For example, strict mode JavaScript is a dynamic language that can detect this error, because JavaScript uses var to declare variables.
Re:Dynamic Languages Are Static Languages (2011) by hayksaakian on Wednesday July 22, 2015 @07:03PM (#9932938)
thanks to tab completion i virtually never run into this bug in javascript or ruby
Re:Dynamic Languages Are Static Languages (2011) by snissn on Wednesday July 22, 2015 @07:06PM (#9932950)
could you share what editor and what, if any, plugins you're using?
Re:Dynamic Languages Are Static Languages (2011) by hayksaakian on Thursday July 23, 2015 @04:21AM (#9934569)
sublime text 3, out of the box.

the only plugin i have is ES6/Babel syntax highlighting.

it mostly "just works"