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 to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

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.

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}