r/dailyprogrammer • 1 3 • Sep 09 '14

[Weekly #10] The Future

Weekly Topic:

Read enough blogs or forums and you can see the future. What trends or topics are coming down the line? Is it a new language? New design? New way to engineer software?

Last Week:

[Weekly #9] (http://www.reddit.com/r/dailyprogrammer/comments/2f6mo2/weekly_9_binary_trees/)

54 Upvotes

45 comments sorted by

View all comments

Show parent comment

2

u/continuational Sep 18 '14

Well, having to express the effects in the type of a function makes you think twice before using effects in the first place, because of the extra work involved. On top of that, global state isn't really possible at all in Haskell (except via the FFI). So most Haskell code is separated into a relatively small part that uses IO, and a much larger part that is pure, or uses specific effects internally (many effects in Haskell can be used locally while maintaining a pure interface externally). The types are often sufficient documentation on their own (specifications, whereas tests are examples - usually you'd want both of course).

1

u/akkartik Sep 18 '14 edited Sep 18 '14

Yeah, that makes sense. But I want to reiterate my point about scenarios. They aren't just examples. They're a kind of "showing your work" that I wish we programmers were better about in the real world.

Haskell's type system encourages one to think clearly about classes of things and make universally quantified statements about them. That is good when people do it, but in my experience most programmers aren't very good about doing it. I struggle with generalizations myself. Even when I make a generalization in my code, I find it valuable to record for myself the specific instances I've tried/thought about.

No matter how much you educate us poor sods, I suspect you won't be able to get us to write code strong enough that it needs just a type system to prove correct. In fact, I suspect there are messy spaces in which enumerating the special-cases is less work and easier to understand than describing all the different regimes. Especially when you include real-world considerations like performance, fault-tolerance, concurrency, etc. If you make a change to your haskell program that makes it go faster and someone later undoes it or compromises the performance gains, how would the type-checker catch that?

2

u/continuational Sep 19 '14

No matter how much you educate us poor sods,

Hey, I'm out there writing code for food like the vast majority. I'm stuck with Scala and pine for Haskell. I think people are often scared away from Haskell because of all the math-lingo you can encounter. I still struggle with understanding things like "profunctor" etc., and building an intuition about these things indeed requires examples. I do think there's much to be gained by borrowing abstractions from a field whose very purpose is to understand & define them.

I don't think there is any widespread language that includes performance in its type system. However, Haskell has Criterion for benchmarking as well as excellent thread-aware profiling. It's also possible to build embedded languages for performance-critical code that are limited in such a way that performance characteristics are straightforward.

The breath of high-quality concurrency & parallelism libraries available for Haskell is unparalleled in any other language. The types do help you a lot here - for example, you know what part of the code is concurrent and you're prevented from trying to do side effects within a STM transaction. And you know that all your pure code is just simply correct, regardless of concurrency.

I think types buys us a lot. Testing is fine too, and can improve the quality of your code, but it's not a substitute.