
6 Months with C# - insraq
http://ruoyusun.com/2013/03/10/6-months-with-c-sharp.html
======
spo81rty
I don't understand why everyone on HN hates Windows server so much. From an
administration standpoint they are much easier to setup and use thanks to
their GUIs. Windows is very standardized and has very good management tools
and interfaces.

C#, ASP MVC, and Visual Studio are extremely good tools. I've programmed in C#
for 10 years and never had a project I could not do quickly with it. It has
very good support of 3rd party controls like Telerik, and there are lots of
open source projects on codeplex, github, etc.

The most expensive part of software development is paying developers. Spending
a few dollars on good dev tools or 3rd party controls is a very good
investment and can save a lot of time.

~~~
stevenelliottjr
Because it's too easy! Nerds would rather spend countless hours at the command
line figuring things out than having a nice interface to get stuff configured
and running. As a developer, I don't want to spend my life also configuring
servers - sometimes it's just nice to get things working without a ton of
hassle. Of course nowadays we use Azure or AppHarbor for everything but we
still have some services running on IIS internally. There is this counter
culture against anything MS on HN - I don't get why.

~~~
nkohari
No one wants to spend their life configuring servers. That's why tools like
Chef and Puppet exist -- so you can write code that will do it for you. They
just don't work as well for Windows as they do for Linux.

After a significant amount of experience in the .NET ecosystem, I believe the
majority of the anti-Microsoft sentiment is well-deserved. At one point, there
was a lot of innovation in .NET OSS, but it seems to have ground to a halt
within the last few years. It's possible I'm just projecting because of my own
experience, but it seems like many of the more influential members of the .NET
ecosystem have gone on to do other things.

It's not that Microsoft or .NET is _bad_ \-- it's just that there are better
options.

~~~
thatfloatingguy
I keep hearing that there are better options... but I haven't found one which
is personally better for me. I'd love to hear suggestions if you have the
time.

I think the biggest problem for me isn't some attachment to Windows Server (I
much prefer working on a Linux server), or some misplaced love for WebForms
(ick!), but the C# language in general.

There are a lot of great dynamic language setups on Linux (Rails, various
Python stacks, etc) which aren't bad or anything... but I always find working
in a dynamic language to be a bit of a hindrance. I've been writing a
multiplayer game server in Go, and I can't even begin to list the hours of
work compile-time type tests have saved me during early development as I
constantly refactor. But on the other hand, I wouldn't want to write a large
"business" style web-app in Go (my day job), which really doesn't have a
standards library tailored for it.

I also get the feeling that the dynamic language web-stacks suffer from
relatively poor performance compared to the CLR, and for some of the clients I
work with who need to do some fairly complex non-database processing, this
wouldn't be a great thing. Maybe this concern is unfounded though.

Perhaps Java is the closest match to .NET, both in style and in spirit. But
having done a fair amount of Java development for Android, Java just feels so
clumsy and clunky... The language isn't as nice, the tools aren't as nice, and
the standard library just doesn't compare in terms of letting my express
myself quickly and easily.

When one of my clients needs a web-app, I always go .NET. These projects won't
ever be scaling to millions of users, so server licensing really isn't an
issue. On the other hand, there will be lots of direction changes no matter
the amount of planning, so static typing can be a God-send with the safety
blanket it provides. And C# really lets me write clean code more quickly than
in anything else I've worked with.

If I we're creating a product for a start-up, I probably wouldn't go with
it... licensing costs would be an issue. But then again, if I was running a
start-up, hopefully it wouldn't be a relatively boring business-app that was
best suited to something like .NET. And if I were creating a product for a
huge number of users, it'd be worth pouring in the development time to have a
super high performance back-end in a language separate from the quick-to-add-
features-to Ruby front-end.

But for my use case, I just haven't found a better option yet. I'd love some
suggestions though, because I'm not a big fan of Microsoft these days and
wouldn't mind being less at-mercy of their platform. Maybe my concerns are
unfounded though, and I'm just stuck in what I know, but I do branch out a lot
for personal projects.

~~~
nkohari
I don't think there is another great option if you want something like C# and
you don't want to go down the Java road.

I adore C# as a language, and the CLR as a platform. If not for the Windows
requirement, I would write quite a bit more C# than I do now. (See my other
comments on why Mono isn't good enough as a platform-independent option.)

Let's be honest, JavaScript is a goofy language with all sorts of ugly parts,
but it's surging in popularity because of the power of the platforms on which
it's used (browsers and Node.js).

Lua is another language which I've taken a liking to recently. It has a
beautiful, clean, simple syntax -- it's basically like dynamic C -- but its
standard library is horribly weak. That's why I think it's relegated to
embedding.

