Is there any reason to choose Node/iojs over Go?

agolangf · · 931 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Don&#39;t get me wrong, iojs is a cool project. But as far as I can tell Go does about the same thing as iojs without callback hell and dealing with an interpreted language. </p> <p>I haven&#39;t studied either of these all that intensively. This is just what it seems like to me. </p> <p>When would you choose one over the other? </p> <hr/>**评论:**<br/><br/>albatr0s: <pre><p>No, there is no reason.</p></pre>ThisAsYou: <pre><p>That&#39;s what I keep coming too.</p> <p>With Go out of the picture, iojs is awesome. I&#39;m also glad they both exist (competition!) but Go seems vastly superior.</p> <p>Only downside is there isn&#39;t a new framework for Go every other second... /s</p></pre>hoffentlich: <pre><p>Go will offer you a superior development experience.</p></pre>Saucysauce: <pre><p>Well, I think the best answer (for you) is : Go try both!</p> <p>For me, I use Go for systems stuff, and Node for stateless services and web stuff. But I&#39;m using Go for more and more services and Node just for web stuff. Eventually, I&#39;ll probably just be using Go.</p></pre>ThisAsYou: <pre><p>I&#39;ve used both a little. I&#39;ve made a url shortener in iojs, and played some with Go (haven&#39;t had much time this semester :/)</p> <p>Anyway, Go has a much better coding experience (code completion is great for shitty programmers like me :p) Sure TypeScript is a thing, but then it&#39;s still JS in the end. The thing about Go is it&#39;s compiled. ONE binary to deploy. It&#39;s also faster, which can make a big difference with large-scale deployments.</p></pre>Saucysauce: <pre><p>Well, I might not completely agree with your reasons for choosing Go, but I think Go is a sound choice :) Honestly, I&#39;d pick anything and invest in it more. It&#39;s hard to go wrong being a polyglot programmer.</p></pre>ThisAsYou: <pre><p>I didn&#39;t choose it JUST because I wanted code completion. That was just a nice touch.</p> <p>The main reason I&#39;m leaning towards it is because it seems like it would scale better, and have better performance per-node compared to Node.</p> <p>When I&#39;m paying for servers to host my projects, I want to get the most per $ as I can. So that&#39;s why I&#39;ve been looking at Go after learning a bit of Node.</p></pre>Saucysauce: <pre><p>Agreed, sorry, wasn&#39;t meaning to imply your choice was simplistic :)</p> <p>Well, performance is super-complex. Personally, I focus on time-to-deliver the project, then I optimize. But it&#39;s good to know <em>you can optimize</em>, and I&#39;d say Go is better for that.</p></pre>ThisAsYou: <pre><p>Time-to-deliver is certainly an important factor. But with personal projects you have a lot more flexibility, which is the situation I&#39;m in.</p> <p>I currently have a url shortener in &#34;production&#34; at work which is using iojs. It works and all, but I really want to rewrite it in Go, especially since Go is much faster. That and my callback mess makes me feel disgusted :p</p> <p>Go&#39;s easy concurrency and parallelism is really cool to me. Being able to spawn a goroutine for every request and have concurrency without callbacks is awesome. Oh and don&#39;t forget.... SINGLE BINARY to deploy!</p> <p>Being able to go back to deploying a binary after messing with scripting languages and things like Java is really refreshing.</p> <p>At first Go seemed really lame to me after getting used to OO in C#. But after learning some node OO doesn&#39;t seem quite as important.. </p></pre>Saucysauce: <pre><p>Ahhhh, well yeah, for personal projects, do whatever seems interesting :)</p> <p>As an &#34;old timer&#34; (does 2 decades of programming make you an old timer? I feel like one), I will say that I was gung-ho about OO and used to be a bit of a bigot about objects in general. Age and wisdom have taught me that everything has it&#39;s place, and very few things are universal, so I totally agree that OO isn&#39;t as important as others may tell you.</p></pre>ThisAsYou: <pre><p>That said, OO can definitely be good for something. But as you say, there is no one size fits all in programming. </p></pre>Saucysauce: <pre><p>Absolutely. I still think OO is great for many applications (or applications that have only one view of their data model). But system-level work? Go is better.</p></pre>iends: <pre><p>This comment makes zero sense. </p> <p>Go is an object oriented language. </p></pre>JuicyMeJacKanoff: <pre><p>I was in a similar position, go go and you won&#39;t ever go back!</p></pre>ThisAsYou: <pre><p>That&#39;s what I&#39;m thinking :) What made you choose Go at the time?</p></pre>xsolarwindx: <pre><p>Yes, if you need to complement your thick glasses, scarf, starbucks coffee and macbook pro while looking like you&#39;re doing something useful.</p></pre>ThisAsYou: <pre><p>I don&#39;t get it? I don&#39;t have any of those things...</p></pre>nerdwaller: <pre><p>I think they are joking that Node is vogue, and hipster types are stereotyped to do all those things.</p> <p><em>edit</em> I think I took you way too literally. Just got out of a long meeting about boring things. My apologies.</p></pre>ThisAsYou: <pre><p>No you&#39;re good. I took him too literally (I get the joke now.)</p> <p>For some reason I thought I asked why you would use Go over iojs, meaning he was making Go the hipster language, so I was confused (as I see Go as a better language without much bias yet.)</p> <p>I should really go to sleep earlier... </p></pre>nerdwaller: <pre><p>I could see where that could be the interpretation, arguably Go could be considered more hipster, but not sure I want to go down that rabbit hole of labeling things just to do it.</p> <p>Go is great, node has uses as well. I personally prefer statically typed back ends, though I do have a Node server up so others in my small organization can contribute.</p></pre>ThisAsYou: <pre><p>You&#39;re probably right, Node deffinitly has more traction....</p> <p>But anyway, I do tend to agree with you on static typing. While working with iojs, I ran into a LOT of undefined vars because of my compile time checks (which I&#39;m sure could be motivated by linters or even TyoeScript) but having real static types is really nice. </p></pre>010a: <pre><p>Ironically it seems like, nowadays, Go has begun attracting the vogue hipster types. </p></pre>nerdwaller: <pre><p>Agreed, it&#39;ll always happen with something new that is good, the real problem is when people flock away from something good just because it&#39;s too &#34;hipster&#34; or for that matter too &#34;mainstream&#34;</p></pre>ptman: <pre><p>Go json encoding is apparently a bit slow because of the amount of reflection. If you do lots of json encoding/decoding, iojs may perform better</p></pre>ThisAsYou: <pre><p>Source?</p> <p>That is unfortunate if it&#39;s true. But surely it would get better in the future right?</p></pre>dgryski: <pre><p>If you&#39;re encoding/decoding known types there are faster ways to use json. Go&#39;s code generation tools make it easy to construct packages like <a href="https://github.com/pquerna/ffjson" rel="nofollow">https://github.com/pquerna/ffjson</a> which are 2x-3x faster than using reflect. There are other serialization options that are even faster depending on your use case: <a href="https://github.com/alecthomas/go_serialization_benchmarks" rel="nofollow">https://github.com/alecthomas/go_serialization_benchmarks</a></p></pre>Effetto: <pre><p>The only cool feature of the &#39;server-side javascript&#39; thing is that it opens the gates of isomorphic applications but I have yet to see actually usage of it in serious +mid-size applications.</p></pre>ThisAsYou: <pre><p>PayPal and Netflix are pretty big.</p> <p>I still think Go is better, but Node is definitely in large-scale production use.</p></pre>Effetto: <pre><blockquote> <p>PayPal and Netflix are pretty big.</p> </blockquote> <p>I was referring to the isomorphic feature. Yes node.js is large-scale ready itself.</p></pre>ThisAsYou: <pre><p>I&#39;m completely blind today apparently <em>sorry.</em></p> <p>What are these isomorphic features you speak of? What does that do?</p></pre>docsavage: <pre><p>Here&#39;s an <a href="http://nerds.airbnb.com/isomorphic-javascript-future-web-apps/" rel="nofollow">article on isomorphic javascript</a>, and I agree with the Effetto -- the only reason I&#39;d use node/iojs is for isomorphic apps, probably in React world. You could also remove running your own server like Google AppEngine and go with <a href="http://aws.amazon.com/lambda/" rel="nofollow">Amazon Lambda</a>. Lambda may allow non-javascript executables now, but initially it was focused on server-side javascript.</p></pre>ThisAsYou: <pre><p>Okay that is pretty cool. </p></pre>mwholt: <pre><p>I was going to say that with Node you don&#39;t have to worry about memory synchronization but that&#39;s not entirely true all of the time, even though Node is single-threaded.</p></pre>ThisAsYou: <pre><blockquote> <p>Node is single-threaded</p> </blockquote> <p>Another thing that makes Go better...</p></pre>thraxil: <pre><p>I would only chose node/iojs if there were some existing domain specific JS library that I could leverage by putting a thin web shim on top of it and that would be very difficult and time consuming to port to Go. Even then, I&#39;d try to contain that to as small a microservice as possible and build the rest of the system in a better language.</p> <p>Other people seem to choose node because they already know JS, like it, and want to get something running without learning a new language for the server side. Fair enough.</p></pre>ThisAsYou: <pre><p>Yeah for current JS people, I can see it being appealing. But for anyone looking to use a new language, Go seems far superior. </p></pre>dpa: <pre><p>Node developer here. I would use node for web apps. Express is great, the stream pattern is insanely useful, ecosystem is vibrant. Add in promises, generators or use highland.js to avoid callback hell and node may become fun and fast to code in. </p></pre>ThisAsYou: <pre><p>Node/iojs definitely has a much larger web-ecosystem. But you can use something like React with Go.</p> <p>Something I don&#39;t like about JS is how there is a new framework every other day.</p> <p>Node is great, don&#39;t get me wrong. But as someone who is still in the learning phase, Go seems like a better language in general. Hopefully Go will get some good web frameworks though...</p></pre>afrobee: <pre><p>This a <a href="http://www.reddit.com/r/programming/comments/32jn2a/gotchas_from_two_years_with_node/cqc2hq5" rel="nofollow">great insight</a> about Nodejs true nature that one should consider commented by u/jerf</p> <blockquote> <p>Node is fundamentally cooperatively multitasking. We got rid of cooperative multitasking decades ago in our OSes, and apparently we raised a generation of programmers so unaware of the issues that not only did they embrace a cooperatively-multitasking environment on their server, of all places, they actually thought the cooperative multitasking was a feature and some sort of step forward.Further, observe this is not some sort of political statement or something that can be dismissed with more rhetoric. This is simply a truth... Node is cooperatively multitasking. Cooperative multitasking has serious, extremely-well-known problems with tasks causing other tasks to have resource starvation. It turns out these people hit those problems. These problems are really, really hard to solve in a cooperatively-multitasking environment... you can mitigate them but you can not solve them. We know this because trying to mitigate the issues with cooperative multitasking is not some sort of new computer science problem that just emerged in this brave new Node world for the first time ever, but something that entire major programming communities grappled with for decades without ever solving, including but not limited to the entire Apple programming community prior to OS X, which I&#39;ll remind you is properly pronounced &#34;OS Ten&#34;, as in, 9 entire major versions preceding that with people trying to deal with this problem. The shocking thing is not that there are very solid, time-tested reasons to think carefully about Node... the shocking thing is that these reasons are considered &#34;controversial&#34;.</p> <p>Node is a technology stack based on a language originally designed to animate things when a button was clicked (and I&#39;ll remind you, that&#39;s also not slander, that really is the origin of Javascript) that developed into a very well-understand dynamic scripting language with well-understood issues, using very old software techniques that have problems that are very, very well understood. The fact that these problems are in fact very well understood means that you may still find use cases where you can use this tech... &#34;well-understood problems&#34; is actually a good thing!... provided you do in fact understand them, which can not be done by trying to go up to the code and argue it out of having these problems, much less trying to argue them out of existence by debating with people.(It is so weird to me watching people trying to defend Node on this point. It&#39;s not like when Rust comes out with a new feature and people dismiss it with &#34;Oh, someone wrote a paper on that in the late 1960s and implemented it in some obscure Lisp variant that died, so p&#39;shaw on your claims of newness&#34;... the Node scheduling paradigm was one of the dominant mainstream schedulers for decades at a time. It&#39;s not news! It&#39;s not something we have to wonder about what could possibly happen... we just open the history book, and there it is.)</p> </blockquote> <p>The OP post on this thread also have some of the gotchas and why the OP change from Node to Go</p></pre>icholy: <pre><p>If I was at a hackathon or writing a prototype, I&#39;d probably use node.js because it&#39;s easy to bang something out quickly and there are tonnes of packages.</p></pre>ThisAsYou: <pre><p>Fair enough. What would you choose for production?</p></pre>icholy: <pre><p>I&#39;m using Go in production right now and it&#39;s great.</p></pre>ThisAsYou: <pre><p>At what scale?</p> <p>Would you want to use it in large-scale productions?</p></pre>iends: <pre><p>I rewrote a production node 0.10.x service in Go and got a 10-30% performance increase. </p> <p>I rewrote a production db migration tool in Go and had approximately the same performance as the node 0.10.x version (probably because core node db stuff was c++) but I had much better type safety guarantees with Go. </p> <p>YMMV. </p> <p>Sadly my company is afraid of Go and used neither. </p></pre>jordic: <pre><p>Keep calm and leave javascript for the browser.</p></pre>metamatic: <pre><p>My perspective as someone who isn&#39;t wild about Go, and writes server-side JavaScript most days:</p> <p>No. Hell no. If you can use Go, you&#39;d be mad to choose JavaScript instead.</p></pre>ThisAsYou: <pre><p>This is the vibe I&#39;ve been getting. Could you expand on your reasoning? </p></pre>metamatic: <pre><p>While I&#39;m generally fine with dynamic languages (I like Ruby, for example), JavaScript has enough pitfalls that I fall into them on a regular basis. The server environment I&#39;m working with is slow enough to deploy to, and ugly enough to debug in, that it&#39;s a real win to catch as many bugs as possible at compile time. While there are tools like jshint, they aren&#39;t as robust as a compiled and statically checked language. So I end up writing as much as I can in a compiled language (in my case, Java, since I&#39;m in a JSF-based world), and then using the bare minimum of server-side JavaScript to glue things together. The thought of having to face debugging race conditions in the middle of a callback in a node.js application makes me realize how good I&#39;ve got it.</p> <p>Client side it&#39;s a different story, as tools like the Chrome developer environment make JavaScript debugging pretty easy, so long as you stick to VanillaJS. I&#39;m not anti-JavaScript, I just find it horrible on the server.</p></pre>ThisAsYou: <pre><p>What are your most common pitfalls with JS? </p></pre>metamatic: <pre><p>Mostly the lack of type checking means that trivial errors, such as forgetting when a singular property is returned as a vector rather than a scalar, result in crashes. Also, nulls have a tendency to propagate beyond their immediate cause and result in unexpectedly empty values elsewhere.</p> <p>Also painful is the narrow choice of data types — no true integers, no trees, and so on.</p> <p>So generally I write as much as possible in Java, get it to run and pass all the unit tests, and only then bring the jar file into the server environment and write the JavaScript glue code. The interface methods dumb down values to strings or doubles, but internally more appropriate types are used.</p></pre>Raiyni: <pre><p>You can scale go much better and it is simple. </p></pre>ThisAsYou: <pre><p>In addition, it seems like Go wouldn&#39;t require as many servers due to the better speed of not being interpreted. Which translates to less servers and lower costs.</p> <p>So for a new project, especially if you want to scale, Go seems like it&#39;d always be better...</p></pre>quiI: <pre><p>I wouldn&#39;t pick a language based on whether it&#39;s interpreted or not, 9/10 your performance concerns are going to have little to do with your language choice. </p></pre>ThisAsYou: <pre><p>Interpreted languages are usually slower in general. So an optimized Go app will be faster than an optimized Node app.</p> <p>When you have a choice in what language you&#39;re going to learn and use, why not go with the one that can go faster when optimized without too much extra dev time?</p> <p>In addition, deployment is easier because you can build a single binary with Go. With iojs you need to also maintain the iojs version. Granted, Docker mitigates this issue. But being able to deploy a single binary is a lot easier and better IMO. </p> <p>I&#39;m not saying &#34;everyone ever should use Go.&#34; I just think if you have a choice and no reservations for either language, Go is better. </p></pre>010a: <pre><p>One thing you need to keep in mind is that, while Go might be more performant (please stop using the word &#34;faster&#34;) under most workloads, if your system ever communicates with an off-machine database then that communication is guaranteed to be the slowest aspect of both a Go and Node system. </p> <p>There are plenty of benchmarks which say &#34;look at this, I wrote a simple HTTP server and Go can serve 10,000 req/s where Node only serves 200&#34;, but the moment you have either of those machines talking to Postgres or Mongo I guarantee both of those numbers will drop to 100-300. </p> <p>And this just reinforces the point that most people in these discussions seem to forget: Good programmers use Node for io-heavy workloads. It isn&#39;t good for compute workloads and thus really isn&#39;t comparable to Go in a lot of domains. That doesn&#39;t make it bad or worthless, it just makes it specialized. </p></pre>quiI: <pre><p>I dont know much about Iojs, but I&#39;ve used <em>other</em> interpreted languages. </p> <p>My point was, almost no one picks languages based on what executes fastest; at least, usually it should be low down on your priorities. Otherwise we&#39;d all write assembly. People pick languages on a variety of factors such as the ones you&#39;ve mentioned but also others. </p> <p>You aren&#39;t considering how interpreted languages <em>can</em> be more expressive and easier to write than Go. </p> <p>Don&#39;t get me wrong, I love Go. But I wouldn&#39;t use Go in favour of say Scala for a lot of problems. Is that because I think higher kinded types are <em>vital</em>?. No, it&#39;s all about tradeoffs. And If i am hacking together a proof of concept i am tempted to use a lightweight interpreted language to get it done. </p></pre>ThisAsYou: <pre><p>That&#39;s why I am advocating for Go rather than C++ :p</p> <p>For prototypes though I agree, use whatever you can hammer out fastest. </p> <p>Edit: really though, I don&#39;t know enough to make any decent arguments / assertions for Go. </p></pre>010a: <pre><p>This is a really uninformed and simplistic comment.</p> <p>Scaling projects in either language is equally easy. The general way of scaling is to horizontally spin up new instances which sit behind a load balancer. You can do this with anything that supports HTTP and its 100% transparent to the language itself. </p> <p>Scaling is <em>cheaper</em> with Go because generally speaking Go is more performant, sometimes by an order of magnitude. So what might take 3 node machines could be done with a single Go machine. </p> <p>A correct statement is that you scale Go much more cheaply, not easily or &#34;better&#34;. </p></pre>Raiyni: <pre><p>You are right, the correct term definitely would have been cheaper. Cheaper doesn&#39;t always equal better but when plenty of companies are switch from node/ruby/python to go for performance reasons does that indicate something? But you really only start noticing those problems when you reach crazy throughputs. An example would be twitter going from RoR to Scala (sure RoR has better scaling now). </p></pre>010a: <pre><p>Companies which run into performance problems or huge costs with things like Python, RoR, or Node are kind of what I refer to as the &#34;1%&#34; workloads. There are <em>many</em> top 50 websites which run on these languages. For example, Yelp is totally Python and Ebay and Paypal are almost totally Node. These languages work fine for them. </p> <p>So while Go is undeniably faster, I don&#39;t really respect that argument for the language because the only people who are going to care are core engineers at Google or Facebook, and those people are probably using C++ anyway (or, in Facebook&#39;s case, PHP). The cost advantage that additional performance offers is also not half as expensive as the billable hours wasted finding or training Go engineers for most other companies.</p></pre>Raiyni: <pre><blockquote> <p>(or, in Facebook&#39;s case, PHP)</p> </blockquote> <p>It&#39;s Hack now, which is basically php still.</p></pre>ninja_uzumaki: <pre><p>I think if you want to prerender a javascript application on the server side, you should go with Node/io js. For anything else, I prefer Go.</p></pre>ThisAsYou: <pre><p>Why not just use something like <a href="https://github.com/olebedev/go-react-example" rel="nofollow">React with Go?</a></p></pre>EstebanVelour: <pre><p>The node ecosystem is really, really worth learning no matter what server-side language you use. Tools like gulp/grunt have become the makefiles of js &amp; css and will simplify your life immensely.</p></pre>Bromlife: <pre><p>I use Gulp &amp; Bower with Go. As long as they&#39;re controlled from within Go, it&#39;s not a big deal. But man oh man do I hate having to write in NodeJS. Even for the Gulpfile.js - so many callbacks. So many, many callbacks.</p> <p>So badly designed.</p></pre>nerdwaller: <pre><p>Promises definitely decrease that feeling, but those can still lead to really hard to read stuff that just have promises for no real reason. It is nice to <em>at least</em> have it read better without needing to jump around so much (when done well).</p></pre>ThisAsYou: <pre><p>That&#39;s one thing that really made me look at Go. I hate <a href="https://d262ilb51hltx0.cloudfront.net/max/800/0*w-CuLtR8aUeLTMvq.png" rel="nofollow">callback hell</a> and I&#39;m really bad at staying out of it.</p></pre>010a: <pre><ul> <li><p>Writing Node is much faster. You don&#39;t have to deal with weird compiler requirements like unusued imports, variables, etc, all of which eat up the most valuable and expensive resource a company has: A programmer&#39;s time.</p></li> <li><p>Vastly superior package manager. NPM supports versioning, which alone makes it better than <code>go get</code>. </p></li> <li><p>Much more configurable build process in NPM, Grunt, etc than the fairly limited and black-box <code>go build</code> tool. If you try to do anything in Go outside of the <code>go</code> tool, you&#39;ll hit a brick wall and end up needing a makefile, whereas its possible to deploy everything you need in Node with Node, from the project to the build process to even the <a href="https://github.com/foreverjs/forever" rel="nofollow">auto restart system</a>.</p></li> <li><p>There are <a href="http://www.modulecounts.com/" rel="nofollow">many more packages</a> and third-party projects written in Node than in Go. </p></li> <li><p>The act of deploying a node application is at least as easy as a Go application, and can be vastly easier with tools like Heroku, of which none exist for Go. </p></li> <li><p>Go hits some performance bottlenecks when dealing with json marshaling due to its type system. </p></li> <li><p><code>$GOPATH</code>. Enough said. </p></li> </ul> <p>If your main concern with Node is that it doesn&#39;t offer good type safety, then you can always look at TypeScript, a product which is actually used by Google for Angular 2. And before you say &#34;but its really just JS in the end&#34;: Yeah, and Go is really just Assembly in the end, like everything else. TypeScript is essentially a zero-cost abstraction over JS. </p> <p>Pitchfork disclaimer: I like both languages. If you want me to list five things great about Go to prove it, I will. </p></pre>ThisAsYou: <pre><p>Unused imports could be fixed using goimports. Unused vars is still annoying though. </p> <p>You&#39;re other points are valid as far as I&#39;m aware. What do you like about Go? :) </p></pre>010a: <pre><ul> <li><p>Packages</p></li> <li><p>Its the performance and garbage collection of Java with the syntax of something like Python. </p></li> <li><p>Its statically compiled which makes deployment easier than something like Java or C++. </p></li> <li><p>The standard tools are the best in class among any language. It has a full build tool, dependency management, and testing suite all rolled up into one. It even comes with specialized tools like <code>yacc</code> builtin. </p></li> <li><p>The standard library is also best in class among any language. There is no other language that comes with full and sufficient implementations of http, json, zip, tar, compression, database drivers, image libraries... </p></li> </ul></pre>zero_coding: <pre><p>I want to prerender javascript application on the server side too and I think Golang is not the best choice for that. How your guys think about that?</p></pre>ThisAsYou: <pre><p>From what I can see, you&#39;re right. But you could always mix <a href="https://github.com/olebedev/go-react-example" rel="nofollow">React with Go</a></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

931 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传