Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Node.js Makes for Cluttered Code

DZone's Guide to

Node.js Makes for Cluttered Code

· Web Dev Zone ·
Free Resource

Learn how error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.

According to a recent post by Peter Moberg on his blog Source Code Bean, your node.js code is being polluted by it's own callbacks.  Moberg's recent hacking in Node.js/Express.js has led him to appreciate its speed, but hate it's verbosity.  He's not the only Node.js user to experience cluttered code.  His post has already attracted 18 comments from his readers, many of who agree with his opinion, as well as suggesting some ways to stem the tide of callbacks, such as this one by Ekin Koc:

This issue goes out of control sometimes, leading to dozens of nested functions and stuff.  CoffeeScript’s syntax makes it a little bit easier to deal with it but it’s still no solution. I think it’s too late for JavaScript for this but maybe, CoffeeScript or some other dialect might provide c# 5 style async handling. -- Ekin Koc

Sounds like CoffeeScript addresses, but does not get rid of, the problem of cluttered code in node.js.  Some commenters seem to think that part of the solution here should be found in how the programmer approaches flow control.  According to commenter Shankar, Moberg was trying "to use sequential flow control on [an] event-driven platform," and this could be fixed through flow control methods posted on github (LINK).  This may, like CoffeeScript, address some of the issues of polluted code, but Moberg suggests that the problem here may not be as much with node.js as it is with the nature of JavaScript itself:

I am just saying that event driven programming in JavaScript could be made much easier. -- Peter Moberg

Comment with some further suggeststions for cleaning up cluttered code, or let us know of your own experiences with node.js below.

What’s the best way to boost the efficiency of your product team and ship with confidence? Check out this ebook to learn how Sentry's real-time error monitoring helps developers stay in their workflow to fix bugs before the user even knows there’s a problem.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}