5 Things I Hate about my Favorite Programming Language: C#

In episode 73 of the StackOverflow podcast , Jeff Atwood mentions one of his favorite questions to ask developers, “What are 5 things that you hate about your favorite programming language?”

It got me thinking. I definitely like some of the language features of C#, especially when developing within Visual Studio. Some of my favorites are Generics, Intellisense, and Short-Circuited conditionals. However, there are other pains that I encounter repeatedly when it comes to language syntax.

 

  1. In C#, there is the nifty syntax of following a variable with “??” allowing the developer to specify a replacement value in the case of the variable being null. In theory this is a great feature. However, I never end up getting to use this and I imagine that is the case for most developers. I find I usually end up using the “?” and “:” syntax because I typically want to use a member of the null object like “user.Identity.ToString()” but I have to check if “user” is null or I will get an object reference error.
  2. Why do I always have to lookup how to format a DateTime object in code without the minutes?
  3. If “ToString()” is a member of every object, why should I have to explicitly call it when setting the value of a string variable from another non-string variable? As an example, why can’t a string value be inferred from my int variable by just calling “ToString()” when there would otherwise be a type issue?


    int i = 0;

    string j = String.Empty;

    j = i;

  4. The compiler considers the use of “=” valid within an if condition. This can be confusing and often causes accidental issues where “==” is the intended code. As a solution, I use a coding standard of typing the constant value to be compared first because it cannot be assigned to (i.e. “if (0 == count)”).
  5. Nullable types seem like a great idea but they are not always intuitive. In the example below, the code seems like it should work. However, I receive a compiler error on the second line.


    int? i = null;

    i = (sender != null) ? sender.GetHashCode() : null;

 

Most of the above complaints were compiled off the top of my head. If you have found a better way to leverage the C# language so that you do not run into these issues, please share them with me in the comments. Perhaps it is my mis-use of the language features that has caused my agony.

Advertisement

About Stu
I am a software developer living in Cincinnati, OH. I primarily focus on .NET and Microsoft technologies and have bounced around quite a bit in my short career between multiple cities in the Midwest (including Cleveland, Columbus, Cincinnati, and St. Louis). I would like to learn more about programming, technology, marketing, and how to run a business. -Nathan Stuller

One Response to 5 Things I Hate about my Favorite Programming Language: C#

  1. brian d foy says:

    Curiously, that’s my favorite question, and maybe Jeff saw it in my Stackoverflow post from 2008. I actually started thinking about this when I was writing Mastering Perl in 2005, and it shows up in the introduction for that book. The trick from jumping from apprentice to master requires that level of thinking. I also mentioned it on use.Perl, in response to someone trying to push Ruby onto me, as I recall.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: