Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better first code example #226

Closed
adius opened this issue Feb 16, 2018 · 3 comments
Closed

Better first code example #226

adius opened this issue Feb 16, 2018 · 3 comments

Comments

@adius
Copy link

adius commented Feb 16, 2018

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 🙈".
    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
Copy link
Member

relrod commented Feb 17, 2018

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
Copy link
Author

adius commented Feb 17, 2018

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
Copy link
Member

relrod commented Feb 18, 2018

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

@relrod relrod closed this as completed Feb 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants