>In Go, you can define different files for different operating systems that implement functionality depending on the operating system.
That sounds like it's actually very difficult to support multiple operating systems. As a developer I never, ever want to write any OS-specific code. Sure, that's sometimes required, but saying that the solution is to have multiple files, each for a single OS, doesn't sound good. It's a lot better to abstract the OS away. Node.js does this quite well. Seemingly a lot better than Go.
Besides, Node.js doesn't need to be compiled for each system. This alone makes Node.js better for writing code for multiple operating systems.
>Go is a compiled language so distributing applications for use on multiple platforms is just easier.
I disagree. You need to compile to code for every single platform, making code distribution costly. With Node.js you can simply distribute the code as it is and it probably works in any platform. (The probability is as high as it is for Go assuming no extra work for a new platform). Sure, each platform needs to have Node.js, but Node.js is supported in most platforms.
> I never, ever want to write any OS-specific code
With Go, you never, ever have to write any OS-specific code. From a single source, you can build executables compiled for different operating systems.
In any case, you're right that it can be nice to simply "run" a JavaScript application directly from its source code without worrying about compilation.
> You need to compile to code for every single platform, making code distribution costly. With Node.js you can simply distribute the code as it is and it probably works in any platform.
You're missing the point about distribution. Let's say you write a non-trivial command line application, and want to distribute it to your clients. With Go, you can distribute your program as a self-contained executable file. Yes, you may generate a few versions (Windows, OS X, etc.) depending on the needs of your clients, but the cost is a few seconds of compile time, and a few seconds posting links to the Windows, OS X, etc. executables. The cost is negligible.
Compare that to Node. How are you going to distribute your Node app to clients? Is every client going to install Node on their personal computer? Will they be able to figure out NPM? Yes, it's easy, but they'll mess it up anyway. What happens when the network has a hiccup and npm doesn't download your dependencies correctly, or they try to upgrade your dependencies and everything breaks?
If you plan on distributing your Node code, you're pretty much limited to distributing it to other Node developers. That's not going to work for everybody.
> With Go, you never, ever have to write any OS-specific code
It actually depends what you want to do. Since Go tends to be low-level, there may be a moment where your code goes into syscall land, in which case you're going to be OS-specific.
The most recent example I have in mind is mmaping a file: see https://github.com/edsrzf/mmap-go: there is a windows- and a unix- specific version. If you're using something else, you're out of luck (with this package at least)
There is a syscall package, but it's just piling up a lot of syscalls with already some OS-specific stuff. It is going to be so much of a burden to manage that the Go team plans to abstract this in a new package (https://golang.org/s/go1.4-syscall)
>With Go, you never, ever have to write any OS-specific code.
Okay. The article claimed otherwise: "In Go, you can define different files for different operating systems that implement functionality depending on the operating system."
>Yes, you may generate a few versions (Windows, OS X, etc.) depending on the needs of your clients, but the cost is a few seconds of compile time, and a few seconds posting links to the Windows, OS X, etc. executables.
Except when the developer only compiles for Windows and Linux, but someone wants to run the code on Mac os X.
>Will they be able to figure out NPM? Yes, it's easy, but they'll mess it up anyway.
You don't need NPM. You can fetch the dependencies and include that with the installer. There's a downside to that, though, which is binary-packages with npm.
> > With Go, you never, ever have to write any OS-specific code.
> Okay. The article claimed otherwise: "In Go, you can define different files for different operating systems that implement functionality depending on the operating system."
Both the article and the poster you're replying to are correct. You almost never have to write OS-specific code, but you can write it if you feel there's a benefit to it. Much like Node doesn't make you write C++ code but allows you to do it when you feel it's necessary. The article's main point was, I'm assuming, alluding to Go's build tags which are much more elegant than the traditional pre-processor directives used in the C/++ world. They give you a powerful expression language for targeting specific runtime environments that lets you separate out your OS-specific code in a very clean way.
When it comes to distributing an application, there's another advantage that Go has over Node. One of the common ways that people are distributing server applications these days is as Docker images. It solves the problem of users needing to understand npm quite nicely for a Node application, but makes the distributable artifact significantly larger since it includes the bulk of an OS alongside the application code. With Go's ability to create a statically-linked binaries, you can build your Docker images "FROM scratch" and images can be as small as 2.5m.
Further to what curun1r said, most(all?) of the Go stdlib is written in Go and that has much platform specific code. Hence, it supports it. However, unless you're writing system code you will most likely never need to touch this.
That's a very naive argument. There are so many other variables in choosing a cross platform language which you've overlooked:
]] Performance (AOT compiled languages will typically out perform JIT compiled language
]] user interface (is this going to be a command line app? Does it need a GUI? And if so, what frameworks are supported and do they need any OS specific boiler plate code?)
]] required runtime environment (does your language tool chains support compiling to a native binary (Windows PE / Linux ELF) or do you need a language runtime environment? And if the latter, what's the likelihood of the target OS having said framework pre-installed?)
I'm not trying to take anything away form Javascript / Node, but it loses as many points as it wins. And frankly both languages fail compared to some other languages too.
Personally I mostly target Linux and FreeBSD, but the majority of my Go tools will compile for Windows with zero code changes (the standard Go libraries actually do abstract away most OS specific discrepancies) and all of my code works on Linux and FreeBSD without any Linux / BSD specific code. So I think the issues of different files for different OSs is overstated anyway.
I didn't argue anything about performance. Go might have better performance than Node.js, but that doesn't make Go better for cross-platform distribution! They are separate factors. If performance is your top priority and Go has better performance than Node.js then choose Go while acknowledging that it's possible that Node.js has better cross-platform code distribution support.
>user interface
I didn't make any arguments about that either.
>required runtime environment
Now that's relevant when it comes to cross-platform distribution. Node.js has that covered pretty well.
>I'm not trying to take anything away form Javascript / Node, but it loses as many points as it wins
My comment was not about Node.js vs Go as a whole, it was about developing cross-platform software.
>So I think the issues of different files for different OSs is overstated anyway.
If you look at the core issue here, it's that theoretically speaking "all things equal" Go and Node.js needs about as much work to implement a new feature that works with most platforms. However, on top of that Go requires a compilation step for every supported platform, and that's not required for Node.js.
However, Node.js requires someone to compile the Node.js environment for each supported platform. For most cases that's already done.
This is my core argument that Node.js does cross-platform development better. It's one of the things that Java and C# got right.
"This is my core argument that Node.js does cross-platform development better."
Your argument is theoretical. In practice, people are finding Go apps easier to deploy. Reality trumps theory.
Why is reality trumping theory? With Go you one artifact, the executable, which runs on its own and you're done. With Node, you don't and you're not done, and even with the incredibly minimal bit of Node stuff I've touched (keybase.io, one of the minifiers), I still had to fight with Node to get it to run. Sorry, this one is easy to objectively call: Go produces artifacts that are easier to deploy. It doesn't matter how you try to talk around that fact, it simply is not the case that you ship one file with Node and are done; that is at best the best case when all the stars align and the wind is at your back.
javascript requires you install Node on your target platform alongside your Javascript program, where as Go doesn't. So the extra step you described gets equalled out.
as I said, it's very naive to blanket claim that node is better for cross platform development.
If I'm completely honest, i find people who say languages are definitively better at boardly defined subjects are usually lacking objectivity. Programming can seldom be summarise so easily without losing all precision.
> That sounds like it's actually very difficult to support multiple operating systems. As a developer I never, ever want to write any OS-specific code.
You may not, but if you want something to work on multiple platforms that someone else has not abstracted, you have to do it anyway. When you do, you may want something more orthogonal than cpp macros.
That sounds like it's actually very difficult to support multiple operating systems. As a developer I never, ever want to write any OS-specific code. Sure, that's sometimes required, but saying that the solution is to have multiple files, each for a single OS, doesn't sound good. It's a lot better to abstract the OS away. Node.js does this quite well. Seemingly a lot better than Go.
Besides, Node.js doesn't need to be compiled for each system. This alone makes Node.js better for writing code for multiple operating systems.
>Go is a compiled language so distributing applications for use on multiple platforms is just easier.
I disagree. You need to compile to code for every single platform, making code distribution costly. With Node.js you can simply distribute the code as it is and it probably works in any platform. (The probability is as high as it is for Go assuming no extra work for a new platform). Sure, each platform needs to have Node.js, but Node.js is supported in most platforms.