Live data from Hacker News

The Way of the Gopher: Making the Switch from Node.js to Golang

medium.com

171–180 of 189 posts

Re: The Way of the Gopher: Making the Switch from Node.js to Golang

#171
post #149
post #134

Earlier quoted context omitted.

The programming model you are describing is almost exactly the model Go has, it just takes it a step further and allows N:M "green threading", so you can use all your cores.

It is exactly Go's model. Go, since the very beginning, has a N:M threading model. runtime.GOMAXPROCS() resp. $GOMAXPROCS is your friend to control the amount of OS threads, and since 1.5 or so, it is by default equivalent to the number of CPUs visible to the Go runtime, anyway.

Well, he was describing a N:1, not N:M: "No need for actual mutexes as the program is still actually single threaded", but yes, Go has been N:M from the start.

Re: The Way of the Gopher: Making the Switch from Node.js to Golang

#172

Earlier quoted context omitted.

I've been learning Node.js for the past several months and building all my pet projects exclusively with it. A couple weeks ago I was offered a job, they knew I was mostly interested in JavaScript, but they dropped one on me in the interview. The condition of me being hired was I had to learn to Golang and would be developing in Go. I just felt like I was switching rafts midstream if I went that route so I had to say…

Interesting, for me the language I use would be near the bottom of the list of priorities in a job search.

True, though, TBH, if a programmer can't say "Sure, I can learn that", I don't want to work beside him.

Re: The Way of the Gopher: Making the Switch from Node.js to Golang

#173

Earlier quoted context omitted.

I think I follow. But why do I want general-purpose functions to ever be non-blocking in Go? To me, idiomatic Go suggests that libraries, data structures, business logic, &c is encapsulated in blocking functions, and that concurrency is expressed in glue code.

That doesn't seem to be the argument to me (though I'm totally ignorant about the Node aspect of this). The argument to me is that Go advertises itself as being easy to write that concurrent glue code & then fails to provide basic abstractions around it. Everything you mention about things being expressed in glue code would be easier if Golang provided a modern promises library & holds just as reasonably for other mo…

> The argument to me is that Go advertises itself as being easy to write that concurrent glue code & then fails to provide basic abstractions around it.

What‽ It provides channels, which are a really nice abstraction for concurrency.

> Everything you mention about things being expressed in glue code would be easier if Golang provided a modern promises library & holds just as reasonably for other modern languages that do.

Have you actually written any Go? Using channels in Go is much nicer than using callbacks. Callbacks basically force one to write one's code in continuation-passing style, while callbacks let one work about sync points only where you need.

Re: The Way of the Gopher: Making the Switch from Node.js to Golang

#174

2010 - Making switch from PHP to Ruby 2013 - Making switch from Ruby to Node 2016 - Making switch from Node to Go 2019 - Making switch from Go to {hype}

Still using PHP (and Python and some other stuff) in 2016. I make it a rule to only jump on the new bandwagon when I know it's not going to explode in 3 months and currently isn't on fire.

[deleted]

Re: The Way of the Gopher: Making the Switch from Node.js to Golang

#175
post #80
post #69

Earlier quoted context omitted.

Care to explain?

Two iron-clad rules of data processing: * All data has a type * All I/O is asynchronous and interrupt (event) driven At its inception Unix doubled down on stupid, first by encouraging data to be stored and migrated in the form of untyped text streams, which require ad-hoc parsing and unparsing logic at the endpoints; and secondly by failing to provide asynchronous I/O primitives to user space. POSIX later provided an…

> At its inception Unix doubled down on stupid, first by encouraging data to be stored and migrated in the form of untyped text streams, which require ad-hoc parsing and unparsing logic at the endpoints

I tend to agree with you here: it'd have been better had Unix offered a typed abstraction over byte streams, but OTOH its approach really was a Worse is Better deal. Building a large set of tools which can deal with typed streams (or even trees, or graphs …) takes a long time, and is error-prone: building a few simple tools which treat everything as text is quick & easy. Of course, it does mean that the next four and a half decades are spent dealing with a lack of types, but it means one can ship quickly.

> Instead what people do is burn CPU cycles in select/poll loops

I thought that select/poll blocked, but it's been a long time since I did anything low-level like that, so I could be wrong.

> And all this stems from the fact that Unix was the Node.js of its day -- an environment designed to make things easy for casual programmers, not to do things correctly.

Well, Worse is Better.

Re: The Way of the Gopher: Making the Switch from Node.js to Golang

#176
post #120

I've been coding in Node for a couple of years. I find it interesting. But I'm aware that the async model of Node inverts the flow of control, turning code inside out and makes application logic difficult to scrutinize and reason about. Stack traces in traditional multithreaded languages are easy to understand, whereas in Node a stack trace is necessarily filled with unrelated calls - or perhaps no stack at all in th…

