News for hackers. Stuff that matters.
Re:Go Home Swift Compiler, You’re Drunk by msoad on Tuesday April 26, 2016 @07:47PM (#11576722)
I guess this means in large application you should always annotate your types. It should be enforced with a linter.
Re:Go Home Swift Compiler, You’re Drunk by geophile on Wednesday April 27, 2016 @12:54AM (#11577903)
I've been using Swift for a couple of months now. While I appreciate that type inference makes for more concise and cleaner code, it also impedes code comprehension. The absence of explicit types forces me, reading an unfamiliar piece of code, to work harder to figure out the type of each expression. This is especially true for expressions of type Optional<T>.

(But at least each expression has a type. While I love Python and have used it for many years, I don't like the uncertainty about types.)

Re:Go Home Swift Compiler, You’re Drunk by mikeash on Wednesday April 27, 2016 @09:36AM (#11580273)
If you're using Xcode, you can option-click a variable and (if Xcode's indexing is working, which is not a certainty) it'll show you the inferred type for that variable. This can help when looking at some new code and trying to figure out what all the bits really are.
Re:Go Home Swift Compiler, You’re Drunk by geophile on Wednesday April 27, 2016 @02:00PM (#11582860)
Yeah, I know, but it's been unreliable.
Re:Go Home Swift Compiler, You’re Drunk by mpweiher on Wednesday April 27, 2016 @02:53AM (#11578333)
In fact, this documentation effect is the only positive effect of static typing that has actual scientific support, unlike the supposed and oft-claimed safety/correctness benefits.

So while type-inference is a neat idea in theory, maybe it's not such a good idea in practice.

Re:Go Home Swift Compiler, You’re Drunk by geophile on Wednesday April 27, 2016 @02:04PM (#11582903)
I'm not sure why you say the safety/correctness benefits are not real. In a large code base, with multiple developers, it is easy to get someone misusing a function, passing one type when a different one is expected. I know that some people in the python world recommend unit testing to guard against this sort of thing, but to me, that is a poor substitute for static type checking.
Re:Go Home Swift Compiler, You’re Drunk by mikeash on Tuesday April 26, 2016 @08:11PM (#11576890)
Not at all. Most code doesn't suffer from this problem. It's a pathological case.
Re:Go Home Swift Compiler, You’re Drunk by catnaroek on Wednesday April 27, 2016 @01:03AM (#11577933)
The code that triggered this long type inference loop seems pretty normal. It's not like Damas-Milner's pathological case (deeply nested instantiations of type schemas), which is genuinely uncommon.
Re:Go Home Swift Compiler, You’re Drunk by mikeash on Wednesday April 27, 2016 @09:34AM (#11580261)
Nested collection literals aren't very common. It certainly doesn't justify requiring something like `let x = f()` to have a type annotation.