The .NET standard library is amazingly powerful, but the only "real"
implementation of it requires Windows. My point is: it's not enough to be a
good language, you need strong platform support.

------
gambiting
Mono is actually finding its way to new platforms all the time.

I was surprised to find out that the recently released Playstation Mobile SDK
is based entirely on Mono, so Playstation Vita runs it.

And I am pretty sure there's an implementation available on Android. As for
iOS there's Xamarin. MonoDevelop on MacOS is also quite good.

~~~
nkohari
I've been a fan of Mono for a long time; unfortunately, we've had a lot of
trouble trying to scale it in production.

Our application was originally built for .NET (on Windows). It was
successfully ported to Mono, but we continue to have strange problems (machine
load average going to 50+ and becoming unresponsive, etc.) which we believe
are related to the Mono GC. After spending a good amount of effort trying to
fix the Mono version, we decided to bite the bullet and migrate to another
platform (Node.js), which has proven to be significantly more stable under
load.

I'm a huge fan of Miguel and the rest of the Xamarin crew, and I'd love to see
a universal implementation of the CLR take dominance. I think maybe 5 years
ago the CLR had a real chance to win in the battle of multi-language runtimes,
but at this point I think the war is going to the JVM. (Chalk that up to yet
another short-sighted decision by Microsoft.)

~~~
sultezdukes
_I'm a huge fan of Miguel and the rest of the Xamarin crew, and I'd love to
see a universal implementation of the CLR take dominance. I think maybe 5
years ago the CLR had a real chance to win in the battle of multi-language
runtimes, but at this point I think the war is going to the JVM. (Chalk that
up to yet another short-sighted decision by Microsoft.)_

The problem is that Java (the language) completely dominates the JVM landscape
still. I don't see Oracle in the game at all as far as contributing/endorsing
something else, and obviously Sun was completely oblivious to anything else
until it was too late in the game for them.

If you look at the CLR, VB.NET has and F# actually have significant
percentages of uptake because they're actually supported by Microsoft. Scala,
Clojure, etc.... are just miniscule blips on the radar in comparison.

~~~
nkohari
I agree with what you're saying, but without a proper implementation outside
of Windows, the CLR is currently a place where great languages go to die. Mono
is functional, but is basically unsupported (for everything but mobile).

~~~
sultezdukes
_the CLR is currently a place where great languages go to die_

No, F# is completely supported by MS. And that's the problem with the
alternative languages on the JVM. Decision makers are wary of anything that
isn't officially supported by Oracle. There are other problems with languages
like Scala and Clojure that have nothing to do with official support, but
that's another story.

