Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Full of sweat and tears of programming experience, beginners should note


Jun 01, 2021 Article blog


Table of contents


As a programmer, there are inevitably many pits in programming. S mall editor has several years of programming experience, which in the middle for others to dig a lot of pits, but also stepped on other people's pits, help others fill the pit. As a comer, I summed up my experience of stepping on the pit, let everyone refer to, perhaps to avoid some pits.

1. Any modifications must be tested before they can go live

The small editor once found that his code had a bug before it went live, because of the time constraints, after reading the next code after the small editor thought there was no problem, self-test did not carry out, put the code submitted online.

As a result, the next day when the user used this feature, they reported the error directly and had to restart the server that night to put the tested code on it.

The matter was reported and criticized by the big leaders, and the project manager was criticized together.

2.sql anti-injection is the most basic common sense

When the small editor first started to do the project, I saw that the project group had stitched the input parameters in sql did not enter parameters in a precompiled way, and the small editor wrote along with this.

And these interfaces are called through the mobile phone app side of the outside network, the danger is increased instantaneously.

The department's security team timely scan to identify these problems, the small editor spent a whole New Year's Day holiday to these sql stitching parameters of the code to replace the precompiled way, but also changed an interface, good repair after no major problems.

sql注入 is extremely dangerous, and avoiding sql注入 in a precompiled way is one of the most effective ways. Of course, in addition to sql注入 there are command injections and so on.

 Full of sweat and tears of programming experience, beginners should note1

3. The key to programming is decoupling and readability

The boss before the small editor taught the small editor, good code must have good readability, readability is the basis of maintainability.

When writing code, I wonder, this class, this method, what's the name of this variable? Good code is the ability to explain itself.

When you maintain the code of a former colleague, you find that some colleagues' code is stinky and long, and the variables are sometimes a1 a2 a3 and so on. Ming Ming is a new method, partial to the beginning of get

Decoupling is that I do what I have to do, you do what you have to do, do not interfere in each other's internal affairs, each to deal with change.

For example, if you inherit a class or implement an interface, it would be nice if you did your part.

For example, a complex logic, can be split into multiple sub-logic, each sub-logic is decoupled, modify one method, will not affect the use of another method, the complexity of the method is reduced.

4. Try not to repeat the wheel

Some classes or jar包 have been widely used, there is no problem, their own free research is good, there is no need to write another.

Before the small compilation to do an import function, because the data to be stored is very large, need to split the collection batch import.

Small editor wrote a method of splitting the collection, after the project another colleague reminded, found that the system introduced in the open source jar包 already has this method, direct guide package use on the line.

Items that use java 8 such as grouping, filtering, list list object extraction properties, etc., can all be manipulated by java8 streams. map

5. Database tables should be built to follow the paradigm of database tables as far as possible

The small project team found that many tables had unnecessary redundant fields, such as names.

When the user modifies the data of the base table, the name data of the business table is not modified, and the query is not associated with the base table to query the name field, resulting in inconsistent data seen by both sides of the user.

Maintaining this data and modifying query capabilities takes a lot of time.

6. Try not to allow business directly in the background database derivatives into the library

The number of database imports bypasses code logic and is not intercepted by code logic and verified by business rules, which can lead to illegal data storage and even affect normal business processes.

And the imported data tends to be huge and heavier after the maintenance costs. Previous small compilations have also imported a large amount of historical stock data, resulting in a lot of problems with this data.

After guiding the data, the user found that the existing use of the impact, had to confirm to the business, re-brush the number, really tired.

 Full of sweat and tears of programming experience, beginners should note2

So anyone who wants to know about SQL数据库 can take a look at the tutorial

SQL tutorial: https://www.w3cschool.cn/sql/

MySQL micro-class: https://www.w3cschool.cn/minicourse/play/mysqlcourse