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!
- Instructions for creating a website for beginners
- 7 great HTML effects anyone can add to their website
- 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!
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:
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:
- Do not interfere with reading flow with complex effects or complicated conditions.
- Define short methods. It makes the explanation easier, the flow clearer, the scope is shorter, then you will have a better feeling.
- 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:
- C ++ exercises have solutions (sample code) for variables, data types, and operators
- 11 basic principles that every programmer should follow
- Form a way of thinking like a programmer
Having fun!
You should read it
- Why write neat and organized HTML?
- 9 tips to help you write 'more delicious' code
- 8 websites that help programmers practice coding skills
- Write Happy New Year in 10 different programming languages
- Multiple choice questions about programming with P1 prize
- Learn Ruby programming from 0
- JavaScript functions
- Why Web Designer should learn Ruby on Rails?
- 13 tips to help you learn code super fast without being too expensive
- How to read and write files using JES application
- Test on JAVA test on P9
- There is a generation of children who learn to write code before they can talk to people in India
Maybe you are interested
GitHub Copilot is now available for free in VS Code
Latest Sword Master Story Code and How to Enter Code
Latest Roblox Clicker Simulator Codes 12/2024
Ninja Team Code: Ninja Village 3D latest and how to redeem code
Full Giftcode Blue Lock Rivals Roblox latest and how to redeem code
Latest Anime Squad Simulator Codes and How to Enter Codes