6 ms·
Why I changed my mind about Node.js
- _jmar777 12y agoThere was a load error when I first clicked the link, resulting in a blank page. Was thinking "well played, punk".
- calebm 12y agoHa :)
- mmset 12y agoI had exactly the same experience! Can't agree more with the article.
- sramsay 12y agoThe thing that changed my mind about Node (and Javascript in general) was the discovery of lo-dash and Immutable. I really enjoy functional programming, and with those two libraries I feel like I'm writing in something approaching Clojure (but with less ceremony, faster startup times, a truly colossal user community/ecosystem, and less memory bloat). I never thought I'd say this about Javascript, but it clicks off more items on my dream-language list than anything else I've used (and I've used at least a dozen, across several paradigms). It's honestly fun to write in JS these days (at least for me).
- calebm 12y agoI didn't mention that, but I totally agree. Maybe it's because of the lack of good OO support, but people don't freak out when you do functional programming in javascript.
- sillysaurus3 12y agoWould you mind copy-pasting some example code? Ideally something similar to what you'd write in Clojure and solves some real-world problem? (The more code you can paste, the better.) I'm quite curious to see whether the claim is true about being able to write something approaching Clojure while solving real-world problems.
- erichmond 12y agoAgreed. We have both clojure and node services in production here and the use cases for each technology is quite different.
- sramsay 12y agoThe big Clojure use-case for me has been Java interop. Aside from that, I'm not sure I'd prefer it to node. Of course, I have no idea what your use-cases look like . . .
- sramsay 12y agoOkay: http://pastebin.com/r40TN3Ni http://pastebin.com/r40TN3Ni This is a small command-line program that I use to compute grades (I have larger stuff, of course, but this one is easy to follow). There are important differences between Clojure and Javascript (cum lo-dash and Immutable). Perhaps the most important overall difference is that Javascript is never mandating immutability -- you have to watch carefully (and I'm probably screwing it up a few times in that code). In fact, I just noticed a bad example of mutating state when I pasted it. :( I also use imperative constructs from time to time, but I like that I can. I originally wrote this code using JS's object system. I absolutely hated it (and I do understand prototypal inheritance quite well). What's more important to me, is that actually writing the code feels "lispy." In that code, you'll see all the classics (especially as you move down): each, map, range, zip, and compose (my favorite). Lo-dash, of course, has many, many more.
- k__ 12y agoFor me it was the discovery of LiveScript. You should look into it.
- hashtree 12y agoHeck yeah, be sure to also check out: - https://github.com/puffnfresh/bilby.js - https://github.com/fantasyland/fantasy-land - https://github.com/baconjs/bacon.js - https://github.com/kriskowal/frb - https://github.com/swannodette/mori - And essentially all things PureScript: https://github.com/purescript/purescript
- calebm 12y ago+1 for mori. Lovely Clojure goodness :)
- egeozcan 12y agoPureScript was something I've never heard of. Took me a few clicks to see some code though: http://docs.purescript.org/en/latest/intro.html http://docs.purescript.org/en/latest/intro.html The language looks good and it seems to be somewhat popular with more than 700 stars on GitHub. Thanks for the suggestion!
- hashtree 12y agoIt's an absolute dream come true for Haskell-ers. Doing server-side in Haskell and client-side/small services in PureScript is... just wow. Anyone in the Colorado area, we have quite a few amazing FP folks here (e.g. Brian McKenna) and there is a PureScript meetup Oct 1st: http://www.meetup.com/Boulder-Haskell-Programmers/events/199566292/ http://www.meetup.com/Boulder-Haskell-Programmers/events/199...
- sramsay 12y agoWow, thanks. I didn't know about fantasy-land and bilby. Hard core. That stuff is definitely getting you pretty close to Clojure.
- findjashua 12y ago+10 for bacon.js!! Edit: While I use it primarily for ajax, skipDuplicates and flatMapLatest are a godsend for building autocomplete
- abritishguy 12y agoI think the author is in the "honeymoon" period.
- freehunter 12y agoYeah, a repl, a package manager, and third party libraries are pretty standard for many languages. Even Lua has them. Non-blocking is nice, but the last one, I agree more on "the disadvantage is Javascript" than "but you only need to know one language!" I'm not a Javascript fan, speaking as someone who recently had to start developing in Javascript. I think it's a damn shame that this is the language that everyone picked to create the Web with.
- ioddly 12y agoIs there something special about node's REPL I'm missing? Just about every language has one. IPython is pretty snazzy.
- jaredmcateer 12y agoI have the impression that he didn't realize that Node had it and was surprised it did, not that the other languages don't typically have it yet Node does
- calebm 12y agoNothing special about it, but a REPL is almost a must for me. Python hooked me on them. (And I love IPython - especially IPython Notebook).
- crimsonalucard 12y agoArticles like these often imply how node is infiltrating the same space that JAVA takes up. Java to the best of my knowledge does not have a repl.
- untog 12y agoI work in JS all the time, but was still a little skeptical of Node until I finally grasped the concept of Promises (the Bluebird library being my preference). It took the callback-driven, event loop system from a liability to a huge bonus - running operations in parallel is so simple now, and error handling is a breeze. Can't recommend it enough. Now I'm spending my time writing view code that can run on both the server and client, allowing me to render the same stuff statically (for fast initial load and SEO) and dynamically on the client (for fast page changes).
- sillysaurus3 12y agoDo you happen to have any example code? I've had some bad experiences with "callback hell," so it's interesting to see that there are ways to prevent it from becoming a problem.
- jowiar 12y agoFor me, callback hell is a code smell - it means that I'm thinking imperatively and not, umm, eventedly. The general fix is to call something a component - give it a name and such, and have it fire some events that something else should listen to.
- untog 12y agoOne of my favourite parts of Bluebird is the 'Promisify' function. It allows you to take existing Node modules and use them as promises. Here's an example of interating over an array of files, only writing ones that don't already exist: http://pastie.org/9559209 http://pastie.org/9559209 It's also one of the reasons that I've ended up liking CoffeeScript more - Promises have a lot of function() and return statements, CS makes that kind of code a lot cleaner. For instance, that JS could be this short in CS: Promise.filter files, (file) -> fs.existsAsync(file).then (doesExist) -> !doesExist .each (file) -> fs.writeFileAsync(file.filename,file.content) .then -> Promise.map files, (file) -> fs.readFileAsync(file,'UTF-8') .then (fileContents) -> console.log(fileContents); ### Will return: [ "File 1 Content", "File 4 Content", "File 3 Content" ] ### .catch (err) -> # This will catch any and all errors that happened above.
- y0ssar1an 12y agotl;dr Other people are using it. It's less verbose than Java. It has a package manager and libraries. It has a REPL. I stopped worrying and learned to love callback hell. I didn't have to learn another language.
- jaredmcateer 12y agoThe article is not long enough to warrant a tl;dr even if such things were welcome on HN. Edit: my mistake, useless reddit joke posts are now welcome on HN, I missed the memo
- sz4kerto 12y agoOh, please, not that Paypal story again. Their legacy system was written on platform/language X, then Z years later, they have written another in language Y, and surprisingly, Y is faster! For Z>=5, this is going to be true for most of X-Y pairs because people learn from their mistakes, people know more about the requirements and pitfalls of their domain after having built the first version, etc. etc. Other than that, the article contains zero interesting information. Somebody had an uninformed opinion of Node.js, then changed that opinion because he heard some good stories, and now he convinces himself with funny arguments that he's right. (I had too many upvotes recently anyway :) ).
- calebm 12y agoIt was not ONLY the good stories, but the combination of things I listed. I work in the enterprise world, and the languages my company most often uses are Java and C#. I've been trying to push Python, but it has been difficult. Node has a lot of selling points which allow me to convince both management and other developers. I'm nearing the end of my first large Node.js project. I may do a retrospective after, but TL;DR - it hasn't disappointed :)
- antihero 12y agoWhat exactly is wrong with Java and C#? You can do amazing things with both. I'm a Python guy, and I constantly dislike the lack of static typing for back-end things in JS/Python.
- calebm 12y agoI don't prefer the verbosity of Java; I do like C# pretty well - it certainly has its place, but Node.js also has its place. My current project is a proxy between a modern web app and a legacy Java system; Node.js was a much better choice than either C# or Java for this use case.
- doorhammer 12y agoI'd be interested in an elaboration on why Node was a better choice than C# or Java. I don't mean that snarkily; I'm really interested. I work mostly in C# and actually feel pretty happy with it as a language (I've used Ruby and Java in other major projects, used to do a lot of my side hacking in Clojure, and I'm learning Haskell now). It's one of the more solid languages I feel that I've used, especially combined with LINQ and some other tools. Also was wondering if you had heard of SignalR in .NET, and if you had, what your thoughts on it are? I don't know a ton about it. I've heard good things from other C# dev friends, but it seems to be aimed squarely at the real-time/near-real-time web arena
- galfarragem 12y agoJavascript is a good girl to marry My crush is Ruby and probably will always be. She is beautiful but sometimes her mind is slow and I always liked fast girls. She is great girl, don't get me wrong, but not to marry. I'm afraid one day she will run away. In my street there are also 2 sisters, Lisp and Clojure. A cousin of them (Autolisp) was my first real girlfriend but we grew apart. Lisp, the older sister, was the most beautiful woman I ever met, it's a pity she is too old for me. Her younger and gothic sister (Clojure) is still a teen and unpredictable. Anyway their family is not very apreciated in my town, people say that they are weird and anti-social. I like them but what would my parents say about a relationship like this? Then there's Javascript. I don't have a passion for her, neither she is the most beautiful and perfect girl I know. Anyway she is good enough for me, I'm just a hobbyist, not a ninja. She is the kind of girl that will be always there for me. Slowly I will love her also, I'm sure of it. If I get really bored I'll take her unstable but so damn pretty co-worker as a mistress (Coffeescript) but I will never divorce Javascript, she's a woman for life. Im 34. I played around already, I don't want to look for more women. I'm old enough to marry and put on my leash. My reasons to "marry" Javascript: - JS is present everywhere and will be for a long time. Coming from a struggling field, I'm tired of begging for work; - I'm an hobbyist, JS still have a lot of amateurs, I'm still in time to jump on board. It's the wild West now; - Autocad (my field) just got a JS API.. ; - Meteor. IMO it has a bright future: it's cool (it's a kids project), user friendly (women involved in the development) and open to newbies (including hobbyists from different fields like me) https://www.youtube.com/watch?v=Z3cOLFP-ZyQ&list=UU3fBiJrFFMhKlsWM46AsAYw https://www.youtube.com/watch?v=Z3cOLFP-ZyQ&list=UU3fBiJrFFM... (This short video of a Tattoo designer running a business on Meteor was an epiphany for me). Note: This is just an humoristic comment, don't take it too seriously..
- dubcanada 12y agoI don't want to start any sort of a war. But why does women involved in development make it user friendly?
- galfarragem 12y agoI say this with a positive meaning: Women are more pragmatist (even if men claim the opposite) and will make any product easier to use (not necessarily more simple).
- mrbonner 12y agoYANN (yet another node nut)
- calebm 12y agoI wouldn't use Node for everything. I use Python more often, and also use some C#. I'd like to do more Clojure.
- anonyfox 12y agoThe biggest step forward for JS development is Meteor, hands down. For anything "appy", the productivity is just insanely good.
- mackwic 12y agoI wrote another comment explaining why I strongly disagree with you (and the Meteor thing) but after reading it I found it harsh and stuffed with negativity. So yeah, I very much disagree with you, but hope I will be wrong and Meteor will be usable for more than a blog or prototype.
- mark_l_watson 12y agoJust curious: I like Meteor but it does not seem appropriate for apps that need to have a huge number of concurrent users. The developer experience is sweet though. What don't you like about Meteor?
- anonyfox 12y agocurious, too. I spent the last months doing meteor exclusively, and compared to the usual node/RoR/php stuff on the server and angular/backbone/ember on the client, meteor is just superb IMO.
- hartator 12y agoI think the main issue with Node.js is that it is still being labeled as "unstable", that implies several things: - At any time, the core team can drop the support of the 0.x versions - NPM is still bugguy compared to gem or pip - The "vision" is something that might change radically. (c.f. the recent issues with some core collaborator)
- ilaksh 12y agoActually that is something that confuses people unnecessarily. There have been stable releases for a long time. The vision absolutely is not going to change, and as far as I know the issues with the core contributor were quite a long long time ago. Anyway every project has issues with people. But at this point, Node is probably right up there actually if you were to make a list of projects that had the least likelihood ever of being impacted by politics. Just because there is such a huge enthusiastic community, great package manager and culture of modular development, etc.
- kolev 12y agoThe things that made Node.js big are npm, the community, and the fresh new frameworks - a story similar to Ruby on Rails. But I have to fess up that I miss C# and Java as their verbosity is actually an investment, not wasted time. I'm really excited about Ceylon although it seems very slow pacing - doesn't even support Java 8 yet. I've recently done some stuff in Groovy (self-contained single-file utilities that download their dependencies from Maven with no build process and dealing with binaries although Capsule seems to be solving this perfectly nowadays). Anyway, one has to consider Dart as well as it can spit out JavaScript for the client and still write everything in one (saner) language. I really don't see myself doing a relatively large project in Node.js.
- ericfrederich 12y agoJust an observation about these statistics: * Built almost twice as fast with fewer people * Written in 33% fewer lines of code * Constructed with 40% fewer files When you choose a brand new language, the people doing the coding are ones willing to learn / try new things. This means you won't have dinosaurs working on your project.
- calebm 12y agoCorrelation vs Causation, yes.
- drderidder 12y agoThe author's experience are pretty typical for most newcomers to node (I help run a large JS meetup, so get to meet a lot of them). But I think what many people miss is that the functional programming and dynamic typing aspects of JS (two of the most maligned aspects) turn out to be surprisingly effective, often resulting in simpler, more concise code. Its a different mind-set from the statically typed OO paradigm, and the learning curve isn't exactly easy, but getting comfortable with functional programming and continuation passing style in general is a great skill for any programmer to have.
- debaserab2 12y agoDo you have any easy-to-grok real world examples/libraries you would recommend? Genuinely curious and want to learn more. The JS code I end up writing is always in a more traditional object-oriented style but I'm usually not entirely satisfied with the end results.
- calebm 12y agoLo-dash is a good place to start: http://lodash.com/ http://lodash.com/
- sramsay 12y agoMight also recommend Functional Javascript by Michael Fogus. He uses underscore.js, and avoids re-implementing classic functional patterns (map, reduce, filter, etc). I understood a lot of functional concepts from Lisp before reading the book. There might be something else you need first if you've had no exposure to FP, But if your basic FP-fu is good, this is a really nice book to read.
- ericHosick 12y ago"JavaScript can be the native format of your data" I don't think developers appreciate how amazing this feature is in a language. Code should be a data-structure giving you all the benefits of data-structures including persistence.
- calebm 12y agoCloser to homoiconicity, but not quite there.
- ericHosick 12y agoYa. Exactly. I like that term.
- rubiquity 12y agoNot exactly at all. Homoiconicity is when your program can be represented as a data structure. Like, literally a data structure. JavaScript doesn't even come close to that.
- deleted 12y ago[deleted]
- ericHosick 12y agoYa. I mean exactly as in the term Homoiconicity. Not Javascript itself. However.. You can use an approach to programming in JavaScript that allows java-script to be Homoiconicit. It is also possible to do the same thing in C#. Here is an example: // This code is a data structure // that can be traversed, persisted, // etc. // Write to the console ( 3 + -1 ) + -1 Con({ text: Add({ left: Add({ left: Num(3), right: Num(-1) }), right: Num(-1) }), }).go; // Add defined var AddF = function() {}; AddF.prototype = { get go() { return this.asNum; }, get asNum() { return this.d.left.asNum + this.d.right.asNum; }, get asStr() { return "(" + this.d.left.asStr + " + " + this.d.right.asStr + ")"; } }; function Add(d) { var f = new AddF(); f.d = d; return f; }; // Num Defined var NumF = function() {}; NumF.prototype = { get val() { return this.d; }, get go() { return this.d; }, get asNum() { return this.d; }, get asArr() { return [this.d]; }, get asStr() { return this.d.toString(); } }; function Num(d) { var f = new NumF(); f.d = d; return f; }; var ConF = function() {}; ConF.prototype = { get go() { console.log(this.d.text.go); return unknown; } } function Con(d) { var f = new ConF(); f.d = d; return f; };
- buckbova 12y agoComing from an IIS, .NET, SQL Server background, the simplicity of full-stack javascript from mongo, to node, to angular cannot be overstated. Propagating a change from the front to the back end or vice versa is much easier and faster speaking the same language throughout. Tools like yeoman, grunt, bower makes it that much more pleasant. Libraries like expressjs, mongoose, passportjs, and many more can do a lot of the heavy lifting, taking away some of the pains of writing boilerplate. All and all I'm a fan. I'd love to use angular against firebase only without a node server, but I can't justify the cost.
- pearjuice 12y agoNode.js is like that cool new kid on the block who is super easy to get around with and before you know it you are best friends forever and he sleeps on your couch regularly. After a few days the coolness wears off. He has flaws, too. Irritations. Annoyances. But, do you really want to go back to your old friends? Who are a magnitude less cooler but better for you in the long run? I decided to do the latter and get actual stuff done. Node.js is fun and all, don't get me wrong, but once you get over the hype and really dive into it you are better off with Java.
- sramsay 12y agoI'm trying to think of a single language of which this is not true. It's certainly not Java. That dude is drinking all your beer.
- sergiotapia 12y agoThis article is literally counting the same reasons listed every time nodejs is mentioned, since it's inception. Non-blocking, single-language, npm. What's new?
- pp19dd 12y agoWhat changed my mind about node.js was when I ran a demo program as a daemon and then forgot about it for months. And it never broke. Despite the program being very poorly constructed (by myself, of course), it was still running reliably on the machine much much later. It's a simple websocket (faye/bayeux) demo that allows multiple users to edit a grid concurrently. Plain version: http://faye.pp19dd.com/ http://faye.pp19dd.com/ - works on iphones and such, and a HAL 9000 babylon.js version: http://faye.pp19dd.com/index2.php http://faye.pp19dd.com/index2.php (Instructions: click on squares, use mouse wheel and such to move camera.) At some point in putting the program together, I realized that I could write modules that could work on both the client and the server without any modifications. IE: client, server data structure. Maybe I'm rusty these days, but mind was partly blown.
- frugalmail 12y agoThis is an idiotic thing to do. - JS is difficult to maintain - JS is difficult to statically analyze - Callback hell is a stupid thing to voluntarily subject a team to - JS is notoriously difficult to debug - It's much harder to find "good" JS resources, but much easier to find "bad" or "mediocre" JS resources
- mackwic 12y agoSame goes for C and C++, pretty much exactly the same. Well, I have some bad news for you... :) It's not because it's JS that we can fire the architect, SOLID principles (yes, they still are quite good practices), and abandon all sane project management. Truth is, there's no silver bullet, it's always a trade-off, blah blah blah. In the end, I found it easier in JS than C to adapt the quality management of the project with it's criticity. Yep, I have some slightly critic components which run in JS right now, and I'm OK with that.
- _random_ 12y agoWho cares about debugging, code correctness and maintenance when it's so "fun" to code in JS?
- ilaksh 12y agoI think people are herd animals. So when a few developers are using some new tool, they are off by themselves away from the herd and considered idiots or something. Then more and more start using that tool, and pretty soon the whole herd, or all of the cattle around you, are doing that, and then you change your mind. I like using Node.js with ToffeeScript (which is a variant of CoffeeScript). I liked Node before most people realized how cool it was. I am also sort of into bash these days. Down the line I would like to get into things like LiveScript and Nimrod. And then down the line I would like to move on to some kind of system based on description logics that makes it convenient to integrate systems because programming languages and data can be translated to and from a common (DL-based) language that can be reasoned on.
- redblacktree 12y agoIf you replace language names with band names, this sounds just like an insufferable hipster riding a fixie in his skinny jeans talking about how he liked Node before it was cool. That's the joke? Or were you serious?
- ilaksh 12y agoMaybe I should have left out the part about liking Node before it was popular. The point was to try to give the idea that I had picked up on a trend before some other people. The reason I want to get credit for that is because I want people to use those other technologies that I like, so maybe someone reading that will think that I can select technologies that, if nothing else, might become popular in the future, and therefore decide to use the technologies I mentioned. Also, I hate hipsters and have no friends and am about the farthest from a hipster you could ever be, BUT I _did_ have a "fixie" when I was a kid 30 years ago. That was because we were lower-middle class and my parents were cheap though. Also, I did finally purchase a pair of skinny jeans on the direct advice of a lady friend last year. Despite having put on at least six pounds, they still just about fit. Pretty amazing actually. It is a little embarrassing wearing them outside, but if I am honest, they are my favorite jeans. LOL.
- ziemo 12y agoOK, but what's about Java's vert.x framework or some asynchronous web-container like undertow and CDI usage? Does that stuff are really so slow and painfull in compare with NodeJS? I don't think so.. I think that there is nothing bad with using "old" Java Enterprise Stack, as long as you are really sure what you are doing and you really know (not guess) what to use!
- anotherevan 12y agoI’ll admit I’ve always passionately disliked Javascript. I also have a strong preference for statically typed languages over dynamic, but always thought Javascript was the most unlikeable of the lot. Perhaps it is that I initially learnt it by osmosis, trying to get things working under both Netscape and early Internet Explorer browsers at the same time. Worrying if I put my curly brace on the same line or the following line, or if I forgot a semi-colon at some obscure, critical location. But I’ve always been hesitant of dynamic languages in general, preferring statically typed for any codebase of significant size. The last decade has been a bit discouraging for me in this regard. First everybody was loving Ruby, then seemed that Python has overtook it in attention. And then Node.js came along and I really felt like Bromden with a pillow, looking for a way to smother the insanity. (As an aside, I do quite like Ruby as a language, and writing Coffeescript - the wonderful lipstick for the pig that is javascript - has given me an appreciation for the indentation feature a’la Python.) The number one problem to my mind with using dynamic languages for a large codebase is maintainability. Refactoring a compiled, statically typed language is so much easier. There is so many potential errors that the act of compiling and type checking eliminate for you that you don’t get with dynamic languages. The focus on huge amounts of unit tests always seemed like compensation for this. And refactoring code is so much easier. Add another parameter to a function, try and compile and you find all the places in the code you need to fix. Maintaining a sizeable amount of code, or code you haven’t looked at for a while is so much easier. And I get the feeling the pendulum of opinion is starting to swing back in my direction. Running stuff in a web-browser is now a serious concern, and good hackers are working on ways to portably do good programming in anything but Javascript. From asm.js to Dart to PureScript and others. Newer languages like Go and Rust are taking the nice features many have lauded in the last decade as the advantages of dynamic languages. Things like good package management, less boilerplate and such, and baking them into static languages. So my outlook is getting rosier.