October 4, 2012
@ 01:15 AM

Notes of read book "clean code"  by Robert C. Martin

SRP: Single responsibility
DRY: Don't repeat yourself
OCP: open close principle

1. Switch break the SRP and OCP, should limit it in bottom and factory.
2. Try catch should keep it small ,and no code after try catch block
3. Use exception in stand of ErrorCode
4. Each function should has only one return...try avoid  break, continue, never use goto
5. one parameter is better than two parameters and better than three or more
6. Make sense Name and comments
7. First write the code as you think, then refactor to follow the principle
8. Don't return or pass null, empty list is much better
9. Put Error handle code out side the main logic

Something in the book I don't agree is for Name convention,
he don't like name interface with prefix 'I', and don't like put the type in classname such as AbstractProduct or Iproduct.

But I think that make our life easier when we code...if you need a interface,  With the help of Intelli come with VS or ReSharper ,you type 'I', it will jump out, if you need a Enum...type Enum..all Enum named start with Enum will list for you to choice.

Categories: Agile | C# | OODesign

September 16, 2012
@ 02:47 AM
I have some thoughts for making better code. I call it 3 rulers plus 2 sub rulers.

1 Readable : small function, single responsibility, straightforward name convention.
2. Re-useable: clear and simple responsibility, DRY
3. Testable : can be tested by UnitTest tools. Also I like write code that I can easily put a break point there.


4. flexible :  Prepare for future change,  configurable, lower coupling. using IoC.
5. performance: improve code for better performance or user experience, Threading, Cache, Ajax, Parallel LinQ,

4 and 5 have lower priority than 123.   You should know why ;)

Categories: C# | OODesign