News for hackers. Stuff that matters.
Re:What is Gradual Typing by varav on Wednesday November 12, 2014 @03:55AM (#8594572)
The `add1` method should be declared static
Re:What is Gradual Typing by chriswarbo on Wednesday November 12, 2014 @05:59AM (#8594847)
`add1` isn't a method, it's a function.

Besides, "static methods" are a hack:

If it's a behaviour of the class rather than its instances, then make it a method of the class. You'd only need static methods for this if your language doesn't treat classes as objects (ie. it's not a particularly OO language). The example is in Python, where classes are objects, so no statics are needed.

Alternatively, it may be a completely standalone piece of code, in which case it has no business being inside a class. Just make it a standalone function, and stick it in a module to avoid name clashes. You'd only need static methods for this if your language doesn't allow standalone functions, or doesn't have a module system. Since Python has both, there's no need to abuse classes like that.

Re:What is Gradual Typing by varav on Wednesday November 12, 2014 @06:07AM (#8594874)
Please read the article. I was referring to the method in the Java example. You cannot access `add1` from main since main is static
Re:What is Gradual Typing by chriswarbo on Wednesday November 12, 2014 @11:24AM (#8596308)
Ah yes, I replied too soon :)

Still, it's just a Java quirk that's irrelevant to the article.

Re:What is Gradual Typing by the_af on Wednesday November 12, 2014 @07:49AM (#8595189)
The add1 method was declared non static on purpose, to illustrate static type checking.
Re:What is Gradual Typing by shawabawa3 on Wednesday November 12, 2014 @09:31AM (#8595525)
No it wasn't.

Even if the type checker passed the compilation would fail because it's trying to call a non static method from a static method

Re:What is Gradual Typing by the_af on Wednesday November 12, 2014 @10:08AM (#8595730)
Oh, you're right, it's unintended. I didn't see the author tried to trigger a type-check error with an argument "a" of the wrong type.

However, failing compilation because you're calling a non-static method from a static context is also a kind of static checking, so the author's example still works, just in unintented ways.