LoginSignup
17
9

More than 5 years have passed since last update.

Node.js to Golang

Last updated at Posted at 2017-12-15

Node.js to Golang

Node.js から Golang へ

This article talks in brief about the experience in developing web applications using JavaScript(Using Node.js based Framework) and Golang.
本記事ではJavaScript(Node.jsベースのフレームワーク)とGolangを使って、Webアプリケーションについて開発した経験について簡単に紹介します。
The conclusions I draw here are my personal opinions and I am quite sure there are other developers out there who will think differently about these technologies.
ここで述べる結論は個人の意見によるものであり、他の開発者の皆様は違った考えを持つと思います。

As the title of this article Node.js to Golang indicates, there are issues with Node.js that developers face, which leaves them frustrated and in search for other languages/frameworks solving those issues. Lately, there have been a lot of criticism about using Node.js in high-performance networked applications. This has lead to many developers switching to Golang.
タイトルが示すように、Node.jsを使って開発すると、開発者いくつかの課題に直面し、他の言語/フレームワークを使って解決しようとします。最近では、Node.jsを使ってハイパフォーマンスなネットワークを経由するアプリケーションには多くの議論もあります。これらの要因から、Golangへ移る開発者も多くなってきています。


JavaScript and Node.js

JavaScript と Node.js

Javascript, is a high-level, dynamic, weakly typed, prototype-based, multi-paradigm, and interpreted programming language.
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. V8 is Google's open source high-performance JavaScript engine, written in C++ and used in Google Chrome, the open source browser from Google, and in Node.js, among others.
JavaScriptは、高レベルの・動的な・型が弱く・プロトタイプベースで・マルチパラダイムである・インタプリタ型の性質を持つ言語です。Node.jsは、Chrome V8のJavaScript実行エンジンとして使われています。V8とは、オープンソースでハイパフォーマンスなJavaScriptエンジンで、C++で書かれており、Google Chrome(Googleの開発するOSSのブラウザ)などで使われています。

Javascript is a dynamically-typed language and hence is a much easier learning curve. As Node.js is written in JavaScript, it inherits most of the properties of that language. JavaScript is so popular these days that the ECMAScript standard development is done at a very rapid pace.
JavaScriptは、動的な言語であり、学習曲線はかなり緩やかです。Node.JSはJavaScriptで書けるため、多くの特徴を継承しています。JavaScriptはかなり人気があるので、ECMAScriptの標準も高速なペースで進んでいます。

This has some negative effects for JavaScript and Node.js development:
JavaScriptとNode.jsの開発にはマイナス面もあります。
- It often causes issues relating to backward-compatibility.
- Rapid development can lead to a messier language design compared to languages that integrate features cleanly into their design. A good example of this is concurrent computing with JS. JS best practices for concurrent computing went from a concurrency API (using event-based callbacks), to the development of promises, to the coming support for async generators. These days callback hell is still a serious issue with many Node.js applications. This in turn causes less slower developer progress and a lot of bugs.
- 後方互換で課題が生じることがあります
- 言語が高速な進化は、他のクリーンな設計の言語に比べるとやや、乱雑になることがあります。良い例は、JSを利用した並行プログラミングです。JSの並列処理の方法は、コールバック、Prosise、Asyncといったように進化しています。Node.jsを用いた場合に、いわゆるコールバック地獄がまだ残ることもあります。結果的に、バグが多く・開発が遅くなることもあります。
But even with these issues, JS still has a huge user base. A lot of great applications are built everyday with Node.js.
一方でこれらの課題がありつつも、JSは依然として多くのユーザを持ちます。多くの素晴らしいアプリケーションが、今でも開発され続けています。

Golang

Go is a programming language created at Google[12] in 2009. It is a compiled, statically typed language in the tradition of Algol and C, with garbage collection, limited structural typing, memory safety features and CSP-style concurrent programming features added.
Golangは、2009年にGoogleが開発した言語です。コンパイル型、静的 型付(Algol/C)、GC、制限された構造型、メモリ安全性、CSPスタイルの並行プログラミングなどがGolangの特徴です。
Go makes it much easier to write robust, networked applications, without sacrificing much in the way of performance, compared to C or C++.
Golangは、より堅牢・ネットワークを利用するアプリケーションを容易に書けます。さらにC/C++に比べてパフォーマンスも悪くありません。
Go improves upon some of the misgivings of those languages:
Golangは、他の言語が持ついくつかの懸念を払拭しています。
- Poor dependency management
- Cumbersome type systems
- Difficult memory management
- Lack of parallel computation support
- Lack of multi-core support
- 貧弱な依存性管理
- 面倒な型付け
- メモリ管理の難しさ
- 並行処理の欠如
- マルチコアサポートの欠如
Go also reduces the amount of code typing needed by being more expressive than C or C++.
Golangはまた、C/C++に比べるとコード量も少なくてすみます。

The high performance is in large part due to the static compilation of the statically-typed Go code. A lot of optimizations are possible when a compiler can do all the code inspection work beforehand, as opposed to the dynamic JS compiler work done during runtime.
これらの高性能は、Golangの型付けがある静的なコンパイルによるものが大きいです。前もって多くのコードのインスペクションをコンパイル時にしておくことで、最適化を実現しています。これは、実行時に実施しているJSの動的な性質とは反対です。


Node.js vs Golang

