News for hackers. Stuff that matters.
Re:Ditching Go for Node.js by iends on Thursday November 23, 2017 @11:53AM (#15766255)
Some random thoughts as somebody who codes a lot of Node.js at work and a lot Go in my freetime (and sometimes at work):

Did you try using pprof and the other tooling go provides to better understand your performance limitations? Tooling is a lot better in go ecosystem for understanding CPU and memory consumption, so if/when you run into into issues with Node you're going to be in a world of pain (this is basically a large portion of my job in a large node.js code base in the $day_job). You'll basically have to resort to using lldb and heapdumps in the Node world. I'm surprised the number of concurrent clients you go with Go was so small. I know lots of people using Go and Gorilla websockets that exceed 1.5k clients with similar memory constraints. To be perfectly honest, it sounds like you're doing something wrong.

As of Go 1.4, the default stack size per goroutine was 2KB and not 4KB.

If you add in TypeScript, you'll have a better type system than Go provides in the Node ecosystem. That's a huge point for using Node.js, especially if there are multiple contributors and the code base lasts for many years.

Re:Ditching Go for Node.js by chmln on Thursday November 23, 2017 @12:45PM (#15766641)
I've found typescript an invaluable tool.

Having worked on large backend codebases in both TS and JS, the difference is stark. The TS API in my case had something like 90% less errors, and those were all subtle bugs in business logic.

On the other hand, the large JS API over time had all sorts of unexpected type errors and undefined behavior. I'm aware that this is anecdotal evidence, but TS is pretty much a no-brainer now on backend.

Re:Ditching Go for Node.js by fauigerzigerk on Thursday November 23, 2017 @01:42PM (#15767028)
Is it not a problem in practice when TS type declarations and their associated JS code are written by different people at different times for different versions of a library?

I have no experience with maintaining TS projects over a longer period of time, but I have started some experimental TS projects where I was looking for type declarations.

What I found didn't seem to have any formal reference to a specific version of the library. I found that a bit scary. Not sure if it actually causes problems though.

Re:Ditching Go for Node.js by mattmanser on Thursday November 23, 2017 @02:30PM (#15767288)
Not caused us any yet over 3 years. You've got to think of it as the opposite, when we find a missing method because we at some point updated a library, we update the ts definition.

So it's not that it's a source of errors as most libraries are backwards compatible.

Re:Ditching Go for Node.js by geon on Thursday November 23, 2017 @02:31PM (#15767295)
> Is it not a problem in practice when TS type declarations and their associated JS code are written by different people at different times for different versions of a library?

It can be. But most popular libraries have very good version syncing, or even include definitions in the module itself. In the worst case, or if there are no typings available at all, you can just import the plain js, and use it untyped, which can be acceptable if it is not used in a lot of places.

> didn't seem to have any formal reference to a specific version

Yeah. It mostly works if you install the latest version of them both at the same time. Sometimes I've had to fiddle with backing the definition or the module back a version to get them to match.

Re:Ditching Go for Node.js by grsblk on Thursday November 23, 2017 @02:56PM (#15767443)
> The TS API in my case had something like 90% less errors

That sounds like a red flag to me. I hardly have any type related bugs in my pure JS server code. Must be a poor developer in the team. Too easy to blame JS for that.

Re:Ditching Go for Node.js by KirinDave on Thursday November 23, 2017 @04:38PM (#15767961)
If Typescript can deliver 90% less errors with the same team, saying "Must be a bad developer" is a useless comment.

If TypeScript let's that developer make good code, then the variable is JavaScript.

Re:Ditching Go for Node.js by crucialfelix on Thursday November 23, 2017 @03:09PM (#15767501)
That's the great thing about Type systems. It doesn't matter if the development team is amazing or not. Typescript still makes huge classes of errors impossible. It also speeds up development due to superior IDE support.
Re:Ditching Go for Node.js by pure on Thursday November 23, 2017 @04:07PM (#15767792)
I've only used TS on the frontend, but I had the same opinion as you until I dug into a couple of TS projects. I don't know if I've ever caused a JS production bug that was a type error at its core, but I've had plenty of bugs like that in development. TS lets me cut out those little dev cycles where I'll write some code, rebuild the app, then see an obvious error in the JS console when I run the app. That adds up to a lot of wasted time over a week of coding. Smart autocomplete and smart variable renaming is also really nice, and I have way more confidence refactoring a TS project than a JS one. I think using TS does result in fewer production bugs, but the big win for me has been having fewer development bugs.
Re:Ditching Go for Node.js by staticassertion on Thursday November 23, 2017 @06:12PM (#15768448)
Types are good for more than just "int instead of string". What you consider a type related error is likely not the full set of errors a type system can prevent.
Re:Ditching Go for Node.js by thraxil on Thursday November 23, 2017 @05:32PM (#15768244)
Aside from the other responses you are getting, consider that the "90% less errors" doesn't actually tell you anything about the overall quality of either codebase. It could be a million lines of JS/TS with 10 errors found in the JS vs 1 in the TS. That would be a 90% reduction, but 10 errors in a large codebase would still be pretty excellent.
Re:Ditching Go for Node.js by jordwest on Thursday November 23, 2017 @05:13PM (#15768155)
A great carpenter can hammer a nail with a screwdriver, but that doesn't mean it's a good idea.

When the tools help you, a good developer can focus on making better things rather than not making mistakes.

Re:Ditching Go for Node.js by always_good on Thursday November 23, 2017 @04:20PM (#15767875)
Tests are also a red flag for the same reason. Just suck less, I always say!
Re:Ditching Go for Node.js by ryanplant-au on Thursday November 23, 2017 @01:14PM (#15766824)
There are quite a few things I like about Go, but it's just so hard to leave the safety and reliability of TypeScript. Go's limited type system is its fatal handicap IMO.
Re:Ditching Go for Node.js by blowski on Thursday November 23, 2017 @01:35PM (#15766964)
It’s interesting how divisive Go’s type system is. For some people it’s the main reason they use it, for others it’s a fatal handicap.

FWIW I predominantly use PHP, so I have no dog in this fight.

Re:Ditching Go for Node.js by iends on Thursday November 23, 2017 @01:49PM (#15767074)
I think a lot of the differences between how people view Go is based on where they are previously coming from. The C/C++ folks are used to worse or more complex type systems so they view Go as fresh air. The “better python” people love the easy to use type system and the performance improvements. But those “better python” people are used to things like package managers which the C/C++ have done just fine without. The Java people don’t understand why they should give up an expressive type system for faster compile times. (Might see this from people who love C++ templates too.)

At least that’s some generalizations I’ve observed, YMMV.

Re:Ditching Go for Node.js by erik_seaberg on Thursday November 23, 2017 @03:36PM (#15767640)
I think some programmers want to carefully select a type specialized data structure, and others just bury the problem under a pile of array iteration.

And to hell with compile time. If the build takes 10x as long but we run 5% fewer prod servers, that pays for itself in minutes. And if type and nullability checking prevents one prod outage, that saves more time and stress than every build I've waited for this year.

Re:Ditching Go for Node.js by iends on Thursday November 23, 2017 @03:58PM (#15767743)
I often don’t understand the Go teams obsession with compile times, but I’ve never worked on large Java or C++ code based that take forever to compile. I mostly want them to optimize for runtime performance even at the expense of compile time, but this does not seem popular with the core team.
Re:Ditching Go for Node.js by owaislone on Thursday November 23, 2017 @09:16PM (#15769047)
You're right. You need to have worked on Google scale C++ programs to understand and acquire the obsession.
Re:Ditching Go for Node.js by w4tson on Thursday November 23, 2017 @02:03PM (#15767133)
What a great comment. I know it’s a bit of a generalization but it’s helped me understand why some might get fanatical.
Re:Ditching Go for Node.js by rubber_duck on Thursday November 23, 2017 @05:30PM (#15768243)
Java - expressive type system ? The bar must have been set really low by Go...
Re:Ditching Go for Node.js by 323454 on Thursday November 23, 2017 @06:51PM (#15768633)
Java has generics, Go doesn't.
Re:Ditching Go for Node.js by stmw on Thursday November 23, 2017 @02:24PM (#15767257)
Good points - where one comes from really makes a difference.
Re:Ditching Go for Node.js by dullgiulio on Thursday November 23, 2017 @02:32PM (#15767300)
I am not too familiar with TypeScript (I only know that typing is optional for backwards compatibility).

What are some practical examples of strengths it has over Go?

Re:Ditching Go for Node.js by piano on Thursday November 23, 2017 @05:14PM (#15768158)
Muh generix!
Re:Ditching Go for Node.js by MuffinFlavored on Thursday November 23, 2017 @02:49PM (#15767412)
> Tooling is a lot better in go ecosystem for understanding CPU and memory consumption, so if/when you run into into issues with Node you're going to be in a world of pain (this is basically a large portion of my job in a large node.js code base in the $day_job).

Is there no movement to change that? What about `node --inspect`?

Re:Ditching Go for Node.js by iends on Thursday November 23, 2017 @03:52PM (#15767722)
node —-inspect is a great debugger but last I looked the tooling around memory wasn’t very good. As far as I know, the best practice is to use Ben Nooordius’ heapdump tool (which is super flakey between bugs and Linux oom killer) or lldb with a node plugin. Joynet has/had some cool stuff for illuminos based OSes and IBM seems to be working on some tooling but it’s not there yet.