Clean Code

full video

Uncle Bob likes OOP

Speed and efficiency

Kent Beck wrote a book called “implementation patterns”. He said that good code is built on a “fragile premise”

Porgrammers are slow because they start of going really fast implementing features left right and center. After a year or so the code becomes so messy that touching even a single line of code could release a deamon because they write messy. As a result adding new features is slow because it is hard to work out what is going on with the code. Eventually the team will bottom out and can’t add more features fast enough. So what do managers do? They add more people. These new people need to be trained by the seniors and they learn from the current code base which is still a mess and the team is slowed down even more. If we didn’t make a mess adding new features will be fast. The desire to go fast is what drives messy code. No one writes clean code off the bat. You should then spend the same amount of time refactoring as you took to write the code. ** Refactoring time == time taken to write in the first place ** > The Only way to go fast is to go well

One Thing

A function should do one thing and one thing well. Every line of a function should be at the same level of abstraction. The Rule of Functions:

  1. They should be small
  2. They should be smaller than that

A Functions does one thing if you cannot exctract a meaningful function from it. You continue naming them and extracting into modules or classes.
All large functions are really classes with little functions inside them, you can turn it OOP. The indent level shouldn’t be greater than one or two. Number Arugments:

> Clean code is simple and direct, clean code reads like well-written prose > — Grady Booch

> Clean code awalys looks like it was written by someone who cares > — Michael Feathers

> You know you are working on clean code when each routine you read turns out to be exactly what you expected… > — Ward Cunningham

It is more important to communicate code to your peers than the computer. It is better to write code which your peers understand rather than code which works and only the computer understands.

Explainatory Variable - one who’s only purpose is to explain the data it holds

Open-Close Principle

A system should be open for extention and closed for modification. You can do this with abstract base classes -> avoid switch statements.

Side Effects

Command Query Separation

A Function which returns void must have a side effect. A function which returns a value shouldn’t change the state of the system. It is better to use an exception than to return an error code. Keep your code D.R.Y

Part Two