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