News for hackers. Stuff that matters.
Re:Clojure vs. The Static Typing World by Verdex_3 on Friday October 27, 2017 @10:44AM (#15568828)
The thing about static typing is that there's a lot of research behind it and it's getting better every day. Eventually it will get to the point where it's nearly almost the same as dynamically typed systems, but with type checking (but today is definitely not that day). Checkout liquid types [1]. It's a way to get type inference with nearly dependent types. Cool stuff.

Dynamically typed languages, on the other hand, don't really have that much more research that can even be done with them. Can't do any more research on the type system because there isn't much of one. Really the only thing you can do is introduce language features that are difficult to type in a static system, but at that point you're just giving more theory CS phd students targets of things to find a novel way to type.

That being said, the problem with static type systems is that there is a lot of details that you need to figure out to A) be able to use it and B) be able to avoid the edge cases. You'll eventually need to learn about type theory ... which isn't just one thing. Agda and Idris have incompatible definitions of equality and that has an impact. Are your dependent types intensional or extensional? It matters. And that's just the theory side. Two different type systems with the same theory might have different implementation details that impact the programmer. Are you using ML? Is that an applicative functor or a generative functor? Hey, you're using first class modules, cool. Btw you can't use that with applicative functors, don't ask why it has something to do with complicated type theory stuff that took people years to figure out. Using haskell? Is it GHC or is it some alternative ... because that impacts some type class definitions that are possible.

Eventually the static types are going to win because we'll slowly figure out how to type everything (well, nearly everything) and we'll slowly figure out how to package that power in a way that everybody can understand.

However, in the mean time there is a very real cost to having to learn any given static type system that doesn't exist if you live in a dynamically typed system. Additionally, if you do understand some type theory you can bring over the lessons learned to your dynamic system. You won't get type checks at compile time, but you will get a more disciplined way to produce code.

[1] - http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=029...

Re:Clojure vs. The Static Typing World by keymone on Friday October 27, 2017 @10:53AM (#15568949)
regarding inference - where do you draw a line between "let's fail to infer with an error message because of rigidity of the type system" and "let's be flexible and construct a type that will pass all constrains implied by this part of program"?

> the problem with static type systems is that there is a lot of details that you need to figure out to A) be able to use it and B) be able to avoid the edge cases. You'll eventually need to learn about type theory ... which isn't just one thing. Agda and Idris have incompatible definitions of equality and that has an impact. Are your dependent types intensional or extensional? It matters. And that's just the theory side. Two different type systems with the same theory might have different implementation details that impact the programmer. Are you using ML? Is that an applicative functor or a generative functor? Hey, you're using first class modules, cool. Btw you can't use that with applicative functors, don't ask why it has something to do with complicated type theory stuff that took people years to figure out.

that in itself is one of the best arguments for strong dynamic systems with small set of ground types - if before solving your problem you have to solve the problem of how to type your problem and before that you have to learn man-years worth of category theory.. no thanks.

