Node.js and C# Use Cases – Practical Applications and Comparisons

asp.net-mvc-3cmvcnode.js

I do quite a bit of ASP.NET work (C#, MVC), but most of it is typical web development. I do Restful architecture using CRUD repositories. Most of my clients don't have a lot of advanced requirements within their applications.

I'm now looking at node.js and it's performance implications (I'm addicted to speed), but I haven't delved into it all that much.

I'm wondering if

  • node.js can realistically replace my typical web development in C# and ASP.NET MVC (not rewriting existing apps, but when working on new ones)
  • node.js can complement an ASP.NET MVC app by adding some async goodness to the existing architecture.

Are there use-cases for/against C# and node.js?

Edit

I love ASP.NET MVC and am super excited with where it's going. Just trying to see if there are special use cases that would favor

Best Answer

I'm now looking at node.js and it's performance implications (I'm addicted to speed), but I haven't delved into it all that much.

Profile, profile, profile. That's the only way to know that your speedups are having the proper affect. You can guess that it's fast enough. But most people like to prematurely optimize. That's worse than playing with yourself during a date.

I'm wondering if node.js can completely replace my typical web development in C# and ASP.NET MVC, if it's better as a complement to C# and ASP.NET MVC, or if there's some things that should just "leave well enough alone".

Are there use-cases for/against C# and node.js?

Sure, if you're in a shop that routinely writes code in C#, then you should use MVC (it's a lot better than WebForms, and is called WebPages). You're going to not lose a lot of time to tooling training, and it's something your workflows should already handle.

What you don't seem to indicate above is the reasons to choose each. You've given two current market options, one still in Alpha stages, the other on its full third year of platform release. I wouldn't want to compare the current testing model electric cars with the Honda hybrids that are already out on the market. They're in two different leagues.

Now, here's a reason for you to stay away from node.js, if you're nominally a C# shop.

You don't currently work in asynchronous evented i/o, you currently work in a procedural format.

That's the antithesis to what nodejs is going to do for you.

However, if you're frequently writing async code in C#, and you use it a lot in an evented style, then yes, node.js is for you to strongly consider.

Here's what you'll give up:

  • IIS - This is actually important to a lot of people. Things like native A/D integration are already done, and pretty bug-free. Actually node.js now integrates well with IIS.
  • Razor templating - If you've done any serious C# MVC, then you are using and loving Razor and how quickly you can churn things out. There are similar templates in node, and I'm certainly not knocking node, but the entire toolchain is already present in C#, and a lot of it is currently being built in node world. NB: a lot of this tooling is now rather mature_
  • compile-time building of dlls - node.js generally gets compiled on the fly, that is to say, not all paths are checked at startup. It's entirely possible to have really bad code in node that nobody ever touches, checks, or tests against.
  • All the tools currently built into VS that you use daily - There just isn't that much VS support for javascript. Partly because everything in javascript is so dynamic. NB: Microsoft is obviously working on tooling support for javascript_

Here's what you'll gain:

  • everything you develop will be in the same language, assuming you do client side scripting as well as serverside. (or why would you even consider javascript on the server)

So, since I seem to be bashing Node here entirely, let me point out that node is my play language at home, I love it, and I help people debug it sometimes on the stackoverflow chat servers (room 642). I see that it has great and stupendous potential in the future.

I'm just saying, don't throw out the baby and wonder why the bathwater is dirty.

You haven't given a reason why you should give up your years of experience and start on something new. Are either bad tools? Not at all. Both are great and make development a breeze.

Can node replace C#? Yes, quite certainly. So could PHP or Java or Ruby. You're not asking about those.

Here's how you know when you're ready to program node.js instead of C#:

  • You're considering writing a book to help other people "get javascript" instead of the boring old programs they've written before in C# and etc.
  • You've got problems with synchronous (blocking) I/O stopping your apps from doing actual work.
  • You aren't using ANY libraries in C# other than the default MVC and that just for routing, and you're pretty sure that you can do a better routing engine, and you're coding everything as close to the metal as you can.
  • Every data object you design you see as a hash instead of a strongly typed object.
Related Topic