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!

  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!

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

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:

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

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!

5 ★ | 1 Vote

May be interested

  • How to write emails effectively and professionally?How to write emails effectively and professionally?
    every day you work with colleagues, partners via email, chat programs ... is a main and professional communication channel at work, how to be effective as well as optimize time and performance which email messages do you bring to you?
  • 9 tips to help you write 'more delicious' code9 tips to help you write 'more delicious' code
    writing code is obviously the first task if you are a software developer. however, have you ever thought your code was really good?
  • 7 simple ways to practice writing skills7 simple ways to practice writing skills
    if you want to write fast, write well, so that anyone who read it will have to love, there is no other way to practice. so how to practice writing skills to be most effective?
  • How to read QR codes on computersHow to read QR codes on computers
    qr codes are becoming increasingly popular and widely used. you can easily find them on banners, product boxes, web pages or even email signatures. the question is how to decode a qr code icon? very simple, today tipsmake.com will introduce you how to read qr codes on your computer with codetwo qr code desktop reader & generator application.
  • How to fix Attempted Write to Readonly Memory on WindowsHow to fix Attempted Write to Readonly Memory on Windows
    attempting write to readonly memory error (stop code 0x000000be) is one of the blue screen errors, which occurs when a driver tries to write to read-only in computer memory.
  • How to Run HTML Files on Visual Studio CodeHow to Run HTML Files on Visual Studio Code
    visual studio code is microsoft's source code editor. the program is currently available for windows, macos, and linux. with visual studio code, you'll be able to write and edit code in many different programming languages, including html. but what do you do when you want to implement some html code? luckily, there are many extensions for visual studio code that make it easy to execute html code right in visual studio code. additionally, you can also use terminal to run html files. today's tipsmake will show you how to run html files on visual studio code.
  • Increase read and write speed of USBIncrease read and write speed of USB
    during the process of using usb, you see that the data reading and writing speed of usb is very slow. you can maximize the speed of usb read and write with just a few steps below.
  • 4 Ways to Test SSD Speed ​​and Performance4 Ways to Test SSD Speed ​​and Performance
    the manufacturer's stated read and write speeds are not accurate specifications because they are not the read and write speeds we can actually use.
  • Introducing Canvas: A New Way to Write and Code with ChatGPTIntroducing Canvas: A New Way to Write and Code with ChatGPT
    today's post will introduce canvas, a new interface for working with chatgpt on writing and coding projects that go beyond simple chat.
  • How to write curves in PhotoshopHow to write curves in Photoshop
    creating curvy typography in photoshop is very simple and you can use it in many different ways.