zashii-1434

Stats of My Life(おいしい人生を味わうために、コツコツとチャレンジしたことを書くブログ)

「リーダブルコード ―より良いコードを書くためのシンプルで実践的なテクニック (Theory in practice)」読みました。(2017年15冊目)"Readable code - Simple practical technique for writing better code (Theory in practice)" I have read. (15th year of 2017)

リーダブルコード ―より良いコードを書くためのシンプルで実践的なテクニック (Theory in practice)

リーダブルコード ―より良いコードを書くためのシンプルで実践的なテクニック (Theory in practice)

 

 

■感想


エンジニアの中では有名な本なものの、きちんと読んだことがなかったので
読んでみました。

 

感想としてはとてもわかりやすいかったです。
もっと早く読んでおくべきだったなあと思います。

 

ちなみにスクーにもリーダブルコードの授業があります。
こちらと合わせて読むと、より理解が深まると思います。

 

schoo.jp

 

<メモ>


第1章 理解しやすいコード

・コードは他の人が最短時間で理解できるように書かなければならない

第2章 名称に情報を詰め込む

・明確な単語を選ぶ
・汎用的な名前を避ける
・抽象的な名前よりも具体的な名前を使う
・接尾辞や接頭辞を使って情報を追加する
・名前の長さを決める
・名前のフォーマットで情報を伝える

第3章 誤解されない名前

・名前が「他の意味と間違えられることはないどろうか?」と何度も自問自答してみる

第4章 美しさ

・読み手が慣れているパターンと一貫性のあるレイアウトを使う
・似ているコードは似ているように見せる
・関連するコードをまとめてブロックにする

第5章 コメントすべきことを知る

・コメントの目的は、書き手の意図を読み手に知らせることである

第6章 コメントは正確で簡潔に

・複数のものを指す可能性がある「それ」や「これ」などの代名詞を避ける
・コードの意図は、詳細レベルではなく、高レベルで記述する

第7章 制御フローを読みやすくする

・比較対象
 ・左側は「調査対象」の式。変化する
 ・右側は「比較対象」の式。変化しない

・条件は否定形よりも肯定系を使う
・単純な条件を先に書く。

第8章 巨大な式を分割する

・巨大な式は飲み込みやすい大きさに分割する

第9章 変数と読みやすさ

JavaScriptでは変数の定義にvarをつけないと、その変数はグローバルスコープに
入ってしまう。

第10章 無関係の下位問題を抽出する

・プロジェクト固有のコードから汎用コードを分離する

第11章 一度に一つのことを

・一度に一つのタスクを行うことを考える

第12章 コードに思いを込める

・プログラムのことを簡単な言葉で説明することで、コードがより自然になっていく

第13章 短いコードを書く

・コードをできるだけ小さく軽量に維持するしかない。
 ・汎用的なユーティリティコードを作って、重複コードを削除する
 ・未使用のコードや無用の機能を削除する
 ・プロジェクトをサブプロジェクトにする
 ・コードの「重量」を意識する。軽量で機敏にしておく

第14章 テストと読みやすさ

・テスト関数に説明的な名前をつけて、何をテストしているのかを明らかにする

 

■Impression

Although it is a famous book among engineers, I have never read it properly

I tried reading it.

 

As impressions it was very easy to understand.
I should have read it earlier.

 

Incidentally, there is also a class of readable code on the school.
I think that understanding will deepen as you read it together.

 

schoo.jp

 

<Memo>


Chapter 1: Easy to understand code

· The code must be written so that other people can understand in the shortest possible time

 

Chapter 2 Stuffing Information in a Name

· Choose clear words
· Avoid generic names
· Use concrete names rather than abstract names
· Add information using a suffix or prefix
· Decide the length of the name
· Tell information in format of name

 

Chapter 3 Misunderstanding Name

· Try to ask yourself a number of times that the name "will not be mistaken for other meanings?"

 

Chapter 4 Beauty

· Use a layout that is consistent with the pattern that the reader is accustomed to
· Similar code looks similar
· Block related codes together

 

Chapter 5 Knowing what to comment

· The purpose of the comment is to inform the reader of the intention of the writer

 

Chapter 6 Comments are accurate and concise

· Avoid synonyms such as "it" and "this" that may refer to multiple things
· Describe the intention of the code at a high level instead of the detail level

 

Chapter 7 Making Control Flow Readable

·Comparison
· The left side is an expression of "subject of investigation". Change
· The right side is the expression of "comparison target". It does not change

· Condition uses positive system rather than negative type
· Write simple conditions first.

 

Chapter 8 Split huge expressions

· Huge formula to split into easy-to-swallow size

 

Chapter 9 Variables and Readability

· If you do not add var to the variable definition in JavaScript, the variable gets global scope
It enters.

 

Chapter 10 Extracting irrelevant subordinate problems

· Separate generic code from project specific code

 

Chapter 11 One thing at a time

· Think about doing one task at a time

 

Chapter 12 Thinking about the code

· By explaining the program in simple terms, the code will become more natural

 

Chapter 13 Writing Short Code

· You have to keep the code light and light as small as possible.
· Create generic utility code and delete duplicate code
· Delete unused codes and unnecessary functions
· Make a project a subproject
· Conscious of the "weight" of the code. Keep light and agile

 

Chapter 14 Testing and Readability

· Provide a descriptive name for the test function to clarify what you are testing