The mono story is an interesting one. At first people thought it would allow
cheap deployments of ASP.NET on Linux servers, but it's really carved out a
niche for itself on the linux desktop, in gaming (Unity, Sony's dev kits), and
now mobile. What's funny is the JVM is completely irrelevant on mobile,
compared to .NET/Mono. Just now Oracle is pulling their heads out of their
asses and trying to get the JVM to work on iOS.

~~~
nkohari
F# is supported by Microsoft on the Windows implementation of the CLR, which
is great unless you're not willing to use Windows.

You're right that the JVM itself is irrelevant on mobile, but via Android the
Java ecosystem still plays a role.

~~~
sultezdukes
F# runs perfectly fine on Mono. The F# compiler is open source. Microsoft
doesn't have to support F# anywhere else. In fact, Xamarin is going to support
F# directly in their new IDE.

------
seanalex
I've been using C# for several years, and have bounced between it, Java,
Node.js for my side-projects. After all said and done, I keep coming back to
C#. I feel more productive and can design and churn out code quicker than say
in a Node project. Overall, I actually do enjoy coding in C# and using .NET
more than any other language I have experienced so far. The day I tried to use
Drupal was the day I realized I made a serious mistake for not thinking I
could do things better or quicker in C#/.Net instead.

Overall though, Microsoft is trying to move to an "ecosystem" platform.
Exampes are Nuget powering their closed/open-source ecosystem for projects and
Azure server templates. Even their latest ASP.NET MVC 4 is pushing several
open source libraries onto their default project template. They truly see they
couldn't win the web battle with WPF/Silverlight as their only options, so
they are going for a different angle here in the last year. Additionally, a
lot of interesting things are coming out of Microsoft and its employees, such
as the open-sourced SignalR which is actively being updated and may become a
standard for C# webapps.

I realize C#/.NET is not the go-to language for small web-apps yet, primarily
due to licensing, but give it time. I say if you are on the fence, and are
interested at all in C#, give it a shot! There are many free options for
development IDE's and hosting provided by Microsoft. For example, you can use
Visual Studio Express and host up to ten websites for free on Azure.

------
stevenelliottjr
I have been a C# developer since 2004 and nowadays I use it with Xamarin
Studio to write iOS apps on the Mac. What Miguel and Nat have done with
Xamarin is awesome and I think the future of .NET lies more with what they're
doing than what MS is doing IMO.

------
crag
"It is quite difficult for Python or Ruby to have the level of IDE that Java
has. IntelliJ for Java is hard to beat. And Jetbrain (the company that makes
IntelliJ) also produces Resharper (R#)..."

Jetbrains also makes IDE's for Ruby and Python; Rubymine and pyCharm.

~~~
insraq
But the language support is not as good as Java and C#, which are static typed
and IDE can make use of static analysis.

------
MatthewPhillips
Microsoft is trying too hard to make C# answer to every single technology
trend, adding dynamic type, asynchronous methods, etc. In most cases you wind
up with a working but much worse alternative to the real thing. For example,
here's how you create an anonymous function that returns a string in C#:

    
    
      (new Func<string>(() =>
      {
        return "foo";
      }))();
    

That's pretty awful and as a result you rarely see anyone doing stuff like
that, whereas with JavaScript it's used regularly. But for C# it's another
checkbox that they can say they support.

C# should stick with trying to be the best statically typed compiled object
oriented language.

~~~
nkohari
You're right, that is awful. It's also unquestionably the worst way to write
it. Try this instead:

    
    
       () => "foo"
    

Please don't participate in a conversation if you aren't willing to spend the
time necessary to gain a baseline level of understanding of the topic.

~~~
MatthewPhillips
That's not equivalent code, it doesn't execute itself.

That it simply returns a string with no logic and therefore can be written
slightly simpler belays the point I was making. You simply don't see this type
of code being used much in C# because it isn't idiomatic, yet it exists to
mark off a checkbox.

~~~
nkohari
Fair enough, if you want to automatically execute an anonymous function, your
example isn't idiomatic C# either. The idiomatic version would look like this:

    
    
        var func = () => "foo";
        func();
    

As far as "you don't see this type of code being used much", that's just
patently false. Anonymous functions (particularly predicates) are the whole
way you interact with LINQ.

So I'll ask this: what's the equivalent example in Java?

~~~
MatthewPhillips
Your example won't even compile. You're confusing functions with lambda
expressions. Lambda expressions look a little like a function but they are
something different. Lambda can be compiled into functions at run time and
that's often what they're used for, but they can't be implicitly assigned to a
var. Doing it you're way would look like this:

    
    
        Expression<Func<string>> func = () => "foo";
        func.Compile()();
        

That's hardly better, and it's still not anonymous! You probably like Lambda
Expressions because they make things like LINQ elegant, and indeed they do.
But a lambda expression is confusingly similar looking to a func (indeed a
mistake you made) but when you try to do something more complicated like this:

    
    
        Expression<Func<string>> func = () =>
        {
          string foo = "bar";
          return foo;
        };
        

That won't compile because a lambda expression can't have a statement body, it
can only contain (a single!) expression.

Now the cool thing about lambda expressions is that to the end user they are
simple and elegant assuming you know that they are not the same thing as
functions, but on the other end of it; consuming a lambda expression you get
to see the guts of it and realize what a hack it is on the language. Sure, in
the context of a compiled statically typed language it's rather powerful. It's
how they are able to compile a lambda expression into a SQL statement, because
you can inspect lambda expressions which you can't do to functions.

Now you asked about Java and I'm not going to defend Java or predict what
their intentions are, but I'll just say that Java is being much more
conservation about sticking to what it is; a statically typed compiled
language. C# is attemping to be everything to every body.

~~~
nkohari
You're right, I'm a bit rusty, not having written anything large in C# for a
couple of years. The compiler can't infer the type, so it would be:

    
    
        Func<string> foo = () => "foo";
        func()
    

I'm well aware of the difference between an anonymous function and an
expression in C#. What in your example suggests that you should be using an
expression? In practice, you never need to work with expression trees unless
you're doing metaprogramming of some kind. They were added to the framework
primarily to support metaprogramming and support the DLR.

LINQ (or at least "LINQ to Objects") does not use expression trees. For
example, this is the signature of the Select() extension method:

    
    
        public static IEnumerable<TResult> Select<TSource, TResult> (this IEnumerable<TSource> source, Func<TSource, TResult> selector) { ... }
        

Note the lack of Expression<Func<>>.

Things like LINQ to SQL and the Entity Framework translate these statements
into expression trees, but they do it transparently inside the framework.

My point in bringing up Java is that in order to do something like what we're
talking about, you'd have to jump through a whole bunch of hoops. It certainly
would be more difficult than in C# -- which is really what matters more than
the "purity" of the language.

------
pmelendez
I have also been working for the last 6 months with C# at the office and I was
reading the article nodding all the time. Working in C# is a good experience
and you have the feeling that it's an upgraded version of Java.

However, for me is still boring. It's not easy to explain and I am pretty sure
is very subjective but I feel C# lacks of soul. In the sense that programming
in C# isn't as fun as programming in Scheme or Python. Maybe is just me, but I
don't use C# outside of my work.

------
ashkenazi
It even saves time, I use it a lot whenever I create an app, even integration
with cousins like Visual Web Developer through SQL Its really a good language
to use, but promotes laziness. But its my language though so I can't complain
about it since I make a living out of it. I got called by an IT company, one
of the biggest in South Africa but they want me to program with Java but I'm
just not interested in that.

------
damian2000
Good article, but I have to disagree with you regarding the C# ecosystem.
Sure, its mainly windows, but there is boatloads of tools and support out
there for it. Visual Studio is a great IDE, and the documentation for C# and
.NET is generally good.

I'm a C# developer mainly, and recently did a bit of Java development in
Eclipse (Android ADT) and did miss some features of C#, but the languages are
still very, very similar.

~~~
NateDad
There's definitely a lot of C# code out there. I do think that _open source_
C# code is more limited than some of the other popular languages. However, the
.Net standard library does so much that you often don't need much more other
than perhaps a custom protocol implementation or some UI code.

I think Windows is the major drawback to C#. No one with half a brain is going
to write server software that only works on Windows. Desktop software? Sure...
I wouldn't write desktop software in anything else (at least for mass market
software). I admit to not having worked with mono, and I think it is kind of a
catch-22 - if it's not a common framework, no one will write for it, and if no
one will write for it, the framework won't get much love... which is a shame,
because Java obviously is in dire need of some competition to spur innovation
over there at Oracle. Using Java feels like going back in time to 2002.

~~~
emn13
Although the core libraries in .NET are huge, many are also very shoddy. There
are also a few great API's, but the overall quality and usability is pretty
uneven. This is mostly a problem with API's back from version 1.0 - however,
unfortunately, those API's often haven't been updated. Documentation is also
not always equally good; MSDN has lots of pages that describe a method
Bar.Foo() as "Fooing a Bar", which is next to useless. I get the impression
the java APIs are often better documented.

NuGet might really turn things around; here's to hoping...

~~~
mattmanser
Yeah, the worst ones are the stream ones, some what ironic given that he
singles one out over Java. The IO one may have `ReadToEnd`, but it's still
nowhere near as simple as Python or Ruby, it just shouldn't have to take that
many lines of code to read a file.

And these days I include RestSharp pretty much straight away if I'm going to
be doing any HTTP calls, the native HTTPClient API is horrible. But even
that's not got the greatest API, there's absolutely no good reason to have to
declare a `RestClient` before doing a `RestRequest`, it's just a waste of
lines of code. You always end up just writing a wrapper round it.

~~~
eel
There are ways in the .NET framework to read an entire file with one line:
File.ReadAllText("file.txt"). And the System.Net.WebClient class provides ways
to make simple HTTP calls in much fewer lines than WebRequest does.

Likewise, Python has ways for interacting directly with streams.

~~~
emn13
WebClient's API is essentially buggy; it cannot support encoding properly
since the order of operations of the API is different from in HTTP, and
further the response headers aren't properly exposed to let you work around
the limitation.

It's fine for a quick hack, it's useless for a reliable web client.

------
sultezdukes
Good writeup, and I agree with much of his post. Going back to Java from C# at
the language level is just painful.

The Java library/framework is more complete and diverse than the .NET one, but
it's actually improved alot for .NET in recent years with Microsoft becoming
much more open source friendly, the ALT.DEV community, Mono, etc... The .NET
community is much more comfortable with alternative not from Microsoft these
days than in the past.

IMHO though, the JVM has a better alternative language ecosystem than the .NET
one. Yeah, .NET has F# builtin to VS these days, but doesn't have things like
Scala/Clojure (not first class citizens), Kotlin, Ceylon, etc...

~~~
brass9
> IMHO though, the JVM has a better alternative language ecosystem than the
> .NET one. Yeah, .NET has F# builtin to VS these days, but doesn't have
> things like Scala/Clojure (not first class citizens), Kotlin, Ceylon, etc...

And the irony is: .net was touted initially as a polyglot platform, whereas
JVM has been primarily associated with Java only.

~~~
sultezdukes
There's really not much irony there. VB.NET and C# were released together from
the beginning, where Sun only thought of Java (the language) until too late in
the game for them.

Sun was screwed because of factors beyond Java, but because of internal
politics there, they never realized the full potential of the JVM.

