[JAVA] [In-house study session] Introduction of "Readable Code"

0. Introduction


Target person


What is "Readable Code"?

参考図書.jpeg


What i want to tell

Notes


Table of contents of "Readable Code"

Chapter 1 Easy-to-understand code

Part I Superficial improvements Chapter 2 Packing information in the name Chapter 3 Names that are not misunderstood Chapter 4 Beauty Chapter 5 Know what to comment Chapter 6 Comments are accurate and concise

Part II: Simplification of loops and logic Chapter 7 Make the control flow easier to read Chapter 8 Divide a huge formula Chapter 9 Variables and readability


Introduction of "Readable Code"


Chapter 1 Easy-to-understand code


Chapter 2 Packing information in the name

2.2 Avoid generic names such as tmp and retval

2.5 Determine the length of the name

2.6 Communicate information in name format


Chapter 3 Names that are not misunderstood

Supplement


3.6 Boolean name

The meaning of true and false must be clarified.

The following variables can be interpreted in two ways.

bool read_password = true;

It is better to use need_password or ʻuser_is_authenticate`.


Chapter 4 Beauty

Three principles


Chapter 5 Know what to comment

5.2 What should not be commented

5.3 Record your thoughts

[Personal view]

It seems better to write the background not only in the source but also in the table name and column name of the database.


7.5 Return quickly from function

Some people think that functions should not use multiple return minutes. Stupid. It's good to return quickly from the function. Rather, it is sometimes desirable. ~ The reason I want to have one function exit is because I want to make sure that some cleanup code is executed. Modern languages offer this mechanism in a more sophisticated way.

In Java, try ... finally is an idiom for cleanup code.

[Supplement] The source of "return prohibition other than the end of the function"

MISRA-C, a "software design standard for C language", seems to be the source.

http://d.hatena.ne.jp/eel3/20121225/1356443485


9.2 Reduce the scope of variables


appendix


Java general naming rules

Reference coding standards


Personal view of coding conventions


Reference site

http://qiita.com/AKB428/items/20e81ccc8d9998b5535d

Recommended Posts

[In-house study session] Introduction of "Readable Code"
[In-house study session] Basics of Java annotation (2017/11/02) ~ Under construction ~
[In-house study session] Java exception handling (2017/04/26)
[In-house study session] Java basics-execution without using IDE- (2017/07/06)
Introduction of pay.jp
Introduction of milkode
[In-house study session] Java basics-Lambda expression and Stream API- (2017/07/13)
Introduction to Ratpack (8)-Session
study of dbpedia part 25
Javasilver study session memorandum
Introduction of user authentication