Coffeehouse Thread

25 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

C# biggest awesome

Back to Forum: Coffeehouse
  • User profile image
    Bass

    This is the mathematical dual to the "C# biggest mistake" topic. What do you think is C#'s best feature?

     

    As a former .NET programmer now professional Java programmer, I have think I have a pretty good perspective on C# in relation to Java. And the single thing that I think could be most useful in Java would be delegates (and the closures/lambdas, but even just delegates would be a godsend).

     

    Event-driven programming is so crappy in Java that many Java programmers will do everything to avoid it. For example, to do what a simple event does in C#, you'd need to write an single method Interface and than wire a collection to a subscribe, unsubscribe and fire method in the producer. For every event! Talk about file pollution.

     

    And the result is still inadequite compared to C#. I still can't pick my own method names for subscribing to the event, that's part of the interface...

     

    I've noticed that a lot Java programmers don't see anything wrong with polling on a method every few seconds instead of writing an event. Seriously!

     

    So what are your thoughts? What you consider C#'s best feature?

  • User profile image
    Adam​Speight2008

    Pure Simple. It doesn't look like VB.  Wink

    It looks like a "proper" programming language, like c or Java.

  • User profile image
    figuerres

     hard to name just one but in the top is LINQ as one of the killer bits.

  • User profile image
    spivonious

    I'm a VB guy, but I agree that delegates and events are two things that Microsoft got right with .NET. I did some Java programming in college and I had forgotten what a pain events were. Using the VB event model was the right choice.

     

    I am curious Bass, after using both .NET and J2EE in a professional context, which is your favorite?

  • User profile image
    SlackmasterK

    Anonymous functions and Thread.Tasks

  • User profile image
    ManipUni

    The ecosystem. The worst thing about Java and best thing about C#.
     
    C#: 90/10 writing code Vs. fighting with the tools/environment/library
    Java: 10/90
     
    Is that cheating? Likely. But it is still true. C# isn't a very much better language than Java. But the tools/environment/documentation is terrible in Java.

    I think this code example sums up both C# and Java perfectly:
    if(args[0] == "test")

  • User profile image
    exoteric

    LINQ - one syntax to query {any,every}thing {any,every}where

    Disclaimer: Not just a C# feature and not just a language feature though.

  • User profile image
    Richard.Hein

    I agree that events/delegates are at the top of the list.  I also appreciate LINQ, and generics, but that's a .NET thing, not C# per se.  Many of the newer features are excellent, like extension methods, object initializers, automatic properties.  Most of all however, the way that the C# designers have embraced change and implemented features, like the new async CTP stuff, is really great.

  • User profile image
    BitFlipper

    Pretty much everything everyone else mentioned, but one huge one to me compared to C/C++ is no more header files Big Smile . Yes this isn't unique to C# but coming from C/C++ it is a very nice improvement (not to mention all the benefits of a managed language).

     

    Another one for me is closures as I use it a lot in cases where I have different nested blocks of code running on different threads (even back when I was using .Net 2.0, before things like TPL made this commonplace - I had my own similar parallel library).

  • User profile image
    BitFlipper

    For a surprisingly detailed and (seemingly) up to date comparison of Java vs C#, see this. I didn't realize just how different they were feature-wise until I read through the whole thing.

  • User profile image
    cbae

    LINQiggidy

  • User profile image
    cbae

    , BitFlipper wrote

    For a surprisingly detailed and (seemingly) up to date comparison of Java vs C#, see this. I didn't realize just how different they were feature-wise until I read through the whole thing.

    Feature-wise, C# looks to be the more refined language despite Java's having being around longer.

  • User profile image
    vesuvius

    It has to be Linq to objects for me. I was slow see what the fuss was about initially, but it makes for some very readable code that is far easier to maiintain that without it.

     

    I also think that it's popularity is also a great strength because there are a lot of examples and projects o the web that reduce development time.

     

  • User profile image
    BitFlipper

    Nobody mentioned P/Invoke vs JNI yet? I recently had to work on some JNI stuff and the difference between P/Invoke and JNI is mind-blowing...

    I know about JNA but my understanding is that it could be 10x slower than JNI, which could be a problem if the reason you are calling native code is performance related.

    I guess P/Invoke has an "unfair" advantage in that MS probably knew early on that it had to work well because there would be so much functionality missing in .Net (at least initially) that people would just have to P/Invoke into Win32. Whether that is true or not I don't know, but having this functionality be a first-class citizen is a nice bonus either way.

  • User profile image
    Bass

    Woops, it looks like I started something quite nasty here with this thread. Smiley I mean to make a Java vs C# war, but I guess there was no helping it.

     

    , ManipUni wrote

    The ecosystem. The worst thing about Java and best thing about C#.
     
    C#: 90/10 writing code Vs. fighting with the tools/environment/library
    Java: 10/90
     
    Is that cheating? Likely. But it is still true. C# isn't a very much better language than Java. But the tools/environment/documentation is terrible in Java.

    I think this code example sums up both C# and Java perfectly:
    if(args[0] == "test")

     

    My opinion is quite the opposite on this one. Java's weaknesses are wholly on the language itself, not the libraries and definitely not the JVM.

     

    Java it's the vast Java ecosystem is probably one of it's biggest assets. Nothing really compares in the .NET world to JBoss, Spring and Apache. Hundreds or even thousands of high quality FOSS libraries from these sources.

     

    I know Microsoft is trying to change that with their CodePlex ("Outercurve?") Foundation, but there is really is no comparison here.

     

    And that's really just comparing the FOSS ecosystem, and not the products from the Java powerhouses like IBM, Oracle, TIBCO, SAP, etc.

  • User profile image
    BitFlipper

    I have to agree that Java does have a huge amount of community code that you don't find for .Net. However, in my limited experience with working on a Java project, I found the following:

    We needed the ability to consume a web service in Java (create stubs from WSDL at compile time given a web service URL), and for a test service I used ServiceHost .Net 4.0. It took me literally 20 minutes tops to create the service in .Net that exposed a simple Hello World method.

    Then I searched around for a way to consume the web service in Java, and initially settled on Axis2. After a huge amount of effort and hair-pulling, we discovered that the reason things just didn't work was because there was a bug in the Axis2 OSGi bundle and some dependencies were not properly included (Eclipse tries hard to make it easy to manage dependencies and versioning but when things go wrong...). The whole point of an OSGi bundle is to be a self-contained bundle that can resolve all dependencies.

    Eventually we gave up on Axis2 and went to CXF. After we got that figured out and the project in Eclipse configured to automatically pull in the WSDL and create the stubs at compile time, things started to work better. However the amount of code that was automatically generated from the WSDL was mind-boggling. Not that it really matters but compare to what you get with WCF. Also using the service in Java is not straight-forward, as the structures you exposed in the service are wrapped in special classes.

    So what is my point? Well, at least in my experience, .Net contains a lot of functionality that you need 3rd-party support for in Java. WCF is light-years ahead of similar functionality in Java, and you don't need to depend on external libraries that are potentially quite buggy and unsupported. If our whole project was in .Net 4.0, it would have been a breeze since we would have been able to use WCF from start to end.

    I'm not saying this is true in all cases, just that .Net is quite complete and at least from my experience one doesn't need to rely so much on community supplied functionality.  

  • User profile image
    Bass

    We use Spring MVC for RESTful web services server side, and Spring RestTemplate for RESTful web services client side.

  • User profile image
    elmer

    For me, although it's more a .net thing... the garbage collector... and the fact that I can get away with being so damned lazy about cleaning up after myself... LOL.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.