4 ms·
> Since pure code has no dealings with the outside world, and the data it works with is never modified, the kinds of nasty surprise in which one piece of code i
by davidw 13y ago
> Since pure code has no dealings with the outside world, and the data it works with is never modified, the kinds of nasty surprise in which one piece of code invisibly corrupts data used by another are very rare.
If you're trying to sell me on Haskell, right there you just made me think "uh, ok, guys, but my code does not live in an ivory tower, and very much needs to deal with the real world, messy data, users, and so on".
I realize that Haskell can handle that, too, but in terms of copy writing, it leaves something to be desired.
They subsequently go on to write much more interesting reasons why you might consider Haskell, including examples of companies using it in the real world, but they should not lead with talk of 'purity'.
- dfeltey 13y agoI 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.
- davidw 13y agoMention 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?"
- seanmcdirmid 13y agoI 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.
- mercurial 13y agoI 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.
- seanmcdirmid 13y agoYou 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.
- tome 13y agoAs 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.
- seanmcdirmid 13y agoYou'd think that an empirical experiment with new programmers could prove the point, or at least provide conclusive evidence.
- tome 13y agoPersonally I wouldn't think that. I think that such things are far too complicated to be amenable to scientific study.
- seanmcdirmid 13y agoI would normally agree, but specific usability claims are being made continuously about the benefits of purity, while many programmers think of Haskell has being anything but.
- mercurial 13y agoYou 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.
- tome 13y agoIt doesn't say you don't have to deal with 'that messy "real world"'! It is called Real World Haskell after all.
- mbrock 13y agoI think it's important to emphasize that while Haskell provides purity, it also enables the definition of impure code in a clear and distinct way, the idea being to encourage a clean "separation of concerns" between logic and interaction. It's not really that Haskell removes impurity, more that it adds purity. The "main" function of any Haskell application is an IO action, but you can define pure functions which relinquish IO and global state. And the best practices include doing that as much as possible, which is a terrific way of making your program more comprehensible and correct.
- _delirium 13y agoI wonder if it would be possible to develop an idiom for programming in a language like C that separated those concerns. Put most/all application logic into const/pure functions, and then have a separate set of interaction functions, i.e. just pull out that one bit of Haskell philosophy from the rest of the language design. Speculative guesses as to what might stand in the way: 1. The lack of a purity-tracking mechanism like Haskell's may make programming in this style in C more complex and error-prone. 2. The fact that C compilers don't expect you to use this programming style may mean they don't optimize common operations in the way Haskell does; for example, if you do manipulations on large arrays in a functional rather than imperative style, Haskell will optimize away a lot of the temporary arrays, but C compilers may not.
- tome 13y agoAbsolutely it would, but it's much easier with a type system to guide you.
- _pmf_ 13y agoGCC's pure and const function attributes pretty much allow for these optimizations.
- _delirium 13y agoFor scalar types I agree, but now that I think of it, I'm not sure it's even possible to write array code using them, unless I'm missing something. If you can't modify the array in-place or write to a provided "output" parameter, and you can't malloc a fresh array to return (because that's a side effect), how do you write a pure function of type int[] -> int[] at all? The nice thing about Haskell is that it conceptually mallocs a fresh array to return, but then optimizes away the intermediate array in a lot of cases.
- wunki 13y agoThe power of Haskell is that it acknowledges the fact that it's a messy world and deals with it with the help of Monads. You could turn it around and say that non-haskell programs live in an ivory tower and ignore the messy world below :)
- davidw 13y ago> it's a messy world and deals with it with the help of Monads. So someone has a tough problem dealing with the messy real world, and then you tell him to use Monads. Now he has two problems :-) Ok, I'm kidding, but mbrock's answer is a lot better in terms of selling the language in that it mentions something that anyone can figure out is a good idea, without getting into the details of it. > encourage a clean "separation of concerns" between logic and interaction.
- aristidb 13y agoI downvoted you because you're putting Monads on a pedestal and misrepresenting their purpose. When you mean IO (or perhaps ST and State) please don't say "Monads". Remember that [] is an instance of Monad too, and it has nothing at all to do with dealing with the messy world. A monad is just a typeclass with two operators that behave according to certain identity and associativity laws, and a _lot_ of types fulfil them.
- deleted 13y ago[deleted]
- rtfeldman 13y ago> in terms of copy writing, it leaves something to be desired. Haskell advocacy is high in the running for the least effective in the business. Boosters can't seem to help but pitch the things they care about rather than the things the listener does. Maybe it feels satisfying, but it's no way to attract converts. A more effective approach would be to choose common tasks people perform in other languages and demonstrate how they can be less (error-prone, time-consuming, verbose) in Haskell. For instance, I recall reading about a Haskell Web framework where the compiler guarantees user-generated content never makes it into any served HTML unsanitized. What a boon for security! However, this is not shouted from the rooftops; instead, it's taking me so long to track down I've given up in the hopes that someone will post it here instead.
- tazjin 13y agoYou are searching for Yesod - http://www.yesodweb.com http://www.yesodweb.com - which has some other fancy features like making sure that you can never render an incorrect dynamic URL (because URL's are represented by data types) and more such features. I've used Yesod in actual real-world projects and it was always a pleasure, albeit sometimes slightly complicated - the new version (which I haven't used yet) promises to simplify this a lot though.
- rtfeldman 13y agoThanks!