Is there a reference of best practices?

We have style guides (and even automatic formatting tools), hlint, and the Haddock standard for comments. These together ensure that Haskell is uniformly good-looking on the level of syntax. We also have a bunch of warnings (some of which are off by default) that catch many blunders, such as incomplete patterns.

However, there are also high level best practices that one really ought to follow in order to take the best advantage of Haskell. Some examples:

  • If you need to acquire a resource and then release it, you should do it with a bracket. (Why?)
  • If you are catching all exceptions, you should re-throw asynchronous ones. (Why?)
  • Whenever you are mapping, folding or unfolding, you should do it with higher order functions. (Why?)
  • Whenever theoretically possible, a type should have exactly the right set of values, so that code is correct by construction. (I think this is the first source?)
  • You should parse, not validate. (I recall the opposite is called «boolean blindness»?)
  • You should know which functions in the standard libraries are safe and easy to understand, and which are dangerous and confusing. (There is some work to codify this.)

These best practices are disparately mentioned here and there. If I forget some of them (and I know I do), there is no way for me to refresh my memory. Further, it is hard to explain to a programmer with a «traditional» background how Haskell is different — it is very much possible to write stringly typed imperative code in Haskell!

How much better life would be if all known best practices were codified!

If there is a reference for this, please link me to it. Otherwise, please throw your best practices in comments and I shall compose that reference from your suggestions and put it on the Internet.

7 Likes

Production Haskell is one such reference of best practices.

1 Like

The old haskell-lang.org site had some good content on this topic, though that has since been moved to the Applied Haskell Syllabus.

Personally, I’d like to see this type of content included in an authoritative guide for onboarding, up to intermediate and recommended reading to become experts. I’d like for that to be community-supported, and hosted on haskell.org.

Before someone says “why don’t you do that”: This is possible/feasible, but agreement among various parties seems to keep blocking that or burning out contributors who push in this direction, so there would need to be a larger group of people working together to make this a reality.

1 Like

Does not seem to be available even for money at this time. (Says will be published some time soon…)

Maybe @parsonsmatt can chime in.

Yeah so, the book was picked up to be published by Manning and as a result Matt took it off of leanpub. According to the project’s twitter, the book very recently finished its first round of reviews and he hopes to get it into the Manning early access program soon. I am very much looking forward to reading it when it comes out but I’m in the group of, I assume quite a few, people who only heard about it after it was picked up by Manning and therefore didn’t get the chance to check out the early versions on leanpub, and am therefore just waiting to hear anything about it. When it comes out I am sure that it will be a great solution to the question this thread is asking but right now I don’t think it’s really a good choice of material to point to, given that nobody new can get access to it for an indeterminate amount of time.

Btw apparently the deal with Manning didn’t work out so Matt put it back up on Leanpub.

There is also a tool called stan that works somewhat like hlint but on the level of meaning, not spelling. It is integrated into haskell-language-server as a plugin since recently.

1 Like