
Writing node.js applications in C# - erik-kallen
http://www.erik-kallen.se/blog/writing-nodejs-applications-in-csharp
======
tomkludy
What exactly is the point here? If you want to write C#, just use ASP.NET and
MVC 4. You will certainly save yourself a lot of headaches, and you can still
do everything async, etc. From what I can tell, the purpose of Node.js is to
reduce the number of technologies that a web dev has to use and understand.
You already need to use JavaScript on the client side, so using the same thing
on the server side allows code reuse, knowledge sharing, etc.

It seems like what the author really wants is ASP.NET on the server, and
Script# on the client side. Then the whole stack is C#. Or perhaps he would
find TypeScript an acceptable middle-ground on the client. But I don't
understand why you would choose Node.js on the server if you hate JavaScript,
does not compute.

~~~
mattmanser
MVC is actually pretty damn clunky. It has a lot of built-ins which are just
frustrating (like IPrincipal, ugh). Also there are loads and loads of weird
quirks that pop up as soon as you start trying to do anything like returning
JSON.

MVC was a huge step forward from the old ASP.Net, but it's still making a lot
of frankly odd decisions or suddenly bizarre behaviours in the background
(e.g. [http://stackoverflow.com/questions/1975983/how-can-i-
disable...](http://stackoverflow.com/questions/1975983/how-can-i-disable-http-
keep-alive-in-asp-net-mvc))

I think one of the reasons node.js is so great is that it just cuts out almost
everything and gives you direct control over what is returned. MVC still mucks
around with everything trying to be 'helpful' as it's really built on ASP.Net
in the background.

To many of us, javascript is still one of the worst mainstream language around
today.

Still, why not just make node.cs instead one wonders? Perhaps the existing
ecosystem.

~~~
utnick
can you elaborate on the quirks around returning JSON with asp.net MVC? its a
pretty common usecase.

~~~
mattmanser
There's a load of little things that are gotchas, but an example that pops
into my head is that it wasn't compatible with default jQuery for example. If
you didn't ask specifically for a content-type of application/json, which
jQuery didn't by default, it would throw a hissy fit. It meant mucking around
with the ajax object meaning you couldn't use certain jQuery shortcut methods.
Regardless of what you 'told' MVC to do.

So there's a bunch of things it's doing you're not even aware that it is nor
have asked it to do.

Think that was MVC 3? I've been using it since the first version, it's much
better than it started (the original JSON support was awful), but you still
every now and then get a WTF moment.

For example I still really have no idea the 'right' way to return 404 or 500
error pages. I swear they change their mind every release.

~~~
sequence7
By default MVC 4 will return JSON so you don't need to specify the content-
type unless you want something that isn't JSON.

~~~
mattmanser
It's not the return type, it was the request type. It didn't like if you
requested it with plain/text instead of application/json. Which was jQuery's
json method's default.

~~~
sequence7
plain/text gives you JSON in MVC 4. I understood what you were saying, the
default in MVC 4 is now to return JSON unless you specify otherwise.

~~~
mattmanser
Yeah, but this is my whole point. Finally in version 4 they stop mucking
around with the requests _before_ they give it to you. Someone, somewhere in
the depths of MS clearly believe they understand HTTP better than you do. And
keep guessing what you really 'meant'.

Even though they quite clearly don't understand and actually really don't get
HTTP. For example take the fact that it's nigh impossible to get the actual
request body in ASP.Net. Who's bright idea was that?

In reality every single interface, every single framework they've produced so
far has shown a woeful lack of understanding about the web in general and
pretty much how it's used outside their world. And I say this as someone who's
primarily programmed in VBScript, VB6, C#, Silverlight, ASP.Net and ASP.Net
MVC.

I keep almost jumping ship and then they just kinda fix it and I stick around
hoping they're not going to make the same mistakes. But they do, jeesus, MVCs
ajax stuff is unsurprisingly fucking awful.

But that's the problem with MVC and anything MS led, they don't get the web,
they don't get javascript, they keep making incredibly silly decisions.

A good example. Every time I hear 'unobtrusive' js, I just want to scream.
_They're_ the cause of this made up problem. No-one else was doing js like
that in 2010, no-one else needed unobtrusive javascript. Just MS. There's no
such thing as unobtrusive javascript, there's just not writing idiotic magic
code like a fucking retard like MS constantly do when it comes to javascript.

And don't even get me started on their 'web services' or WCF. Both deserve to
die in a fire.

TL;DR; I love C#, think it's the best language available today by far. I hate
asp.net though.

------
louthy
It strikes me that there's a much simpler solution, and that is to use
TypeScript. It has all the VS intellisense that's required and none of the
boilerplate in the OP's solution.

<http://www.typescriptlang.org>

------
cincinnatus
There is already a node.js analogue that runs on .net and hosts .net
<https://github.com/jacksonh/manos>

Hasn't been updated in a long time. Not sure why it isn't getting any love,
maybe something better came along. Seems to me it should be more performant on
equal hardware.

------
gizzlon
I can't believe Javascrip is really _that_ awful that anyone would rather go
through all this trouble, rather than just write JS..

Maybe it has more to do with people being to reliant on IDE's, which he, kind
of, admits to anyway..

I can't believe that any IDE is _that_ great that anyone would rather go
through all this trouble, rather than just use something else..

~~~
yawgmoth
I think in this case, it isn't about being dependent on Visual Studio, but C#.

~~~
hkarthik
The two go hand in hand. Aside from a very small cross section of Mono users,
most C# users are very dependent on Visual Studio.

------
kantl
Not more than month ago when this project was announced people were praising
it. (No wonder, it features a fairly complete subset of C# - it's free and
open source, it works and it's great - mad props to the creator keep up the
good work!) Now when the author presents a use case people are throwing rocks.
(At least this is my impression by reading some of the comments). I don't know
about you, but I feel bad about it. It's the same story everytime a topic of
compiling to JS is brought up. The JS "crowd" steps in with their "wisdom" of
why it's a bad idea to do "X" and all they do is criticize...

------
cdl
May want to take a look at ServiceStack, nice lightweight alternative to MVC
with an extensive architecture providing for super easy and high performance
ORM, JSON/JSV serialization/de-serialization, POCO DTO's with no-effort
endpoints!

<http://www.servicestack.net/>

------
fpp
One of the key benefits of node.js is that people who are great with JS can
write server code and you have one language stack less to worry about. You can
with that (watch for security issues) also share code & objects between the
server and browser.

Can't see how this fits into that.

------
impostervt
When I read about Node.js, the first selling point people mention is how you
can reuse code on the client and server sides. For me, the main selling point
is that it's Javascript. When I see new variants of js, developed to "fix" js,
it makes me want to cry.

~~~
Jare
Currently, reusing code on client and server is far from the first selling
point. Companies like Meteor and Groupon are pushing in that direction quite
heavily, but for mere mortals it's still limited to reusing a few core
libraries like underscore, async or templating.

Reusing experience and knowledge, and reducing the cost of context switching,
those are very clear and positive advantages.

On the topic of sharing code, these should be interesting: the 'pipe dream' (
<http://keithnorm.com/spainjs-pipedream/> ) and the 'holy grail' (
<http://thatconf.chrisjpowers.com/> ).

~~~
rdrey
Thanks for the "pipe dream" link, I found the conference talk on youtube and
enjoyed it a lot. The reusable code 'function' of node is still too non-
obvious to achieve without the right mix of tools and this talk gave a nice
intro for a solution.

------
politician
"JavaScript is the only language people feel like they don't need to learn to
use." -- Crockford

