Points for refactoring (if statement)

What is refactoring?

Refactoring is the process of improving the source by removing redundant code or rewriting it into versatile and efficient coding.

Key points for refactoring if statements

** if / else order ** It is recommended to write the formula of "survey target" whose value changes on the left side and the formula of "comparison target" whose value does not change on the right side.

sample

 if value >= 5
  #Processing content
 end

** for if / else **

# bad
if  a && b == 0
  if c
    #processing
  end
end

# good
if c
  if a && b == 0
    #processing
  end
end

Nesting is a nested structure There are cases where the if statement is embedded in the if statement to create a nested structure, but the deeper the nesting, the harder it is to read the code, so it is important to try to make it as shallow as possible.

Recommended Posts

Points for refactoring (if statement)
About for statement and if statement
if statement
Java for statement
[Java] for statement, while statement
Complex for statement (basic)
[Java] for statement / extended for statement
About Ruby if statement
10 Corresponds to if statement
Studying Java-Part 10-if statement
(Memo) Java for statement
[Java] Basic statement for beginners
Knowledge required for object-oriented refactoring
Let's understand the if statement!
[Ruby] problem with if statement
[Ruby] conditional branch if statement
Java study # 4 (conditional branching / if statement)
About if statement and branch processing
Review points for 2019 new employee training