2 ms·
> 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 th
by 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...
- lmm 9y ago> 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). A broad library of standard functions is certainly valuable; working in Java with Stream and CompletableFuture one naturally finds oneself wanting traverse, cataM and dozens of other such helpers. Maybe the ability to abstract over monads is only useful to library authors, but the libraries they produce are then immensely useful for regular programmers. > Monads are equivalent to delimited continuations, but delimited continuations compose more easily Perhaps, but at the cost of completely incomprehensible code. We've known for years or decades that continuation-based style can produce higher-performance code than conventional approaches, but they've seen limited adoption even in high-performance environment; many, perhaps most programmers (myself included) just don't and can't "get" them.
- pron 9y ago> one naturally finds oneself wanting traverse, cataM and dozens of other such helpers. Maybe the ability to abstract over monads is only useful to library authors, but the libraries they produce are then immensely useful for regular programmers. I find libraries that help developers save a few lines of code here and there not worth changing a programming paradigm. By far the biggest boost comes from reuse-in-the-large. I fully agree that languages with such higher-order constructs allow writing more reusable code than classical imperative languages. But "more", in this case, does not translate to big savings and does not justify a change of paradigm. We are deep in diminishing returns territory there, even if pure FP had no disadvantages. But those higher-order constructs do not require a pure language, and could be added to Java/Kotlin once there are no bigger-impact improvements to be made, and if it's judged that their meager contribution justifies adding complexity to the language. Not every added utility automatically translates to "we should do it." Its cost must be weighed as well. Languages like Java/Kotlin choose to be more conservative in the cost/benefit of the features they embrace compared to languages like Scala. > Perhaps, but at the cost of completely incomprehensible code. Quite the opposite. Ordinary imperative code (i.e., blocking threads) is programming with continuations. Continuations are the core abstraction of imperative languages, just as partial functions are the core abstraction of pure-functional ones, and all the core constructs in those languages -- loops, exceptions -- are built to work with them. The complex code you're thinking of is analogous to very complex code that can be achieved with monads. While it could be done, there is no reason to ever do it.