• November 2014
    M T W T F S S
     12
    3456789
    10111213141516
    17181920212223
    24252627282930
  • Latest Posts

  • Latest Comments

  • Archives

How to Write Bad C# Code

In case you’re afraid Microsoft might help you write some good C# code, here’s a list of the top tips to make sure you still write bad C# code.

Now I’m sure that’s not the objective, but when you read this post you’ll frankly wonder why it is that we still see so much bad code being written!

Do NOT Learn to Use Visual Studio 2013

This is by far the most important of these items. Make sure you don’t know about Code Analysis – that will baby-sit you and tell you when you make common coding mistakes. If you do stumble across it, be sure to leave the default of Microsoft Managed Recommended (for weak code) Rules rule set. Or better yet, set it to Microsoft Managed Minimum Rules. Whatever you do, if you have discovered Code Analysis, don’t go to the Code Analysis tab for your project properties and set it to Microsoft All Rules. You will be frustrated that you might have to stop and learn how to write proper code to avoid these warnings.

Do NOT Pair Program with a Good Developer

You might actually learn something if you do. I learned the most by working with developers better than myself and watching them closely. You also don’t want to do this because you might learn some tricks about fast navigation or other productivity tips.

Do NOT Write Unit Tests

This really slows you down if your metric is lines of code per day. Most won’t count the lines of code in the tests toward your number. Also, not writing unit tests is great job security. Who else in your organization will want to come in and take over maintaining “your code base” (BTW… If you work for someone, it’s not your code as much as you’d like to think it is.)

Unit tests also mean that you’d actually have to stop and think about what is expected of the software.

Unit tests mean that if you changed something, you know if you broke something.

Unit tests mean that if you want to refactor your code, you can – quickly.

Some Microsoft Visual Studio Project templates actually offer you the ability to create unit tests for your project.

I’ve NEVER seen writing unit tests make someone’s code worse – only better. So stay very clear of these if you want to keep writing bad code.

Do NOT Get Any Visual Studio Extensions

There are some tools out there that, for example, will check your spelling in comments. Oh… Wait, your writing bad code. There won’t be any clarifying comments anyway. But there are some others that will do things like reformat your file as well as sort your using statements and removed unused using statements upon save (Productivity Power Tools).

Summary

The notion of this post isn’t to actually write bad code, but to show how hard you’ve got to work to stick your head in the sand and not leverage the tools provided to constantly improve your code.

I’ll update this over time as I get feedback from others.

Thanks – Karl

Leave a Comment