Hacker News new | ask | show | jobs
by dfeltey 4701 days ago
I do understand your point, but purity is one of the defining characteristics of Haskell, and one of the features that differentiates it from most other languages, so I think it should be mentioned up front when introducing Haskell.
1 comments

Mention it, maybe, but pointing out how great it is not to have to deal with that messy "real world" is bad marketing. It makes you think "oh, so all these benefits only exist in the magical fairy land and not in the real world where I work?"
I understand what you're saying. It would be better to just talk about the enforced separation between pure code and code with side-effects, and explain that it's possible to structure a normal program so that it's mostly pure.
You are just making a claim though, no one know if it is actually true. Semantic purity doesn't necessarily lead to human clarity, which is one of the mountains Haskell has had to climb: it doesn't seem "easier" or "more simple" than other approaches, only claims of safety might hold up to some scrutiny.
You will note that I make no claims about clarity, only that it is possible to separate pure from impure code in Haskell (which is certainly true).

The problem with Haskell and clarity are, in my experience, twofold:

- large amount of high-level concepts to absorb (though not everything is necessary to start producing code)

- the power of the language is its own worst enemy at times - it is possible to write a pipeline of complex computation with very little work, which leads to less code but less readability (on the other hand, Haskell functions are typically short, which helps a lot with maintaining up-to-date comments)

On the other hand, the separation between pure and impure code is not a complex notion per se, and reasoning about pure code is made much easier.

Right. It is quite easy to build convoluted Haskell code just as it is easy to to build convoluted Java code.

One of my primary complaints about Haskell, however, is that Haskell code is impossible to debug. You can reason about it, the type checkers can check deep properties about it, but it is difficult to actually observe the computer executing it! To me, this is a deal breaker.

> Right. It is quite easy to build convoluted Haskell code just as it is easy to to build convoluted Java code.

I don't think it's quite as easy, but I'll concede the point so I can make the more important point: it is much easier to write clear Haskell code than clear Java code (at least, "clear" as I understand clarity, YMMV).

> You can reason about it, the type checkers can check deep properties about it, but it is difficult to actually observe the computer executing it!

Certainly purity makes it hard to observe, and laziness makes it hard to understand how the program executes. However purity also means that static debugging (e.g. QuickCheck) is far more powerful than in other languages so dynamic debugging (actually watching your running program) is less needed. In fact I do far less debugging in Haskell than in Python, say. I first fight the compiler. When I win, the end result is correct more often in Haskell than in any other language I've ever used.

> To me, this is a deal breaker.

That's fair enough. Everyone has their own preferences. Personally I've never noticed it be a problem.

Disclaimer: I don't write performance sensitive code. I expect performance tuning in Haskell is harder than what I've described above.

You're overstating it. Debugging Haskell code is definitely harder than in other languages.

But it's far from impossible (I use Debug.Trace successfully), and you do it far less often.

So debugging takes 5 times more effort but needs to be done 15 times less than in other languages.

At least that's the deal I'm getting and I don't usually find myself debugging much so it's not a grave concern.

I'd say lack of non nullability or pattern matching are worse show stoppers.

Have you looked into Debug.trace? The type of trace is "String -> a -> a". This is a 'pure' function that 'ignores' the first argument and returns the second unmodified. What actually happens is that the first argument is a String that gets printed to stdout. Furthermore, once you give it the first argument, it is simply the identity function, which allows you to easily place it anywhere in you code.

For example, if you have a function: add x y = x+y, and you wanted to see all of the inputs add gets, you could do: add x y = trace (show (x,y)) $ x+y.

For anyone confused about how such a function is possible in Haskell, not that it is in Debug, and the documentation clearly states that it should only be used for debugging.

EDIT: You could also do traceShow (x,y) $ x+y.

As a day-to-day Haskell programmer I'm happy to say that purity makes it easier to understand the programs that I write. Still, you're welcome to suggest that's an entirely subjective anecdote if you like.
You'd think that an empirical experiment with new programmers could prove the point, or at least provide conclusive evidence.
Personally I wouldn't think that. I think that such things are far too complicated to be amenable to scientific study.
It doesn't say you don't have to deal with 'that messy "real world"'! It is called Real World Haskell after all.
I think it is great "truth in marketing", because going beyond purity requires talking about things like monads, and then they've lost most of their audience anyways.

It is better to lose those not interested in purity early rather than have those uninterested folks become disappointed later.