Re:Clojure vs. The Static Typing World by Verdex_3 on Friday October 27, 2017 @11:21AM (#15569255)
Ideally, the best way to approach a problem is going to be to find the right type to express it. However, sometimes problems in the real world can only be typed with types that are so complicated that you end up with no confidence that you're doing the right thing. Sure it checks at compile time, but you're not convinced that the program is doing the right thing.

In these instances you might as well create a dynamically typed system and see what happens when it meets real life. Yeah it might fail, but the static version was going to fail too. You can save time by not having to worry about what the "proper" type is.

The other side of this is: What do we really want our types to do for us? This isn't always the same thing for everyone. I've created DSLs in a dynamic system that failed in weird places and when I tracked down the reason it was because I was using two functions together that did not agree on the "type" they were passing between themselves. In this instance, type theory wasn't going to help solve my problem, but a quick "typecheck" of the code would have pointed me in the right direction to find a silly mistake. On the other hand, sometimes you can use types to solve your problem. I know it's a bit cliche, but rust is a good example of this. If you want to avoid GC but still want high level programming features and no memory corruption then linear types is one way to achieve that.

Re:Clojure vs. The Static Typing World by tome on Saturday October 28, 2017 @07:30AM (#15574785)
> you have to learn man-years worth of category theory

No you don't. Most of the most prolific Haskell programmers (Don Stewart, Neil Mitchell, Lennart Augustsson, probably SPJ himself) would tell you they don't know any category theory.

Re:Clojure vs. The Static Typing World by dragonwriter on Friday October 27, 2017 @11:25AM (#15569290)
> Dynamically typed languages, on the other hand, don't really have that much more research that can even be done with them.

In the same way that static systems are moving toward something that looks like dynamic typing with static safety, so are dynamic systens via gradual typing and optional static analysis tools. I don't think static or dynamic as we know it now are going to win, the dominant model of the future may well be one where broad inference allows statically verifying most constructs without type annotations, and languages support either allowing and disallowing constructs that aren't verifiable (and maybe even support disabling static analysis entirely, though people who use that option for anything but prototyping will be mocked as unprofessional.)

Re:Clojure vs. The Static Typing World by throwawayjava on Friday October 27, 2017 @10:50AM (#15568900)
I'm not sure I agree that "eventually the static types are going to win". The problem is that a lot of program specifications are possible and even economical to write down, but not at all interesting from a research perspective.

I do agree that "eventually statically checked specifications are going to win", but I'm not sold that those specifications will take the form of (something easily recognizable as) a type theory. (However, neither outcome would surprise me).

Re:Clojure vs. The Static Typing World by hota_mazi on Friday October 27, 2017 @12:29PM (#15569892)
Agree with everything you said except that bit:

> You'll eventually need to learn about type theory ... which isn't just one thing.

I'd say that most Java developers are comfortable with its type system, including the parametric polymorphism that it supports, and most of them probably don't know much about type theory. The same can probably be said of C#.

> we'll slowly figure out how to package that power in a way that everybody can understand.

I think we're already there. Java's generics appeared in 2005, and while there probably was some cultural shock in the Java community in the years that followed, it's safe to say that most of this community can claim to have a reasonable understand of generics in general. The addition of C# and its type system helped disseminate this knowledge further.

Re:Clojure vs. The Static Typing World by ridiculous_fish on Friday October 27, 2017 @11:42AM (#15569485)
Imagine StaticScript: a JavaScript replacement with static types and no dynamic types, that is statically compiled and runs in your browser.

What would it mean for a StaticScript program to typecheck? It doesn't guarantee it will have no type errors. The model you typecheck against may be very different from the runtime truth. Browsers are different and provide different features, and will change after your program is compiled.

Static type checking has a fundamental limitation: it happens too early. The more divergence between the static model and runtime truth, the less useful static typing is. This is a fundamental limitation, a place where static types can never supplant dynamic ones.

Re:Clojure vs. The Static Typing World by dragonwriter on Friday October 27, 2017 @11:48AM (#15569536)
Dynamic types don't help you there either; if the runtime you test on behaves differently than the runtime used at the end, then suddenly your code blows up even if your tests are perfect. (In practice, of course, that's a bigger problem with interpreted than compiled languages, and, while that's a different divide than static/dynamic, it's correlated.)

In any case, your example is one in which static languages are no worse than dynamic ones, so it is not one which prevents static languages from displacing dynamic of they are otherwise superior.

Re:Clojure vs. The Static Typing World by ridiculous_fish on Friday October 27, 2017 @12:18PM (#15569808)
Dynamic types do help in this scenario!

1. When accesses are resolved dynamically, the failure mode is better controlled, e.g. exception instead of buffer overflow.

2. The failure is deferred to the point of execution (instead of e.g. load time). It is easy to omit features that depend on missing runtime support, just arrange for that code to not be executed.

3. Dynamic types allow you to interrogate which interfaces are supported, via reflection.

We see all of this at work in (good) web sites. They gracefully degrade, they can dynamically choose implementations based on what the browser supports, and failures are JS exceptions instead of aborts.

> In practice, of course, that's a bigger problem with interpreted than compiled languages

Why does interpreted vs compiled matter? IMO the key distinction is dynamic linking vs static linking. When you link against code compiled after yours, the less assurance static types give, and the more important dynamic types become.

> static languages are no worse than dynamic ones

The proper comparison is between languages with dynamic types and languages without. TypeScript has both static and dynamic types. If it had no dynamic types, it would not be a viable JS replacement.

Re:Clojure vs. The Static Typing World by dragonwriter on Friday October 27, 2017 @12:44PM (#15570031)
If (as is typically, though not always, the case with dynamically typed languages) you are distributing source rather than compiled code, all the advantage of deferring until the runtime environment is known and making decisions based on what is actually available applies to statically typed languages, as well. Heck, even without that, dynamically linking support libraries specific to the renvironment has been a solution to this issue forever.

Dynamic typing changes a little bit about how the solutions are implemented, but not the difficulty or even the basic logical approach.

Re:Clojure vs. The Static Typing World by jahewson on Friday October 27, 2017 @12:59PM (#15570176)
No they don’t. Everything you describe bone can be done in any language with reflection, such as Java, or even C++with RTTI. No need for any dynamic types in the type system.