Sayfalar

15 Haziran 2015 Pazartesi

Clean Code

I read the “Clean Code : A Handbook of Agile Software Craftsmanship” book. It is realy good book , and I’m very satisfied. For me and who want to write clean code I selected fundamental and important tips from book,  here the list for writing clean code ;

-LeBlanc’s Law : Later equals never.(Yeah ! I know it is not about code code , but all of us know why i put it here...)

Meaningful Names

- The word “variable” should never appear in a variable.
- Single-letter names can only be used as local variables inside short methods.
- Classes and objects should  have noun or noun phrase names.
- Function names should verb or verb phrase names.
- Say what you mean. Mean what you say.

Functions

-The first rule of functions is that they should be small. The second rule of functions is that they shoul be smaller than that.
- Functions should do one thing. They should do it well. They should do it only.
- The ideal number of arguments for a function  is zero. More than three arguments requires very special justification.
-Flag arguments are ugly.
-Functions should either do something or answering something, but not both.
-Prefer exceptions to returning error codes.

Comments

-“ Don’t comment bad code , rewrite it. ” Brian W.K and P.J. Plaugher
-TODOs are jobs that the programmers thinks should be done, but for some reason can’t do at moment.

Formatting

-Every programmer has his own favorite formatting rules , but if he works in a team , then the team rules.

Objects and Data Structres

-Objects hide their  daha behind abstractions and expose functions that operate on that data. Data structre expose their data and have no meaningful functions.

Classes

-They should be small.
-Class or module should have one, and only one reason to change.
-In a clean system, we organize our classes so as to reduce the risk of change.

Unit Tests

-Write unit tests first , before writing production code.
-If you don’t keep your tests clean, you will lose them. And without them, you lose the very thing that keeps your production code flexible.
-Cleant test codes should follow the FIRST rule.(Fast, Independent, Repeatable, Self-Validating, Timely).