Although Go and Node.js have their differences when it comes to which programming paradigms they enable to be easier, they both have unique and supportive followings. One area where Node.js outshines Go is in the sheer size of their package library and community. Node.js package manager (NPM), the largest package registry in the world, has over 410,000 packages growing at an alarming rate of 555 new packages per day. That number may seem staggering (and it is), however, something to keep in mind is that many of these packages are redundant and/or non-production quality. In contrast, Go has about 130,000 packages.
GoとNode.jsは、プログラミングパラダイムについて考えると違った側面を持ちます。どちらも、ユニークで指示されるような以下の特徴を備えています。Node.jsがGolangより優れている点は、単にライブラリ/コミュニティの数が多い/大きいという点です。Node.jsのパッケージ管理であるNPMは、世界でも最大のパッケージレジストリで、410,000のパッケージがあります。さらに、毎日555の新しいパッケージが増え続けています。とても多くて驚愕するかもしれませんが、冗長でまだプロダクションで使うには難しい品質のものもある点に注意ください。対象的にGolangは130,000のパッケージがあります。

Although Node.js and Go are around the same age, JavaScript is more widely used — boasting a large development and open-source community. This is of course because Node.js was developed for the general public with a robust package manager from the start while Go was specifically built for Google.
Node.jsとGolangと年齢はほぼ一緒ですが、JSの方が広く使われています。これはNode.jsがもともと強力なパッケージ管理システムと共に、最初から育ってきたのに対し、GolangはGoogleで開発されてきたためです。

Node.js Go
Performance Due to JS's dynamically-typed nature, Node.js can not reach the raw performance of CPU or memory bound tasks that Go can achieve in many tests. However, in the common use cases where network communication or database interaction are involved, the performance of Node.js and Go are often equal. Similar performance characteristics as with C or C++, which is to say very good.
Concurrency Node.js suffers from JavaScript's less than elegant concurrency support using the event-callback mechanism. However, for a lot of applications, working with JS promises and the coming async generator support. Go uses coroutines called goroutines. A goroutine is a lightweight thread managed by the Go runtime. Communication between goroutines is done very elegantly using channels.
Scalability Node.js was never created to solve the compute scaling problem. It was created to solve the I/O scaling problem. Any CPU intensive computation will block Node.js responsiveness, so a threaded platform is a better approach. (* By Node.js Foundation) Go was really designed for scalability and concurrency, without too much hassle.
Ease of Development For a JS developer, it is really easy to get into Node.js programming. People coming from a JS/Node.js background will need to learn some new programming concepts, such as: coroutines, channels, strict typing (with compilation), interfaces, structs, pointers, and some other differences.
Node.js Go
パフォーマンス 動的型付の性質より、Node.jsはGolangよりCPUバウンドやメモリバウンドなパフォーマンスで劣ります。しかし、ネットワーク/データベースを使う処理が含まれるアプリケーションの場合、Node.jsやGolangのパフォーマンスはほぼ同様です。 C/C++と同様で非常に良いです。
並列性 コールバックを用いる処理の場合は、エレガントな並列処理のサポートとは言えません。しかし、多くにアプリケーションではPromiseおよびAsyncでよりエレガントに書けます。 Goはゴールーチンという仕組みを使います。ゴールーチンは、Goのランタイムに管理される軽量スレッドです。ゴールーチン間のコミュニケーションは、チャネルによってエレガントに実現されています。
スケーラビリティ Node.jsは計算処理のスケーラビリティの課題を解決するようには、デザインされていません。どちらかというと、I/Oのスケーラビリティ課題を解決することに狙いを置いています。CPUインテンシブな計算処理は、Node.jsの応答性をブロックすることがあります。その場合は、スレッド処理の方が良いアプローチになるでしょう。(* By Node.js Foundation) Golangはスケーラビリティと並列性向けに非常に適しています。
開発の簡単さ JSの開発者であれば、Node.jsのプログラミングを始めるのは簡単です。 JS/Node.jsをバックグランドに持つ開発者にとっては、新しいプログラミングコンセプトを学ぶ必要があります。たとえば、コルーチン・チャネル・型付け(コンパイル)・インターフェース・構造体・ポインタなどです。

Conclusion

結論

This post is not to prove that one language is better than another. Every programming language has its place in the software development community for one reason or another. The intentions were to highlight the differences between Go and Node.js, as well as promote exposure to a new web development language. When choosing a language for a given project, there are a lot of different factors to consider including developer familiarity, cost, and practicality. I encourage a thorough low-level analysis when deciding what language is right for you.
本記事は、どちらが良いかを証明するものではありません。全ての言語は、かならず何かしらの理由・向き不向きがあります。本記事の狙いは、GoとNode.jsの違いを明確にすること、また新しいWeb開発言語として利用を広めるのが狙いです。特定のプロジェクトの言語を選定する場合、多くに要素を考える必要があります。例えば、開発者フレンドリーであるか、コストはどうか、実際に使えるかどうか、などです。実際に決断される場合には、さらに詳細な調査をオススメします。

As we have seen, there are several benefits to Go. The raw performance, simple syntax, and relatively shallow learning curve make it ideal for scalable and secure web applications. With its fast growth in adoption and community involvement, there is no reason Go can't become a prominent player in modern web development. That being said, I believe that Node.js is moving in the right direction to remain a powerful and useful language if implemented correctly. It has a large following and active community that makes it a simple platform for getting a web application up and running in no time.
これまで見てきたように、Golangにはいくつかの利点があります。パフォーマンス、簡単な構文、比較的ゆるやかな学習曲線は、スケーラブルで安全なWebアプリケーション開発を可能にしてくれます。コミュニティを含むその成長のスピードにともなって、GolangがモダンなWeb開発において、卓越した地位を築くのは間違いないでしょう。とは言うものの、Node.jsが正しく成長していく・実装されていくのであれば、強力で便利な言語であり続けるという点も確認しています。多くのアクティブなコミュニテイがあるので、簡単にWebアプリケーションを動かし続けることができます。

17
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
9