“What major advantage does the C# language have over and above the Java language?“
My first thought was “attributes“ which allow developers to tag code with metadata that can be programmed against but I was sure there was more. Since I’m not a C# guru I did a quick web search and found a great essay entitled "A comparison of Microsoft’s C# Programming Language to Sun Microsystem’s Java Programming Language" by Dare Obasanjo.
Dare listed the following things C# has that Java does not:
- Deterministic Object Cleanup
- Value Types (Structs)
- Run Time Type Identification (as operator)
- foreach Statement
- Multidimensional Arrays
- Preprocessor Directives
- Runtime Code Generation
- Pointers and Unsafe Code
- Pass by Reference
- Variable Length Parameter Lists
- Verbatim Strings
- Overflow Detection
- Explicit Interface Implementation
That’s a lot! Though that list is great, it was written as a list for developers, not managers. The question then would be, which of these differences could actually translate into a benefit a manager could appreciate?
I’ll take a stab at this, but would love comments from others on how to best present C# as having values business people can appreciate. I can’t find a direct business benefit for some of these features:
- Without Deterministic Object Cleanup Java apps could create unacceptable performance bottlenecks after deployment, which could cost a lot of time and money to fix.
- Delegates allows a more flexible implementation of callbacks, which reduces the complexity of code and reduces the likelyhood of logic errors.
- Enumerations increase robustness by providing type checking and reduces “copy&paste“ errors because enumerations can be converted to their string equivalent. Java developers will need to spend more time testing and debugging.
- Properties allow more natural syntax. If Java programmers “get lazy“, write directly to fields, and later need to trigger code on a field assignment, they have to modify a lot of client code. If they get lazy in .NET, they can just change the field to a property w/o affecting client code. However it does take a recompile (I’ve always hated that about .NET)
- Attributes allow developers to embed metadata and program against that metadata. This increases the power and flexibility available to a software architect designing an application framework. .NET modules are discoverable which greatly reduces the need to distribute related information across multiple source files. This reduces potential errors and hence testing and development time as well as increases reliability and robustness. In my mind this is probably one of the strongest benefits of using C# over Java.
- Runtime Code Generation allows an application to implement its own extensions based on user imput. Most developers will never attempt this, but when it is useful there really isn’t an alternative.
- Overflow Detection increases robustness and reliabiliy because potentially critical errors that might go unnoticed in Java will be caught by the .NET runtime.
- Explicit Interface Implementation can offer significant cost savings when naming conflict occur during code integration, especially if those conflicts are in 3rd party components.
That’s my list. BTW, I think VB.NET offers all the same benefits. Do you have more?