64 points · by aashishkoirala · 12y ago · 76 comments
Personally, however, I think C# as a language strikes the right balance in terms of power, ease-of-use, learnability and code readability. Even if you have a problem with Microsoft, I think it is wrong to let your "MS-hate" translate into "C#-hate". It is a beautiful language and the open-source community around it is growing rapidly. The progress made by platform-independent endeavors (case in point Xamarin) is admirable.
In the unlikely scenario that all of programming were to converge into one language, I would want it to be an open-source, platform-independent version of C# (with maybe just a tad more constructs borrowed from the functional programming world).
P.S. I also think it is a mistake to lump C# and Java in the same bucket. Ten or more years ago, maybe. Today, they are VERY different.
Was wondering what, in your opinion, are the largest differences between Java and C#? It's been a long time since I've done any Java, and while I can definitely name a bunch, I thought it'd be interesting to get your take on the most impactful or meaningful differences.
In terms of differences with Java (and limiting this to just the language and the syntax), LINQ is a good example of it :) I guess you could classify a lot of the other differences as synctatic sugar, but those little things add up and make a real difference in terms of code brevity, readability and developer productivity. To name a few (and I know that Java, especially with v8 has started adding support for some of these): Properties (and auto-properties), Delegates, Events, Lambdas/Anonymous Functions/First Class Functions, Extension methods, "using" for IDisposable (although Java 7 has something similar in AutoClosable), the lack of forced checked exceptions, the newly added async/await keywords, object and collection initializers and anonymous types, etc.
F# is definitely a nice language. I haven't done any large scale projects in it, but what I have done has been very nice. Check out type providers if you haven't already. They're really interesting and handy. I switched over to F# as my side/fun language from Clojure when my day-job became .NET. It's not that I'd say they're equivalent languages, but the way of thinking about most things was similar enough that it felt right. On top of that, it was nice having a fairly strong type system to back things up. It meshed more with how I think about things.
Hah, I probably should have assumed LINQ would top the list of a linq post. I remember before I knew what LINQ was about. Once I started using it, it quickly became one of my favorite parts of the language/ecosystem.
I really do feel that the things you've mentioned do make it a much cleaner and more consistent language than Java. I've got a friend who switched from full time Java to C# recently. I'll have to see what he thinks as well.
I regret I didn't knew about it when I wrote my first LINQ provider.
I used it to build a LINQ provider for a legacy mainframe database system, abstracting away the incomprehensible table and column naming, weird date systems, EBCDIC, and other nastiness involved in querying that system using straight-up SQL.
One thing I found is that implementing a custom LINQ provider gives you a better understanding of how Entity Framework runs your queries. You get to see how queries get split up into the parts executed in the CLR versus the parts that get translated, and how expressions get rearranged and rewritten.
C# is a great language, and there are several libraries with fantastic design aesthetic; one that is much better than most of Ruby/JS.
It's painful when you have to go into your IDE, step through a bunch of stuff, just to make a small change, and then a couple minutes goes by before you can check your work. Integrate some larger testing, and it's worse.. try to break you project up into smaller libraries (as you would with node) and it gets worse.
Don't get me wrong, I really like C#, and love the Razor view engine... but .Net and VS as a whole just feel really sluggish and bloated. With node, I can fire up an app, and include modules with relative ease.. I don't get the same level of intellisense as VS with C#, but I find I need it quite a bit less, and tend to be just as, if not more productive.
I started with C# in mid 2001 (before VS.Net RTM), and until Node.js it was by far my favorite environment.
I mean, C# is a fantastic language, but a lot of the libs MS has bundled into it are absolutely horrible and people use them anyways because they're the blessed first-party product. And rather than fixing the problems, Microsoft simply creates a new replacement lib with a new approach. I mean, how many kicks at the can did they get with remoting? DB access? Serialization?
Microsoft has gotten a lot better recently, taking an open-source-style development approach to Entity Framework and MVC, but they're very late to this particular party.
.NET has been around for a long time, long enough to have gone through the rise an decline[1] of many open source alternatives:
DHTML, PHP, Python, RoR, NodeJs
And the language and framework has been thoughtfully improved over that period of time.
> Microsoft's bloated and broken enterprise tools instead of sensible, rapidly-released libs.
Developers have been writing great software with these tools for decades.
And rapidly-released libs could just as easily be classified as "not-yet-ready-for-production."
> I think the big problem is that MS
In my estimation, the biggest problem is that using .NET "requires" the rest of MS along for the ride. Yes you can use mono, yes you can use apache, but everything just works if you use the WINS stack.
I like .NET and I really like C# as a language, but I'd rather have my infrastructure be linux.
[1] Not all of these have "declined", but popularity has shifted focus.
I do not mean to raise the ire of defensive .NET programmers by saying this: as with most things, used right it is a beautiful thing, and there is nothing fundamentally wrong with LINQ. But what it was used for in practice was almost always grotesquely inefficient.
If someone had to make a loop to iterate objects to find a member on every function call, pretty soon they'll realize they should using a System.Collections.Generic.Dictionary for instance, or some other appropriate data structure (e.g. Need sorted data? Then use a sorted tree, for instance). When it's a simple LINQ query, though, it's one seemingly harmless little line, so it tends to get a pass.
Pretty soon profiles were just hundreds (if not thousands) of different cases where LINQ was used as a cure-all, destroying performance under any load at all.
LINQ is not magical. It is doing the same dirty work that you would be doing yourself if you needed to filter / sort / recast, but provides syntactical sugar to do so. The compiler and runtime will happily generate horrifically inefficient code if you request it, with no warning or complaints.
The tldr; is that it is a fantastic set abstraction that is more often than not grossly abused.
I think the real problem is Cargo Cult programming. People are using linq (especially in combination with EF) and not understanding what's actually going on. So they end up getting things like n+1 selects on collections with thousands of items. They don't understand delayed evaluation. Or how sorting effects a Where() call.
The problem is programmers who think they can take some code from stack overflow and use it without outstanding it. That problem is not unique to LINQ or .NET.
It absolutely isn't unique to it -- powerful features allow programmers to shoot themselves in the feet, and this is true since we began this profession.
When dealing with larger applications and datasets it has the potential of easily imposing enormous costs, of the sort that absolutely eclipse most other anti-patterns. Appending on an immutable string through recursive function calls suddenly looks like child's play.
The truth is that in most apps, these inefficiencies simply don't matter, and to all of the "just learn how to use it right!" replies, I would say that odds favor that those people aren't using it right at all. But in the end it just doesn't matter that much because small amounts of data, low demands, etc, just makes it an irrelevant cost. Most apps are running with an excess of CPU resources relative to the demands on the app, so it just doesn't matter.
Many .NET developers have never run Visual Studio's profiler. They don't even know what the costs are, but we're in a world where 1500ms to load a basic form is okay.
When you deal with very large scale financial data, as I do, however, your world is a very different world. You don't just have a scrum where you try to teach people that LINQ isn't magic (which of course we did). The risk factors become much higher.
I find it incredible when I see comments like this. What you should have done is instigated a mentoring programme for the programmers who aren't yet up to speed. LINQ is one of the best things to happen to the language and you just go and kill it.
Also, check out LinqOptimizer -- it analyzes your LINQ queries and can optimize them for better performance (and it's free!): https://github.com/nessos/LinqOptimizer
For example, all queries that are generated for database calls via LINQ are reviewed and analyzed to make sure its what is expected.
You are right, LINQ is not magical and was never meant to be. I don't think using LINQ is an automatic ticket to leave your brain at the door.
In your case, it's easier to blame the tech and stop using it than to take responsibility for training the team to be better developers.
I would also imagine that on this team the use of var was also restricted?
LINQ is really one of the best things in .NET. Just like any tool, you need to learn it before using it properly.
Believe what you want. I will say again that of the three "I can't believe it!" responses thus far, I'll bet zero have ever even run their profiler. Ignorance, as they say, is bliss, and in many cases is perfectly fine.
You need to know how to parse function bodies and I strongly suggest algebraic types approach, e.g., using SpecificType v = genericTypedVar as SpecificType and checking if v != null. You have to write your own parametrized type supporting Where, Select, etc.
And you're good to go.
It took me three days to write first LINQ-like thing.
That said, I think for stuff that is supported, better to stay within the "standard approach".
But I get your point.