Why I’m staying with Node
medium.com
medium.com
I don't think TJ wrote his post just for the sake of complaining or comparing Node with Go. He had a decision, and had to tell the community he was leaving because, you know, a lot of people uses his modules. I rely on a couple of his modules and I liked that he took some time to explain why he'll not be working on them anymore.
This post is no more interesting than blogging "I'll keep drinking my morning coffee.. Just as always."
The author correctly frames it as a personal decision in which tool to use for which job.
Ridiculously simple: Set out to hire a good programmer (as opposed to "a Go programmer"), and make it clear in the job description that they're expected to spend the first 6 months learning Go on the job.
You end up demonstrating to employees that you're willing to give them something useful, gain loyalty; AND end up with someone you can be confident is able to learn whatever else your company might need in the future, and writes better code by way of having a focus on programming knowledge, not language knowledge.
Nowadays either one has the right keywords on the CV or good luck.
Day 2-3: read Effective Go - http://golang.org/doc/effective_go.html
Take a whole week, if you feel it is necessary.
After that I had also read enough online to be familiar with the tools and the environment. Go is a really small language, but the ecosystem is rich.
You can have them try prototyping stuff on Go on the second week, trying some libraries, examining some existing Go code and that's it
There are good "XX" programmers, but I'd say that they're mostly good programmers and not tied to a specific language. Yeah, there are some niches where someone who's great at that niche may not be so good at other places (front-end, or maybe performance critical programming, or even things like COBOL or Java)
Of course like in everything you have different levels of expertise. But I can tell you first hand that most developers can be productive in Go within 2 weeks if not less.
Node makes SOA (service oriented architecture) a lot easier. SOA is what all the cool kids are moving to, and is one of the reasons why it's so easy for big companies with lots of legacy code to switch to Go. Once your code is appropriately partitioned into services, it's easy to write a single service in Go, and go is a nice language for writing services.
That being said, Node is particularly well suited for consuming services. You'll necessarily have lots of client code written to consume and use these services from your webapp. So whenever you write a batch job or notification system or anything else that is primarily server side consumption of services or glue between services, node.js is a natural fit.
The other natural advantage of Node is that your business logic can run on both the server and the client. Your standard client-side web app (angular, backbone, ember etc.) has the bulk of the business logic in the client-side models. On the server side, the corresponding models are mostly just shims to the database, but they will also contain some business logic. If your code is written in Node.js, you just instantiate the client side model to be access the business logic.
The other killer feature for node.js has already been mentioned: combining both server and client side rendering with https://github.com/rendrjs/rendr or https://github.com/wvl/highbrow.
But if you Google for running Backbone.js on the server, you get links for people running Backbone.js views (as well as models and collections) on the server. That's a little more involved, but the work has been done for you by frameworks such as rendr.
A good starting place might be: https://github.com/rendrjs/rendr-examples
I'm only familiar with Backbone. If your models are written in Ember or Angular or (?) instead of Backbone, I can't help you but would be very interesting in knowing how myself...
And to your list of isomorphic view frameworks I'd add React [0], which allows you to render server-side with almost no additional effort.
Furthermore I personally dont rely on anything to OP wrote, so wether he stays or leaves nodejs doesnt matter.
I think sharing code is dangerous as it tightens component coupling and makes architecture less flexible and more complex.
An average web project nowadays seems to be a back with many fronts: end-user website, admin interface, iOS app, Android app, Windows app… Making all fronts equal in their separation IMO keeps the architecture more predictable and easier to understand. Like DRY but with design decisions instead of lines of code.
Also, I don't see how you can be flexible without making API the only point of contact for your back(s). That way you don't lock yourself in and can rewrite any component with another framework or language, once requirements change sufficiently. I imagine it's much harder to do if you have everything in one Node project.
First, why. To your point about DRY but with design decisions instead of lines of code, that's how software development has always been; that's what the Gang of Four is. Isomorphic JavaScript allows you to literally not repeat yourself. You write code to solve a problem and you never need to worry about that problem again. Building a system that has every problem solved (at least) twice in (at least) two different languages is what makes architecture harder to understand, and more importantly maintain.
Ok, how. You create lots of little modules that each do one thing well. They declare their dependencies on your other modules, so it's actually much harder to introduce coupling between components. You use the modules appropriate to whichever part of the system you're building.
A practical example: you want to validate user input. You have a series of business rules that must be checked before you allow an update. Of course you want to check them on the client, so you can provide valuable feedback as quickly as possible. But you also must check them on the server, to prevent a wily user from circumventing your rules.
How do you architect this system? If you're sharing code, you just write a function to check the rules and call it in both places. If you're not, you end up reimplementing the rule in both places. But of course you'd like to at least share the rule definitions, so you end up writing the rules in JSON or something and then building parallel rule loaders in both places. Or if you're me you just give up and use Node instead.
If only that were true, but that's where my doubts are. You write:
> If you're sharing code, you just write a function to check the rules and call it in both places.
But you can only use that function if you can use Node on your front end. Most fronts today (native iOS apps, etc.) won't be able to reuse that function, and you'll have to reimplement it anyway.
I would only go with Node if I absolutely knew that incompatible front end won't be required for the project in foreseeable future—but I'd need to be a CTO to decide on that. Besides, what about when browsers get an additional runtime, with better tools than JavaScript? (Okay though, this one may not count as ‘foreseeable future’.)
I'd rather reimplement the function every time if I know I may need to reimplement it an unknown number of times. Perhaps in that case I'd try coming up with some language-agnostic specs instead so that validation function can be reimplemented on other platforms without breaking UX consistency.
Having to deal with a poorly-designed legacy weakly-typed scripting language not just on client (where you have no choice) but on server as well? Why be masochistic?
I find that javascript is most often an overused crutch on the client side, though. It's used more for premature optimization and making your website look shinier than it is anything really very useful.
Nonetheless, some webapps really do require a lot of it.
> It makes sense if your app flat out requires a lot of
> javascript on the client side.
Well, you can take a different look: spend some time thinking why does your app requires a lot of JavaScript, and is it really necessary. Even if the answer is still "yes" that may be a good exercise.The "alas" in this quote is sad. Sad to be using tools you hate.
1. the server can run the client code to render and serve HTML, so you get all the benefits of server side rendering as well as client side rendering. [1][2]
2. imagine you have an architecture that allows multiple clients to simultaneously modify a single document, like google docs, or like all your standard cookie-cutter enterprise form & report interface to records in a database database. Now imagine that you need to do some sort of batch operation to these documents. If your code is written in Node, you just run your client code on the server. Instead of directly manipulating the database from your batch workers, you use the standard REST & WebSocket API that your clients do. This is called a service-oriented code structure, and there are huge advantages to this; so big that everybody is switching to it. Node makes it almost free.
1: https://github.com/rendrjs/rendr 2: https://github.com/wvl/highbrow
Regarding the second point: if the client modifies the document through the API calls, who cares what technology is used to implement those API methods?
Operational transform algorithms for collaborative editing are a good fit for this. They are complex and have to run in both places.
Well, now I feel offended.
Let's go with metaphors. Programming languages and driving a car are similar things. When you change your car from Toyota to Audi, you don't learn everything from scratch. You just spend sometime to get used to the car (wheeling, brakes etc) and then you're all set. Programming languages are similar. When you switch from language A to language B, you don't learn programming from scratch. So, when you want to hire someone to code in Go, you just hire a developer and tell them they're going to code in Go. After getting used with Go, they would be all set.
You also need to develop a full understanding of the package/library/framework ecosystem, which can take years. This isn't transferable knowledge, either, but it's absolutely vital to understanding a language.
Knowing that requests is a great python library, for instance, and knowing when (and when not) to use it isn't going to help much when picking up Ruby, let alone something like Go or C.
I've seen good, experienced programmers pick up new languages and consistently step in the many of same traps that beginners do, simply because those traps aren't very obvious.
If a project requires expertise in a specific language then sure, shoot for "an X programmer" (there are very, very few of these in reality). Otherwise "a programmer" (who is good) will almost certainly be able to perform the job, and do it well, all other things (e.g. motivation, interest in actually using the technology in the project, etc.) being equal.
On the other hand language is an investment. Switching a language in the same paradigm is more like maybe learning a local dialect of dialect of English, new words, new pronunciation. Say you are moving to Australia from US, you might have that issue. But if you think it worthwhile it is an investment.
But that is for when the paradigm is the same. Object oriented, functional, dynamic types vs static types, logic programming, declarative (SQL) those are like different languages French, Spanish, etc.
Clojurescript + Om is a pretty nice combo for the browser.