News for hackers. Stuff that matters.
Re:Go as an alternative to Node.js for Very Fast Servers by jgrahamc on Friday February 22, 2013 @12:15PM (#5265291)
While JavaScript drags the scars of its hasty standardization around with it, Go was designed very thoughtfully from the beginning, and as a result I find that it’s a pleasure to write.

This is very true. Go is a pleasure to write. In fact, it's such a pleasure then when you hit something that wasn't really well designed it's horrid.

Re:Go as an alternative to Node.js for Very Fast Servers by VeejayRampay on Friday February 22, 2013 @02:06PM (#5265999)
I've done Java, PHP, Objective Caml (in college for a few years), some basic C, Ruby and Javascript before and I concur. Go is a real breath of fresh air. I have the same feeling I have when I code with Ruby: that sense that the language works WITH me, that the whole experience is smooth and seamless.

I wish Go stays on that path for a long time. And it never gets TOO big, which makes for awful communities.

Re:Go as an alternative to Node.js for Very Fast Servers by tikhonj on Friday February 22, 2013 @03:13PM (#5266478)
Maybe you didn't do much OCaml? I've found it to be mostly significantly better than Go, especially with it's type system. Go's type system is relatively limited and ad-hoc where OCaml's is extremely elegant, simple and consistent.

In particular, OCaml has an awesome module system and a great take on structural sub-typing combined with proper type inference and sane parametric polymorphism.

Having actual algebraic data types is night and day to Go's more limited structs. OCaml also has a good object system which people don't use too often but can come on very handy.

Re:Go as an alternative to Node.js for Very Fast Servers by acc00 on Friday February 22, 2013 @04:43PM (#5267059)
I've written a moderate amount of OCaml and some Go.

While I agree that the former is a nice language, it doesn't compare favorably to Go as a development suite: the standard library is terribly designed, and the package management is rather poor compared to Go's (which is about as great as it gets).

Now there is "OCaml Batteries Included" which is supposed to mitigate that, but it appeared after I stopped actively using OCaml so I can't comment on that (incidentally, I dislike many of their choices).

Also Go has many of the features that make programming in ML a pleasure, many languages these days have them, which is a good thing.

Personally my tool of choice for many tasks would be OCaml with Go's package management system, and perhaps a syntax closer to M-expressions (like Mathematica).

Re:Go as an alternative to Node.js for Very Fast Servers by gnuvince on Friday February 22, 2013 @05:41PM (#5267390)
OCaml should definitely move toward adopting either Batteries or Jane Street Core as its standard library; they offer a lot more functionality.

For package management, I haven't had the chance to really try it yet, but I'm hearing good things about OPAM.

Finally, Rust just looks awesome, I'm hoping that the language stabilizes before the end of the year, as I'd love to do my master thesis with it.

Re:Go as an alternative to Node.js for Very Fast Servers by acc00 on Friday February 22, 2013 @05:52PM (#5267459)
As great as OPAM might be (neither have I tried it), it has one fundamental downside compared to Go: it is a package manager for OCaml.

Package management is one of those things that are better off when there is just one.

Re:Go as an alternative to Node.js for Very Fast Servers by gnuvince on Friday February 22, 2013 @06:07PM (#5267533)
I'm pretty sure OPAM will become the de facto standard of the OCaml world; most people don't want to deal with the other ones.
Re:Go as an alternative to Node.js for Very Fast Servers by grey-area on Friday February 22, 2013 @05:16PM (#5267259)
I love the package management in go and agree it is pretty good, but the lack of versions make me nervous. I do wish they reacted quicker to common criticisms like this and the missing generics, but I guess they want to take their time and do things right. What there is of go has been a pleasure to explore though.

Would you mind expanding on what is good about m expressions and how that could apply to go, I'm not familiar with them?

Re:Go as an alternative to Node.js for Very Fast Servers by acc00 on Friday February 22, 2013 @05:49PM (#5267433)
See [0] for an introduction to M-expressions, which was initially an alternative syntax for Lisp, but have found its way into APL and Mathematica.

Please note I'm suggesting using that syntax for OCaml, not Go.

In short, I want to write "f[x;y]" for "f x y". On the first sight it appears this adds a bunch of noise, but there are many advantages:

1. You now have much less parens resulting from nested function calls;

2. You get partial application by any argument, not just the last. map[;list] is a "functor" that applies its argument to "list";

3. Corollary to this, chaining functions together is now much easier even if you need to supply a parameter other than the last: f[;x]$g[y] (assuming $ stands for apply; it might be wortwhile to take empty space for application)

4. Further you are able to unify many aspects of the syntax (if[cond;true;false]), which makes parsing easier for both humans and computers.

[0] http://en.wikipedia.org/wiki/M-expression

Re:Go as an alternative to Node.js for Very Fast Servers by steveklabnik on Friday February 22, 2013 @05:03PM (#5267170)
If you like OCaml but find Go lacking, you should check out Rust. I'm more of a Haskeller than a OCamlist, but the Rust compiler was originally written in OCaml, and it's influenced the language a lot.
Re:Go as an alternative to Node.js for Very Fast Servers by cmars on Saturday February 23, 2013 @12:36PM (#5270521)
I find this recommendation interesting because I am developing an OpenPGP keyserver in Go, called Hockeypuck (https://launchpad.net/hockeypuck). I started the project because of problems I ran into with SKS in a very specialized, write-heavy use case. SKS is developed in OCaml.

I've been porting the reconciliation algorithm in SKS to Golang so Hockeypuck can peer with SKS servers. I think it will be very useful in other applications beyond keyservers. The mathematical definitions of finite fields and polynomials are elegant in OCaml, and I definitely understand the choice of language from that point-of-view.

If you want to see a comparison of finite-field arithmetic and polynomial factoring in Go vs OCaml, my recon port is in a separate project called conflux (https://github.com/cmars/conflux). It's an incomplete work in progress, needs tightening up, tail-call elimination, etc. but early feedback is welcome.

As a developer unfamiliar with OCaml & without much formal mathematics background, I had a hard time understanding some of the intent of the SKS sources -- in those cases, conflux is a straight-up port from OCaml with unit-tests also ported from SKS to back it up. Some of it, I understood the math concept, but not the OCaml, so I ported from SymPy instead.

Wolfram Alpha was also helpful to validate my work and create test cases -- it does polynomial factoring over finite fields!

Re:Go as an alternative to Node.js for Very Fast Servers by VeejayRampay on Saturday February 23, 2013 @03:30PM (#5271345)
Yeah, like I said, it was mostly during 2 years in college (in France in the close-knit network of research institutes and universities where the language was actually born) and OCaml is a wonderful language. It has numerous upsides (type inference, the mixed functional/OO paradigms, non-verbose, relatively fast, the awesomeness of pattern matching).

I was mentioning it in my previous comment to provide perspective on my opinion of Go.

I am a big supporter of the idea that all languages have their advantages anyway :)

Re:Go as an alternative to Node.js for Very Fast Servers by papsosouid on Friday February 22, 2013 @12:40PM (#5265442)
Can I ask what language you are used to? I hear how nice go is as a language a lot, but coming from haskell, go is hideous in comparison.
Re:Go as an alternative to Node.js for Very Fast Servers by codygman on Friday February 22, 2013 @01:08PM (#5265605)
I'll tell you that coming from Python/C it looks very nice. I'm actually learning haskell atm (use xmonad for a window manager), I'm afraid that if it lives up to it's hype I won't want to program in anything else.

Also playing with Racket, Clojure, and good ol' Common Lisp.

Re:Go as an alternative to Node.js for Very Fast Servers by tel on Friday February 22, 2013 @04:50PM (#5267104)
Here's a comparable Haskell server, warts and all

    {-# LANGUAGE OverloadedStrings #-}
    import Snap
    import qualified Data.ByteString as BS
    
    main :: IO ()
    main = httpServe (setPort 8000 emptyConfig) $ writeBS $ BS.replicate (1024*1024) 100

I'm benchmarking it currently, but my laptop's network stack seems to break ab. It's also probably faster to build the response incrementally using an Enumerator, but I've never used Snap's Enumerator library and this is slightly closer to the design being tested in the other servers since it'll allocate the whole bytestring instead of writing it lazily.
Re:Go as an alternative to Node.js for Very Fast Servers by e12e on Friday February 22, 2013 @11:08PM (#5268508)
I tried this, the other Haskell version, and the go and node version from op -- with some rather ridiculous ab-values -- the end result was that both of the haskell versions crashed after around 8k requests, while both the go and node-versions completed -- with no missed requests.

I don't have the full numbers (didn't log them) -- but running "ab -n 100000 -c 1000 http://localhost:8000/ -- nodejs completed in 160 seconds, go in 170 seconds. Nodejs had a few requests around 8 seconds, and go had a worst time of almost 5 seconds. (This is on an old desktop, with a core 2 duo - roughly 6000 "bogomips" pr core, two cores).

I'm guessing the haskell solutions ran out of resources, but I'm not sure.

Re:Go as an alternative to Node.js for Very Fast Servers by tel on Friday February 22, 2013 @11:56PM (#5268623)
Not sure, I'm trying to replicate it but I'm having a tough time with OSX's network stack. I can't siege or ab very well. The Haskell server tends to stay under 6Mb on my machine though. I'll keep stressing it.

http://imgur.com/b89bxST

Re:Go as an alternative to Node.js for Very Fast Servers by danieldk on Saturday February 23, 2013 @01:46AM (#5268812)
Because this isn't the same benchmark, did you compile with -O2? The Go version allocates a 1MB slice once and sends it to every user. The Haskell version literally states that it should make a bytestring during every request. The compiler might optimize it away with the right flags.
Re:Go as an alternative to Node.js for Very Fast Servers by danieldk on Saturday February 23, 2013 @02:40AM (#5268906)
I tried the benchmark as in the article, and the above Haskell compiled with '-O2'. With Go I usually get around 1320 reqs/second, with Snap around 1100. Both using four threads.

With a single-threaded Warp instance, I could get around 1350 reqs/seconds, though it failed dramatically when I used more threads.

Re:Go as an alternative to Node.js for Very Fast Servers by e12e on Saturday February 23, 2013 @09:40AM (#5269729)
No, I didn't (see my other comment). I expect (especially Haskell) to be correct without -O2 -- being slower isn't a problem - crashing - not so much.

Tried it now -- both haskell versions crash with -O2 as well (and ab -n 100000 -c 1000 -- so not the same benchmark as the original -- and a rather silly test).

Re:Go as an alternative to Node.js for Very Fast Servers by chimeracoder on Friday February 22, 2013 @01:06PM (#5265594)
Go is going to look hideous to you because you're probably expecting functional things like list comprehensions (which Go doesn't have) and a very intricate type system allowing for things like generics (which Go doesn't have either).

Go code will look a little less DRY to you as a result, which is a fair criticism, but it makes up for that by being incredibly opinionated (that's a good thing), being incredibly easy to prototype in, and being incredibly easy to refactor painlessly.

Re:Go as an alternative to Node.js for Very Fast Servers by zem on Friday February 22, 2013 @06:03PM (#5267514)
actually, the thing i find most lacking in go (although granted i've only done a few toy programs in the language) is sum types. it would make error handling a lot more pleasant, for one.

i'm excited about rust, which did go the algebraic datatype route.

Re:Go as an alternative to Node.js for Very Fast Servers by papsosouid on Friday February 22, 2013 @01:21PM (#5265690)
>Go is going to look hideous to you because you're probably expecting functional things like list comprehensions

Nah, list comprehensions are just syntactic sugar and not used much in haskell. Python seems to encourage their use a lot, but you hardly even see them in haskell code.

>a very intricate type system allowing for things like generics (which Go doesn't have either).

That is definitely one of the big problems, but I take issue with the characterization of that as needing "a very intricate type system". Parametric polymorphism is very simple, and has been a completely solved issue for a very long time. There is simply no excuse for a brand new language to be decades behind on something so easy to do right.

>being incredibly easy to prototype in, and being incredibly easy to refactor painlessly.

Those are actually two of the other big issues going from go to haskell. Go is harder to prototype in, and it is easy to add bugs when refactoring because the type system is so poor.

Re:Go as an alternative to Node.js for Very Fast Servers by chimeracoder on Friday February 22, 2013 @01:29PM (#5265738)
> Parametric polymorphism is very simple, and has been a completely solved issue for a very long time. There is simply no excuse for a brand new language to be decades behind on something so easy to do right.

Go has addressed this; their approach is Go's interfaces, which combines the best of all worlds: duck typing with static type checks and type inference.

> Go is harder to prototype in, and it is easy to add bugs when refactoring because the type system is so poor.

This is where we'll have to agree to disagree. It's definitely not harder to prototype in - and I say this as a functional programmer - and if you find the type system to be inadequate when refactoring, it sounds to me like you're trying to write idiomatic Haskell in Go. Go's type system, by design, stays out of the way - if you're writing Go idiomatically, you really shouldn't be thinking very much about the types as you write them.

As for generics, this gets beaten to death on every single Go post on HackerNews. Yes, Go would ideally have generics. Yes, there are tradeoffs involved. Yes, those tradeoffs have been explained by the Go developers at length. Yes, they would be open to including them in the future, if somebody addressed the existing concerns. No, nobody seems to mind that they're missing from the language as-is, given those tradeoffs.

Re:Go as an alternative to Node.js for Very Fast Servers by emidln on Friday February 22, 2013 @01:48PM (#5265858)
> Go's type system, by design, stays out of the way - if you're writing Go idiomatically, you really shouldn't be thinking very much about the types as you write them.

I'd wager that if you aren't thinking about what your inputs and outputs are going to be at every step, you're introducing bugs or working harder than you have to. A strong static type system like you find in Haskell formalizes that so that it's required, but even in the languages I write most often (Python and C, which get bashed constantly for their type systems), this is just what writing solid code is about.

In Python, I may not be thinking exactly "what is the type of this thing, foo", but I am asking myself "okay, I'm trying to iterate this thing, is it actually iterable? How do I handle when it isn't? or guarantee it to always be an iterable ?".

Re:Go as an alternative to Node.js for Very Fast Servers by papsosouid on Friday February 22, 2013 @01:41PM (#5265808)
You are contradicting yourself about parametric polymorphism. First you acknowledge it doesn't exist, then you claim a limited workaround solves it.

>It's definitely not harder to prototype in - and I say this as a functional programmer

Have you used haskell to make the comparison?

>if you're writing Go idiomatically, you really shouldn't be thinking very much about the types as you write them.

I don't understand where you are coming from here. I am not thinking about types, that is why I need the compiler to point out when I mess them up. The problem is go has such a limited type system, that you have to change much more code when you refactor, and the type system is inadequate for catching many errors, in particular dealing with error handling. The combination makes go worse for refactoring than haskell. It is certainly much better than python for example, but you seem to be convinced that go is the top of the spectrum and nothing can exist above it.

Re:Go as an alternative to Node.js for Very Fast Servers by dman on Friday February 22, 2013 @02:02PM (#5265970)
I have been wanting to learn Haskell for some time. Is Real World Haskell still the best book for the language? Could you point me to some well written libraries/projects that are considered idiomatic haskell? Would appreciate the pointers.
Re:Go as an alternative to Node.js for Very Fast Servers by gtani on Friday February 22, 2013 @03:11PM (#5266463)
There's lots of books: Hutton, Hudak, Thompson, Richard Bird. I have a ugly draft/link dump for learning

http://isthishaskell.blogspot.com/2013/02/tips-on-learning.h...

Re:Go as an alternative to Node.js for Very Fast Servers by papsosouid on Friday February 22, 2013 @02:23PM (#5266144)
I would definitely start with learn you a haskell. It makes a much better introduction to the language than RWH. RWH is great when you have learned the basics and want to start tackling bigger problems.

Xmonad is a pretty common recommendation for looking at "good haskell code", in particular the overall design and how they keep the IO part minimized and isolated so the bulk of the application is easier to unit test. I think the standard libraries the come with GHC are good examples too.

Re:Go as an alternative to Node.js for Very Fast Servers by dscrd on Saturday February 23, 2013 @03:44AM (#5269036)
I studied Haskell for a decade with the goal of actually using it for production software. When I finally found a nice gap to try it, the experience was mostly awful.

Go was such a huge relief after that horrible catastrophe language that seems to still continue to wreck new generations. Please, please, don't poison your career on focusing on a single language, especially one as disturbing as Haskell.

Re:Go as an alternative to Node.js for Very Fast Servers by gtani on Saturday February 23, 2013 @12:43PM (#5270555)
What were the specific problems you had with haskell?
Re:Go as an alternative to Node.js for Very Fast Servers by dscrd on Wednesday February 27, 2013 @05:14AM (#5291590)
I had several small things (laziness, poor libraries [in 2009], failing to get anyone else in the organisation even the slightest bit interested, my own lacking skills) but the overall worst problem was the feeling of the disconnect between the language and the host running my program. That is of course more or less always an issue when one uses a higher level language, but I felt Haskell was so far off that it disturbed me.

Also, the negative effect one gets after going back to one's own code after several months seemed much much worse in Haskell. Haskell code is too thick, too concise, not unlike mathematics. I find it ironic that the community, apparently, values that.

I bet others have had better experiences, but I definitely did not. Hanging around with Haskell clearly taught me many good things about program design, but I don't foresee myself wanting to ever write anything on the platform ever again.

Re:Go as an alternative to Node.js for Very Fast Servers by papsosouid on Monday February 25, 2013 @09:45AM (#5279149)
>Please, please, don't poison your career on focusing on a single language

My career is likely older than you, I think it'll survive the horrors of using a good language. I've been running production web sites on haskell for a year so far, and it has been great.

Re:Go as an alternative to Node.js for Very Fast Servers by dscrd on Wednesday February 27, 2013 @05:04AM (#5291559)
"My career is likely older than you"

Your career spans over 30 years? If so, I applaud you and of course withhold my rights to criticize your choices without knowing more details.

Re:Go as an alternative to Node.js for Very Fast Servers by jgrahamc on Friday February 22, 2013 @02:58PM (#5266379)
Define hideous.
Re:Go as an alternative to Node.js for Very Fast Servers by papsosouid on Friday February 22, 2013 @03:32PM (#5266592)
"Extremely unpleasant"