Node's javascript engine v8 can only run in one thread, if you want to access it from a different thread you need to take a lock (for example in Chrome / Chromium you need to take an isolate lock; each page runs it's own isolated v8 engine (read only code pages are shared, all other javascript pages (data plus read/write code pages) are private); in this sense it is very similar to the GIL in Python. So although node…

Since Google changed the V8 API to mandate use of Isolate pointers passed in to V8 functions as a parameter rather than implicitly using thread-local data for engine storage it is now possible to run separate V8 instances within the same thread (one at a time), or from different threads as they do not share state. One of the many issues Node has to contend with in using the V8 engine is a perpetually changing API surface.

Re: The Way of the Gopher: Making the Switch from Node.js to Golang

#177
post #41

Earlier quoted context omitted.

Why on earth are both of you getting downvoted so hard? I am so tired of reading hacker news articles with comments that are so pushed down because of subjective opinionated voting that is so obviously skewed towards one personality type. I have so many thoughts and opinions I want to contribute to these discussions but I have zero confidence it will fit within this type of environment that's been created. It really…

this is why i hardly commment on hackernews even when I give constructive feedback; simply people here are mostly childish

yup, the downvote proves me right after all

Re: The Way of the Gopher: Making the Switch from Node.js to Golang

#178
post #64

Earlier quoted context omitted.

> What Go does better than Nodejs is a better standard library What is so hard about `require('lodash')`, or `require('moment')`? > true concurrency The trade-off is you get great concurrency without thinking about it. If you are working in Go, you have to start thinking about it as you go. You can always think about it as you go with Node.js if you want, but you don't have to and you will still get quite far. > stat…

A big advantage for Go is that the standard library has been stable since 1.0 and there are no plans for breaking changes. This appears not to be true for lodash.

Lodash introduces breaking changes in major version bumps (following semver).

So upgrades are optional and not pulling the rug out from underneath the feet of devs.

Major releases allows the project to make corrections and avoid carrying around years of baggage.

Re: The Way of the Gopher: Making the Switch from Node.js to Golang

#179
post #173

Earlier quoted context omitted.

That doesn't seem to be the argument to me (though I'm totally ignorant about the Node aspect of this). The argument to me is that Go advertises itself as being easy to write that concurrent glue code & then fails to provide basic abstractions around it. Everything you mention about things being expressed in glue code would be easier if Golang provided a modern promises library & holds just as reasonably for other mo…

> The argument to me is that Go advertises itself as being easy to write that concurrent glue code & then fails to provide basic abstractions around it. What‽ It provides channels, which are a really nice abstraction for concurrency. > Everything you mention about things being expressed in glue code would be easier if Golang provided a modern promises library & holds just as reasonably for other modern languages that…

> What‽ It provides channels, which are a really nice abstraction for concurrency.

Channels are a concurrent safe queue, nothing more. They are not even particularly well implemented concurrent queues as they are highly contended.

What go provides for abstractions around those queues are range and select. Range is a nice way to make simple concurrency cases look like traditional for loops (and is very rarely used in practice as simple concurrency cases are rare, at least for me).

Select is a nice addition to the language, yet the edge cases around channels make it very difficult to reason about without keeping http://dave.cheney.net/2013/04/30/curious-channels open.

> Have you actually written any Go? Using channels in Go is much nicer than using callbacks.

I have, for 2 years, full time. I have not used node. Have you ever used a language that supports concurrency besides Go? Go does not provide, as part of its concurrency abstractions, things that are deemed bare necessities by other languages such as timeouts, cancellation, supervision, lock free structures, etc.

The entirety of the Golang concurrency story can be wrapped up with 3 things a) the culture of the language prefers message passing concurrency b) the scheduler is a very good example of when simplicity gets you great performance in the main cases c) select as a language keyword is interesting.

By leaving the basics out you push all of that work to the application level, which is why I think the callbacks argument is a red herring. At the application level you are either going to encounter callbacks (as in the stdlib http handler) or blocking code (subject to races, deadlocks, etc).

Re: The Way of the Gopher: Making the Switch from Node.js to Golang

#180
post #15

The crux of the difference seems to be, in the Node.js service: "when any request timeouts happened, the event and its associated callback was put on an already overloaded message queue. While the timeout event might occur at 1 second, the callback wasn’t getting processed until all other messages currently on the queue, and their corresponding callback code, were finished executing (potentially seconds later)." And…

This is the first solution that a boring 'enterprise' Java programmer would have used and got on with other work.
Post reply on HN