by mpweiher · 9y ago · 0 comments
Q: "Do you hate static types" GB: "No" MF: "No"
GB: "Types are useful for: 1. Doc for human 2. Doc for machine 3. Making things faster … 4. Correctness"
This was experience from the Strongtalk project, which implemented a fast, typed Smalltalk. Strongtalk was purchased by Sun and the tech. was the basis for Java's Hotspot. They actually expected the correctness factor to be much higher, but in practice the static type system only helped to find one or two minor bugs in largely unused code-paths in the libraries. I also find it interesting that "making things faster" is on the list, because the mantra from that part of the discipline has always been that static types do not help for performance, because the JIT will fix it all.
MF: “Research on Types and Soundness smothers research on programming languages”
Clarifying, says something along the lines that you have to figure out more powerful/better language mechanisms first, then later start thinking about how to type them properly.
However, if I can figure out what a method actually returns and click through to it in the IDE, that's the real gain from types for me. Type analysis has to be fast to be able to do that.
My impression of research in academia is that it's disproportionately focused on even stronger types that are even harder to compute. Not everyone builds spaceships.
research in academia is that
it's disproportionately focused
on even stronger types that are
even harder to compute.
Type inference for simple types in sequential computation is a solved problem, Milner and Damas showed how to do it in [1] in 1982. However, most extensions of Damas/Milner cross from decidable type inference to undecidability, so some annotation is often necessary, e.g. Scala, Rust, Haskell (kinding).Most work on expressive typing systems (e.g. dependent types) has a different aim, namely using types for the verification of arbitrary program properties. This is undecidable, but we want (and need) as much automation as possible to lower the cost of verification, whence a lot of research is about partially automated type inference for very expressive typing systems. For most standard front-end dev, verification is not an issue since
- the field has fairly low correctness requirements that can easily achieved with testing
- typically you don't have strong specifications to verify against. No formal spec, no verification.
[1] L. Damas, R. Milner: Principal type-schemes for functional programs, http://web.cs.wpi.edu/~cs4536/c12/milner-damas_principal_typ...
Indeed over the weekend I was able to design and build a GUI DSL, layout system, model-view databinding, command event system, and serialisation/deserialisation logic for a side project of mine. This sort of stuff would have taken weeks of effort in a static language.
However, I don't see why this would be true:
> This sort of stuff would have taken weeks of effort in a static language.
I've also written plenty of things in typed languages, and in many ways they can be faster to develop in than dynamic languages. Of course, you do need to change the way you program a bit to really take advantage of types.
I think the main advantage Clojure has over most typed languages is macros, but there is work being done to rectify even that.
For you, maybe. For someone familiar with that static language? They might have gone faster.
Productivity in a language is highly subjective so it shouldn't come into the equation if you're trying to compare statically and dynamically typed languages.
Also, a frequent problem I have in JS and Python is that they don't scale very well; type documentation must be updated manually and inevitably becomes incorrect with time; determining the type of a return is always a matter of extensive grepping, etc. With most statically typed languages, the IDE can tell you this right away, but in the worst case you just look at the function signature; does Clojure have a solution for this problem?
1. It is a Lisp: The only type is the 'list', and in Clojure you also have 'maps' too (basically a dictionary in JS). That's it. Any object in JS is a map in Clojure, which keeps everything nice and simple. The main power of this is you only ever need to support lists or maps in your functions, and then your functions work for every data structure you ever create! For example clojure.core ships with 'get-in' 'assoc-in', 'diff' etc, all functions that work on your structures no matter how complex.
2. It is a functional language: JS is imperative, meaning you have to fit your ideas to the language, breaking everything down into for loops and if statements. With Clojure you fit the language to the idea, and think in data transformations instead. Then you create a set of functions that deal with that problem specifically, all wrapped up in single namespace. For example a 'tilemap' ns that contains a set of functions for converting to/from screen and grid coordinates. Or getting the neighbours of a specified tile from the 2d array. The end result is a custom DSL that reads almost like English.
3. It is 'immutable by default': All data structures are persistent. The problems you have with scaling in JS and Python is all because of mutable local and global state, as it becomes very difficult to know what is changing what. Clojure doesn't have this problem, as values can't be edited, only new ones returned. There is still mutability of course, but it is restricted to maybe 10 locations in your codebase. The mental burden this lifts from your shoulders cannot be understated.
4. It has a REPL: Let me ask how much effort you think building a HTML editor is? Or the UI designer in Visual Studio? With Clojure, I can just make edits to the GUI code on the fly and press F10 and voila the changes appear in-app. Instant editor, for free. This is what i was doing the other day; editing my GUI code (re-arranging controls, changing positions and sizes) and then immediately inspecting the result in the running program. The productivity gains are huge when you remove the laborious 'write code, wait for build, navigate to place in the app, finally test your changes, find error, end program, change code, repeat' cycle from your workflow.
5. Macros: Lisp macros are just Lisp code again. Literally the whole language available to you at compile time. The clojure.async library for example uses this to provide Go style channels for async programming. It means you can write code that looks great, and still compiles down to something performant at the end.
[1] https://sites.google.com/site/stefanhanenberg/
[EDIT] Clarified which effect
Which effect, sorry? I can't identify the referent of "That".
That sounds like the global optimum of what I want in a language.
> They actually expected the correctness factor to be much higher, but in practice the static type system only helped to find one or two minor bugs in largely unused code-paths in the libraries.
Maybe these were already mature, well tested libraries?
I'd love to see them pitted against each other on many types of programming problems with same tooling and similarly-skilled developers. I want to know what differences there would be on large programs in terms of productivity, defect introduction, defect removal, and maintenance-level changes.
because the JIT will fix it
This has not been borne out in practise. Moreover JITs are much more complicated and hence expensive to develop to maturity than standard AOTs.Exactly. http://blog.metaobject.com/2015/10/jitterdammerung.html
The type system is a convenient way to express memory layout. Java is a bad example, because it intentionally hides the memory layout. You could use other means than the type system, but I don't know any examples off the top of my head. Maybe some Python meta class magic?
Perhaps, but you could turn it around, too.
Statically typed languages had time to catch up because innovation into "more powerful/better language mechanisms" has stalled, for some other reasons.
innovation into "more powerful/better
language mechanisms" has stalled, for
some other reasons.
For sequential languages there is probably not much to improve -- except at the edges. ML nailed it. Almost all core PL research today is about- verification
- concurrency/parallelism
because both are beset with deep unsolved problems: for verification the problem is how to do it efficiently (we know we can do it in principle), and for concurrency/parallelism we have not yet discovered core abstractions including the right types that can express simple properties of concurrency/parallelism (at least that is my working hypothesis). This is intimately related to our current inability to auto-parallelise.
And that's the problem right there. There is sooo much that is out of whack with programming, even sequential.
For starters look up 'architectural mismatch'.
So, there's not so much a problem in programming languages with architecture so much as programmers ignoring proven ways of catching such problems. Usually what I just mentioned plus review and testing. People like hwayne are laying groundwork for reductions in this problem by making accessible tutorials showing practical value of such techniques.
Then why does Haskell exist? And if Haskell nailed it, why does the Backpack module system exist?
Clearly, nobody has "nailed it".
They're especially useful when you are writing libraries for use by somebody else.
1. Correctness of the code
2. Correctness of automatic refactorings, which dynamically typed languages can never achieve, which is why refactoring a dynamically typed language always requires the supervision of a human