What is Wrong with C#

How C# Can Be Improved

Eric Harty
C# is my programing language of choice, so this is not an attack on it, but more of a guide towards improvement.

First C# should have tuples. When I first started using Python I found tuples to be annoying, and unnecessary, but now I wish that they were available in more languages. Too often I find myself creating a struct to act as a tuple class for me. While this works the workaround should not be needed.

C# should get rid of the decimal type. The fact that there is a decimal type that is separate from a double is simply confusing. Most programmers are used to defining close to all of their numerical variables as either int or double, so to present this additional value type in a number of gui components just forces a lot of casts that shouldn't really be needed.

Strings should also autocast. In Java whenever you concatenate a non-string object to a string, the toString() method is called automatically. C# on the other hand forces you to write out all of the casts. While the underlying code ends up being the same for both situations, the Java approach to this is cleaner, and easier for the programmer.

Variables should scope in the same manner that they do in most other programing languages. In that you can re-use a variable name as a different variable within a loop or conditional. While banning this does make some things simpler, it can be quite a pain to be forced to come up with a different throw away variable after being allowed to use the same one in other languages.

using System.Web needs to be simpler. Unlike almost all other .Net components, when you use system.web instead of simply working you need to go and explicitly add it as a reference. While I understand why this type of opt in system would be wanted for COM components anything that is .net anyhow should simply just work, or at the very least be automatically added as a reference by visual studio.

There needs to be a simple way to write multiple sorting algorithms for custom made objects so that arraylists and the like can be sorted by different components by using simple method calls. The current simplest system requires you to declare delegates as an argument within the arraylist's sort method. While this works there is no reason that this couldn't be simpler.

Every event argument should not require both an object sender and EventArgs e, more often then not both of these values are simply ignored, so they should be optional. Yet these two values are passed whenever anything happens regardless of if they need to be used or not.

These seven issues are all things I would love to see fixed in C#. Still the list is mostly small, and workarounds are available for most of these gripes, but that doesn't imply that changes would not be nice.

To comment, please sign in to your Yahoo! account, or sign up for a new account.