News for hackers. Stuff that matters.
Re:Ditching Go for Node.js by iends on Thursday November 23, 2017 @11:59AM (#15766311)
Hopefully it's linear, or it's implemented wrong.
Re:Ditching Go for Node.js by bryanlarsen on Thursday November 23, 2017 @12:23PM (#15766503)
Hopefully, but all he said was "fanout" which could be either.

He knows it's implemented wrong, that's the point of the article: that Go doesn't make it easy for him to implement it right. The only question is the degree of wrongness. :)

Re:Ditching Go for Node.js by weberc2 on Thursday November 23, 2017 @01:47PM (#15767059)
I don't think this criticism holds water since he opted for JavaScript. If he was having problems with goroutines and channels, he could have picked a Node-like architecture (single-threaded, callback-driven) and still likely enjoyed better performance (and optimization tooling!) than with Node. If his issue was Go's type system, then he shouldn't have chosen a language with a strictly worse type system. In other words, in the worst case, some scenarios may require you to drop into `interface{}` in Go, which has the same safety guarantees as any type in JavaScript. This way only ~3% of your code is type-unsafe instead of JavaScript's 100%.

While I think there are lots of valid criticisms of Go (concurrency correctness is still hard and its type system is not very good for certain tasks), none of these are reasons to switch to JavaScript, as the author did. If he was struggling with goroutines and channels, he could still elect for a Node-like architecture (even making it single-threaded by setting GOMAXPROCS=1). If he needed generics and unions (as he cited), he switched to a language without them and without any static types at all (or a single static type, if you will); in Go he could have downgraded to `interface{}` which is analogous to JavaScript's one static type, and he would have only gave up type safety in the bits of code where Go's type system was lacking instead of everywhere.

I don't want to give the impression of overselling Go here; it's just that for the cited criteria, Go is strictly better than JavaScript.

Re:Ditching Go for Node.js by always_good on Thursday November 23, 2017 @04:24PM (#15767890)
In Javascript you have the option to gradual type into Typescript which offers much better static typing than Go. So I wouldn't be too dismissive.

Also, the "just write Node-like code in Go" isn't a solution at all. You're back to fitting a square peg in a round hole.

Re:Ditching Go for Node.js by weberc2 on Thursday November 23, 2017 @06:27PM (#15768533)
> In Javascript you have the option to gradual type into Typescript which offers much better static typing than Go. So I wouldn't be too dismissive.

It's not reasonable to switch from a language that gives you type safety in ~95% of cases to a language that gives you type safety in 0% of cases but which provides an easier transition to a type-safe language. This is why I'm dismissive.

> Also, the "just write Node-like code in Go" isn't a solution at all. You're back to fitting a square peg in a round hole.

You're wrong here. I read and write lots of Go code, and it's perfectly idiomatic to write single-threaded, asynchronous code. In fact, I'd probably do just this for his application, modulo a thin compatibility layer to deal with the fact that net/http spins up a goroutine for each request.

Re:Ditching Go for Node.js by adamweston on Thursday November 23, 2017 @01:58PM (#15767111)
Node makes the Node-like architecture much easier than it would be in Go, sort of by definition. Also, wouldn't Node's JIT fare much better in the face of dynamic typing than using reflection (interface {}) everywhere?
Re:Ditching Go for Node.js by weberc2 on Thursday November 23, 2017 @09:22PM (#15769063)
No, there's nothing special about it, and I probably shouldn't have used that term because it might convey that it is particular to Node. Event loop, callback based programming is easily implemented in most languages.
Re:Ditching Go for Node.js by Vendan on Thursday November 23, 2017 @02:16PM (#15767217)
interface{} is not reflection, and using both reflection and excessive amounts of interface{} are not a good idea in Go, and frankly, I don't see anything in this code that would require using either
Re:Ditching Go for Node.js by weberc2 on Thursday November 23, 2017 @09:20PM (#15769059)
To be clear, my point is that interface{} is the worst case in Go and the only case in JS.
Re:Ditching Go for Node.js by bryanlarsen on Thursday November 23, 2017 @01:52PM (#15767084)
Sure, if you don't mind writing your own websocket and pub/sub libraries.
Re:Ditching Go for Node.js by zsombor on Thursday November 23, 2017 @03:59PM (#15767749)
Both Go and JS are async and callback driven. The difference is that with JS those nasty callbacks are painfully explicit, whereas it is all hidden in Go. Node's callstack is a goroutine, except that the latter can also be preempted. If you have 100000 requests in progress in Node, it will consume at least as much memory as a well written Go program would.
Re:Ditching Go for Node.js by iends on Thursday November 23, 2017 @01:23PM (#15766879)
It being implemented incorrectly is not a property of the Go language, though.
Re:Ditching Go for Node.js by KirinDave on Thursday November 23, 2017 @04:29PM (#15767918)
It is a property of the Go language that the most recommended and explained concurrency primitives are slower than even 20 year old implementations.