Hacker Newsnew | comments | show | ask | jobs | submit login

I think that a much better alternative to Node than Python or Go is Haskell. Why? Well, for one, it makes writing asynchronous code very easy--you essentially get it for free. Haskell web servers perform very well while keeping the code readable.

However, ignoring performance, there are also all of Haskell's other advantages. The type system is great--you can do stuff like ensuring links within your app work using the type system. Haskell is also very good at embedding DSLs, which can make writing web-specific code much nicer. In my experience, Haskell code tends to be more concise and declarative than Go or Python, making it easier to read. And, crucially, you can program at a higher level of abstraction which makes it both easier to write and maintain relatively complicated code.

Now, admittedly, going from almost any other language to Haskell is quite a shift. For most programmers, learning Haskell will take a bit longer than learning yet another imperative language (e.g. Go). However, I think this is well worth it, and web apps are a particularly convenient field for it.

This[1] StackOverflow question and an associated paper[2] are very interesting to read about how a Haskell web server could work and have good performance.

[1]: http://stackoverflow.com/questions/3847108/what-is-the-haske...

[2]: http://community.haskell.org/~simonmar/papers/web-server-jfp...

It would also be useful to look at a Haskell web framework like Yesod[3], Snap[4] or Happstack[5]. I'm currently a little biased towards Yesod (which has, coincidentally, recently received commercial backing), but I think the choice of framework is largely a matter of preference.

[3]: http://www.yesodweb.com/

[4]: http://snapframework.com/

[5]: http://happstack.com/




/second Haskell. If I could do everything in it I would (stuck with JVM for some things though). Ryan Dahl even looked at Haskell before choosing V8, said the language is ideal but hacking GHC was too complex:

>I was into Ruby for a while, I said, but eventually the VM just drove me insane, because it's just so slow, every time you try to make it faster you realize: "OK, I am just going to write this part in C" and every single line of Ruby that you add to your application, actually just slows down the server noticeably. And so eventually I just kind of ended up with this big C thing that I was kind of happy with, like OK I could write a web server with it and I could do file IO and so I had for a long time the idea of "I would have this kind of library that abstracted some part of the problem away and people can write it in C and they can write their little web servers.

People don't like writing stuff in C. Basically I want to put people in this non-blocking environment because it is the right way to design a server, it just kind of maneuvering around all the other pieces of the computer system and I would really like to do such a thing in Haskell or some sort of declarative language like this, where you could literally be purely functional when you receive events off of the socket, because all your side effects would happen on the event loop and you would just allow that to happen and then you kind of get a function call with some data and you would do whatever with that, make some call which would not have a side effect, you just write something to some buffer that would get flushed to the kernel and then you drop back down to the event loop.

Side effects would happen, everything would happen and then you get another call from that. But when you are receiving an event from the event loop you could be purely functional, you could really have nothing to do with anybody else and that is attractive. But you look in the GHC code and it's very hard and I am not such a good programmer and I gave up on that. And then V8 came out and it just kind of clicked. I am not a Javascript originally, have nothing to do with that really, but it just seams like a natural sort of thing once I started poking around VA.

1. http://www.infoq.com/interviews/node-ryan-dahl

-----


Finally I am convinced about Haskell. I am giving it a shot: http://learnyouahaskell.com/chapters. Thanks :)

-----


There's lots of books, you can find RealWorld and Road to Logic online too (not sure if RtL is legit)

http://alexott.net/en/fp/books/#sec7

and tuts

http://www.haskell.org/haskellwiki/Learning_Haskell

http://www.haskell.org/haskellwiki/Category:Tutorials

-----


Learn you a Haskell for Great Good is one of the best introductory programming language books I've ever read. I don't use Haskell very often, but after carefully reading this book, I'm now able to easily use functional code in my Python and CoffeeScript/JavaScript when I need to do so.

The online version is free, but I bought the book. It's worth it.

http://learnyouahaskell.com/

-----


you're out of your skull if you really think that Haskell has a shot in this market. Node.js is popular because it's easy to learn. Haskell fails there. That's probably the most important factor for web frameworks. Remember the total fucking trainwreck that is Rails, and how popular that was (and still is)?

Technologies don't become popular on technical merits alone. Haskell fails at psychology.

-----


I never said Haskell would become popular, I said it was the better alternative. I don't expect every web developer to drop what they're doing and pick up Haskell--but I do expect some of the best ones to do so :P. I honestly don't care that much about what most people are using anyhow.

You really shouldn't choose your technology just based on popularity. Sure, it's a metric. But I don't even think it's an important metric. So next time you start a company, think Haskell and ignore the peer pressure to choose something common :).

To me, popularity is not really a goal in and of itself. As long as something is the best to use, I'll use it even if it's not terribly widespread. Sure, popularity is nice and brings some benefits, but I'm never bound by it. After all, I use Linux too!

-----


I don't think Haskell will ever enjoy wide-spread adoption (although I wish it would happen). Haskell really does have the best constructs for parallelism. You have sparks, which can map to Haskell threads, which can map to OS threads. Using an evented system would be similar to using Haskell threads except Haskell can utilize more than one CPU core.

-----


Are there libraries similar to Socket.IO for Yesod framework?

-----


I believe they are building sockjs, which is better than socket.io, in haskell so you should be able to use that someday soon.

-----




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: