Chapter 1 - 99 bottles of OOP

Vincent Nguyen 19 June 2017
ruby, oop

Chapter 1: Rediscover Simplicity

In the chapter 1, the author has introduced four ways to solve a problem named 99 bottles. Basically, the problem is not difficult but it has many cases - these four ways that author shared are common ways to solve this problem.

Below are my notes after finished chapter 1.

For example, almost we know about principles to refactor the code such as DRY or Single Responsibility. DRY and Single Responsibility are great ideas, but that doesn't mean it's free. Extract methods to many small methods to make sure single repsonsible for each method, or extract the duplication into a single common method then invoke this method in place of the old code, the price you pay for these ways is that the invoker of new method no longer knows the result, only the message it should send.

The example above proves one thing: combining many ideas into a small section of codes make it difficult to isolate and name any single concept. This example named call, uses a facebook authentication token, verify it before get facebook user information. You see, three missions in a method named call

Hence, code clarity is built upon names. Writing code is like writing a book, your efforts are for other readers.

  1. How difficult was it to write?

  2. How hard is it to understand?

  3. How expensive will it be to change?

The first question is a memory, the last question is imaginary but the second question is true right now, always applies.

Therefor, the author said: You should name methods NOT after what they do, but after what they mean. You should name methods after the concept they represent.

That's all about chapter 1.