Live data from Hacker News

Why I went from Python to Go (and not node.js)

orel.li

71–80 of 202 posts

Re: Why I went from Python to Go (and not node.js)

#71

Ah, code comparisons. I don't see much difference in the Go code vs Javascript, except for the extra comments and logging in the js. How about this? var cluster = require('cluster') , http = require('http') , os = require('os') if (cluster.isMaster) { os.cpus().forEach(cluster.fork) } else { http.createServer(function(req, res){ res.writeHead(200) res.end('Hello world') }).listen(8000) }

Thanks, his uneven code comparison was bothering me. The main difference I see is that the nodejs code is easier to read.

Of course it's easier to read for you: you know JavaScript. I know both JS and Go and the Go version is much easier on my eyes - there's simply a lot less to it.

Re: Why I went from Python to Go (and not node.js)

#72

Earlier quoted context omitted.

Interactive coding is a very powerful way of working, it's one of the reasons I'm so productive in Mathematica. At a Go talk he did, I raised the idea with Russ Cox of having a "repl" package that would allow one to instrument a running program with a live REPL to do debugging and development on it. The reflect package is powerful enough to make some of that relatively straightforward, but one major problem is that G…

> one major problem is that Go can't construct new types at runtime. The current implementations can't. I don't see any reason why one couldn't. In any case, I don't think that's such a big deal. One just goes from completely seamless interactive coding to mostly seamless interactive coding. > Unless one builds a full Go interpreter That is precisely what I was proposing. (Are you implying some sort of hard VM/interp…

Go's compiler is said to be fast. Could you fake interpretation by continually recompiling everything?

Re: Why I went from Python to Go (and not node.js)

#73
post #65

I'd like to start porting a few of my little scripts to Go (that do pretty poor messy parallelism in Python), and I was wondering what a good resource/book type thing would be for people learning Go. Like, the equivalent of learn you some haskell or whatnot. Also some advice on "wtf library do I use for this". Is there some sort of Go package manager? How does all this shit work?

I recommend starting with http://tour.golang.org/#1 . Yes, the Go tool comes with package-management capabilities. "go get labix.org/v2/mgo" will download the very excellent MongoDB driver mgo, for example.

But then actually implementing something useful is cryptic and obscure. I tried figuring out how to connect to a postgresql server following the spaghetti documentation of https://github.com/bmizerany/pq and http://golang.org/pkg/database/sql/ and have yet to find anything useful. Hacking around only leaves me with frustration. Searching around only leads me to unhelpful descriptions of what the GO command does in MSSQL Server.

Re: Why I went from Python to Go (and not node.js)

#75
post #31
post #20

Another gonatic? I'm immediately reminded of the days when everyone who liked D proclaimed it would overtake C++ and rule the world with terrible, contrived examples: "let me show you why my language is better than yours by completely misunderstanding how to solve a problem, then implementing that broken/overengineered solution in your language, then compare it to something my language's API can do for me, just so we…

Big difference is that D did not have a Google backing it and D had a fairly major falling out by different factions. This was a great pity because I think it probably is one of the best languages ever made and didn't get the take up it absolutely deserved.

The big difference between D and Go is that D is another kitchen sink language. It has almost all of C++'s features, and more! Conversely, Go has many fewer features than C++ or D, and many argue that this is Go's biggest selling point.

Re: Why I went from Python to Go (and not node.js)

#76
post #27
post #24

Earlier quoted context omitted.

ah, so, I don't think I wrote that section particularly well. I hold Erlang and Haskell in very high regard; I was really trying to mock my own superiority complex, which I think is fairly common in the Python community. I guess what I was really trying to get at is that Go is verymuch an industry language. Haskell I would argue against being an industry language not because it can't be used in industry; that's not a…

You're digging in. > Haskell I would argue against being an industry language FYI, the problems the Haskell community has been working on are things like scalability, performance and safety because they're critical to industrial problems . Toy approaches don't work at the scale we operate at -- you need real computer science. You want 1,000,000 Haskell threads in your app? You've got it. Want to write numerical model…

While I agree with you, please be careful - you're an extremely influencial member of the Haskell community. This post could come across as very smug, and is thus potentially damaging. I'm sure it wasn't your attention, but please - be careful.

Re: Why I went from Python to Go (and not node.js)

#77
post #38

Earlier quoted context omitted.

The perception out there is that Haskell is an academic language, also that it is a "difficult" language. This is not fair on Haskell but that is what people think and that really is the issue that Haskell has to overcome.

Honestly, I find Go more difficult than Haskell

I spend 3 days and learned all features of Go. Haskell, I spend 3 month just to barely touch applicative functors and a bit monads. I am expecting another year if I need to truly fluent in haskell.

Re: Why I went from Python to Go (and not node.js)

#78
post #70

Ah, code comparisons. I don't see much difference in the Go code vs Javascript, except for the extra comments and logging in the js. How about this? var cluster = require('cluster') , http = require('http') , os = require('os') if (cluster.isMaster) { os.cpus().forEach(cluster.fork) } else { http.createServer(function(req, res){ res.writeHead(200) res.end('Hello world') }).listen(8000) }

You should update the node.js docs if you consider the original JS snippet ugly, because that's where I pulled the original code sample from verbatim. In any case, it's still not an apples to apples comparison. The node.js example forks separate processes that share nothing, while in the Go example it all runs in one process so the HTTP handlers can communicate with each other via channels or other shared data struct…

Shared-nothing is a design decision (and runtime/language limitation), due to the single-threaded nature of js. The workers can communicate with the master via message passing: http://nodejs.org/api/cluster.html#cluster_worker_send_messa...

The documentation has the primary goal of explaining how things work, not being the canonical style guide.

Take a similar example from the Go documentation:

    const NCPU = 4  // number of CPU cores

    func (v Vector) DoAll(u Vector) {
        c := make(chan int, NCPU)  // Buffering optional but sensible.
        for i := 0; i 

Re: Why I went from Python to Go (and not node.js)

#79
post #70

Ah, code comparisons. I don't see much difference in the Go code vs Javascript, except for the extra comments and logging in the js. How about this? var cluster = require('cluster') , http = require('http') , os = require('os') if (cluster.isMaster) { os.cpus().forEach(cluster.fork) } else { http.createServer(function(req, res){ res.writeHead(200) res.end('Hello world') }).listen(8000) }

You should update the node.js docs if you consider the original JS snippet ugly, because that's where I pulled the original code sample from verbatim. In any case, it's still not an apples to apples comparison. The node.js example forks separate processes that share nothing, while in the Go example it all runs in one process so the HTTP handlers can communicate with each other via channels or other shared data struct…

Read again, he didn't say it was ugly. He just pointed out that it wasn't 1:1 because the Go code omitted the logging and comments. A valid criticism.

Re: Why I went from Python to Go (and not node.js)

#80
post #36

Earlier quoted context omitted.

well, the complaint isn't entirely that it's hard, per se, but that there are many different ways to do things concurrently in Python, and that it presents too many choices to be made for the novice programmer. In Go, you just say `go myfunction()` and you're done. There's a lot of value in that.

Until, that is, you tackle a problem for which one machine isn't big enough, at which time you need to do all of the "real" solutions anyway, and `go myfunction()` buys you...nothing. There's way too much focus today on new languages that are designed to work on just one machine, and scale there – as if vertical scaling was the true problem we all face, when in fact, it's not. /sigh

Go is well suited for this too. Look at dozer at github.
Post reply on HN