haskell-infra / hl

Haskell web site (old -- see new repo at https://github.com/haskell-infra/www.haskell.org)
http://haskell.org/
BSD 3-Clause "New" or "Revised" License
158 stars 92 forks source link

Better first code example #226

Closed adius closed 6 years ago

adius commented 6 years ago

For reference:

primes = filterPrime [2..] 
  where filterPrime (p:xs) = 
          p : filterPrime [x | x <- xs, x `mod` p /= 0]
  1. Most developers are not interested in calculating prime numbers. It's like saying "this is just an academic toy language for math problems"
  2. I think the where syntax is not the best part of haskell. Defining something after using it feels rather stupid. When you start reading you're like "mh, from which unqualified import was that function imported" until you reach the where: "oh, it's defined here. After I've already used it :see_no_evil:". So definitely not a syntax feature I would present upfront.
  3. List comprehension is kind of cryptic and there are more beautiful ways to write the same code

I think we should rather present a short example where there is maybe a short function to generate some value (map, filter, or similar) and then do something IO related. E.g. http request, database read, …. Maybe use https://archives.haskell.org/projects.haskell.org/diagrams to generate a graphic.

People often have the notion that Haskell is too academic (https://news.ycombinator.com/item?id=8803128), therefore the first example should exactly counter this and not support it like at the moment.

Other languages have better examples. E.g. https://racket-lang.org does some GUI and web server stuff, https://elixir-lang.org presents messages and fault tolerance.

relrod commented 6 years ago

Hi @adius and thanks for the comments. The example on the front page is something that has gone through many variations, and I fear it will always be something over which people will bikeshed.

See:

If you want to present some alternatives and you can get a fair backing behind one of them, I wouldn't necessarily be opposed to changing the example (I can't speak for everyone else on the team). But please do check out the above discussions and understand the reasons why this example has been chosen. This discussion is not a new one by any means :).

adius commented 6 years ago

Haha, thanks for the references. I wasn't aware ...

I pitched the idea already in the functional programming slack and folks seemed to agree that other languages have better examples and that the current one is playing into the hands of the sceptics.

But yeah, really coming up with a better example is the hard part 😅. I'll mull over it the next weeks. Hopefully I'll get an enlightenment =P

relrod commented 6 years ago

Going to close this for now to bump it out of my queue, then.