4 ms·
> Even if Haskell dominated Java as a language (which I absolutely don't think it does), I wouldn't consider it worth switching because the bottom-line benefits
by lmm 9y ago
> Even if Haskell dominated Java as a language (which I absolutely don't think it does), I wouldn't consider it worth switching because the bottom-line benefits are too small (if they exist at all), while the tooling and ecosystem (both libraries and hiring) is so lacking that the significant hit would dwarf any gains.
I found these problems were worse when trying to use contracts; since they're not part of standard Java, the tooling and ecosystem doesn't work nicely with them. Automated refactoring in the IDE won't update the annotations properly. You go to use an existing library and find that the published annotations were for a previous version and no longer match the current API, or you can't find which version they go with - or worst of all, they still match the method signatures but are no longer true. And the hiring problem is the same. Ultimately the point I suspect we may have to disagree on is that I'm a lot more confident most Java programmers could learn Haskell than I am that most Java programmers could learn a contract-like approach, because I really think the latter is a much bigger conceptual leap.
> I disagree that FP has any advantage here over most programming languages.
I see programmers in other languages having to go around the language to get these things - e.g. the popularity of annotation-based AOP in Java codebases, and the use of monkeypatching to address similar problems in scripting languages - in a way that doesn't happen in (Haskell-like) FP languages.
> monads are completely meaningless and useless once functions are not how you describe computation. They are very much a formalism-dependent construct.
Be that as it may, I thought we agreed that we frequently do want to do the functions-and-values kind of reasoning about our programs, even if we only do it for the "easy parts".
> Lastly, while I like type systems, I think about the problem not the solution. The problem is cheap specification and verification of simple propeties. Types are not the only way of doing that, and when considering the future of programming, we cannot constrain ourselves to solutions found within a very narrow sub-discipline while ignoring the full body of research.
If there's an adequate solution in that narrow sub-discipline then we can. If the cheapest, most familiar approach works then there's no reason to look at more expensive approaches. Almost all programmers working in the industry have at least some basic familiarity with type systems. I'm not against exploring more radical approaches - that's part of what research is for - but when it comes to advocating something for industrial use, let's be sure we've exhausted the easy options first.
- pron 9y ago> Automated refactoring in the IDE won't update the annotations properly. Right. There are always tradeoffs. > And the hiring problem is the same. I don't think so. A Java programmer can be trained in JML in a day. > Be that as it may, I thought we agreed that we frequently do want to do the functions-and-values kind of reasoning about our programs, even if we only do it for the "easy parts". Sure, but pure "functions" can be reasoned about as functions even in Java. > If there's an adequate solution in that narrow sub-discipline then we can. If the cheapest, most familiar approach works then there's no reason to look at more expensive approaches. It's neither the cheapest nor the most familiar. Virtually no formally verified programs encode correctness properties in types. Contracts are far more common. > I'm not against exploring more radical approaches It's not more radical. If you look at the programs of formal methods conferences, you'll find that the typed-FP approach is in the minority. I think that part of the problem is that some FP people have isolated themselves in a bubble that they sometimes forget how small it is.
- lmm 9y ago> I don't think so. A Java programmer can be trained in JML in a day. This I don't believe, not in the general case. If it were that easy we'd see a lot more people doing it. (And I'm pretty sure I've put more than a day's worth in over the years). > Sure, but pure "functions" can be reasoned about as functions even in Java. It's much harder without monads. You lose the ability to cleanly divide the return value of a function that's composed from smaller functions into two visibly orthogonal aspects that you can provably think separately about, so you have to understand all aspects of what the intermediate values represent at once.
- pron 9y ago> If it were that easy we'd see a lot more people doing it. It is that easy. What is hard isn't knowing JML, but gaining experience with specification in general. This is a skill that is required regardless of formalism (and is actually why Idris and Java+JML, despite being very different, are still much more similar than they are different; same goes for TLA+ and Lean). One of the reasons I would encourage those who are interested in correctness to read Schmidt's overview of abstraction/refinement relations [1] -- which forms the core of possibly the most important idea in all of program analysis: abstract interpretation -- is that it allows one to see type systems, contracts, refinement logics etc. as different expressions of this same core idea; specifically of a Galois connection between different abstraction levels, be they a program and its type, a program and its contract, or different abstraction levels in a formalism like TLA. > It's much harder without monads. But you have monads in Java. In fact, there are many more Java programmers using monads (e.g., Stream and CompletableFuture) than Haskell and Scala programmers using monads combined. What you can't do is abstract over all monads, which is of questionable value even in Haskell (and Java has other ways of abstracting over common patterns). The goal now is to remove the need for monads in Java. Monads are equivalent to delimited continuations, but delimited continuations compose more easily (algebraic effect systems are modeled after them) and they fit much more nicely with imperative constructs like loops and exceptions. Delimited continuations are the monads of imperative programming, and they are coming to Java. [1]: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.16.4564 http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.16.4...