Guide the most simple and effective way to write easy-to-read code

Invite you and TipsMake.com to find out the article to guide the simple and most effective way to write easy-to-read code below!

Invite you and TipsMake.com to find out the article to guide the simple and most effective way to write easy-to-read code below!

  1. Instructions for creating a website for beginners
  2. 7 great HTML effects anyone can add to their website
  3. 17 simple HTML codes you can learn in 10 minutes

Most of us know how to write code but only lazy, so we don't follow it. This is one of the most understated ways of writing code and there are some false rumors, but I will mention it later. That method is, converting code into functions!

I know that we all convert code into functions but not too often. Get the code below, a code from my old company for example. Take a look at each of the points mentioned below!

Picture 1 of Guide the most simple and effective way to write easy-to-read code

1. It looks like it is recovering some groups. Although there are only 2 lines, you can draw a reasonable method from there.

2. Initially it must start with a flag. Programmers must feel uncomfortable about why only one line of code must have a separate method. Then another flag is added and the next one is a flag!

3. It looks like we are creating a container for frames. Why should high-level code pay attention to how it initializes?

4. As soon as I looked at the 4 lines of code, I understood why we should care about device information. I know 4 lines are not many but it can multiply tens or hundreds of lines. It is better to separate a method!

5. Login while reading flow is not effective. Must change now!

6. All listeners should be separated in one method.

After performing a few refactoring operations:

Picture 2 of Guide the most simple and effective way to write easy-to-read code

The code has become more eye-catching than before. It's easy to flip through without getting unnecessary details. A defined method will not require any comment lines.

Advice:

  1. Do not interfere with reading flow with complex effects or complicated conditions.
  2. Define short methods. It makes the explanation easier, the flow clearer, the scope is shorter, then you will have a better feeling.
  3. Make all declarations of the lecture code.

Adding two lines to a method is always easy. However, you should also note that the code changes above and below require a separate range, if any, to separate the method immediately. In each method, separate logic must be applied, so later contributors will add changes according to each corresponding method.

Conclude

Does increasing the number of methods negatively affect performance as many people find it? This is a disastrous misunderstanding and in most cases these effects are too small to worry about. If you work with the languages ​​on the JVM, congratulations, JVM is a great software with many really great time optimization features. And transform it .

"Code is like humor. Khi bạn có thể tạo nó, nó sai ." - Cory House

Author: Girish Budhwani

Refer to some more articles:

  1. C ++ exercises have solutions (sample code) for variables, data types, and operators
  2. 11 basic principles that every programmer should follow
  3. Form a way of thinking like a programmer

Having fun!

Update 26 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile