Writing simple c# code

I’m doing a lot of code reviews at the moment and thought I’d write up some thoughts on simplifying c# code.

What is simple code?

simple code is code that amongst other things
* fits on a single screen
* can be understood pretty much at a glance.
* has simple logic
* has well-understood side effects – preferably none
* often make use of LINQ.

Why write simple code?

  • Simple code can be understood quickly.
  • Simple code can be checked for correctness.
  • Simple code can be tested easily.

When are you done?

There are tools to measure how complex your code is (google Cyclomatic complexity for examples) but for my purposes, once you have met the requirements in the first list, you’re there!

Advertisements


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 )

Google+ photo

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

Connecting to %s