当前位置:网站首页>Eight honors and eight disgraces of the programmer version~
Eight honors and eight disgraces of the programmer version~
2022-07-02 23:13:00 【Programmer Xiaohui】
Preface
Hello everyone , Recently, I sorted out an eight honors and eight disgraces about the daily development version of programmers , It's interesting . Let me share with you , ha-ha ~
1. Proud of interface compatibility , Shame on the interface running naked
With Interface compatibility take as an honor , How do you understand that ?
quite a lot bug All because of the modification External old interface , But Not compatible As a result of . Most of the key problems are serious , May directly lead to System Publishing failure . It's easy for novice programmers to make this mistake . So we When modifying the old interface , Generally, it is necessary to be compatible .

If your requirements are modified on the original interface , Especially if this interface is to provide services to the outside world , Be sure to consider interface compatibility . Let's give you an example , such as dubbo
Interface , Originally, it only received A,B
Parameters , Now you add a parameter C
, We can consider this way of handling :
// Old interface
void oldService(A,B){
// Compatible with new interface , Send a null Instead of C
newService(A,B,null);
}
// The new interface , The old interface cannot be deleted for the time being , Need to be compatible .
void newService(A,B,C){
...
}
We still need to Interface streaking For shame . To ensure the security of interface message , Reject interface message streaking . therefore , We can use https agreement , It is also recommended to add a signature for the interface , Data encryption, etc .
Interface signing is simple , That is, the interface Request relevant information ( Request message , Include request timestamp 、 Version number 、appid etc. ), Client private key signature , Then the server verifies the signature with the public key , It is considered legal only after passing the verification 、 A request that has not been tampered with by an intermediary .
It's about adding and checking signatures , You can read my article , The programmer must have the foundation : Additional signature
2. Take pride in standardizing the log , Shame on typing logs
Our business logic code needs Log escort . such as : You realize the transfer business , Turn a few million , Then it failed , Then the customer complains , And then you haven't printed it into the Journal , Think about the deep and hot predicament , You have no way ...
So everyone should keep a good diary , such as The log level is used properly , Log format , Where to log , Parameter which to print wait . Don't make random logs , Take pride in standardizing the log , It's a shame to make a random diary .

3. Proud of code self-test , Shame on overconfidence
Modify the code , I need to test myself , This is a necessary quality for every program , Even if you just change a variable or a field .
Put an end to overconfidence , In particular, do not have such a fluke mentality : I just changed a variable or I just changed one line of configuration code , Don't test yourself , How could there be a problem .

therefore , We want to Proud of code self-test , Shame on overconfidence .
4. Proud of parameter verification , Shame on running exceptions
Parameter verification is an essential basic quality for every programmer . Your way of dealing with , Parameters must be verified first . For example, whether the input parameter is allowed to be empty , Whether the input length meets your expected length . therefore , We should be proud of parameter verification .
For example, your database table field is set to
varchar(16)
, The other side passed a32
Bit string over here , If you don't check the parameters , Inserting into the database directly caused an exception .

We should be ashamed of runtime exceptions .
For example, you didn't do some non empty checks , Array boundary verification, etc , Null pointer exception caused by 、 Array boundary exception , In particular, these runtime exceptions It also happens in the production environment Words , In the eyes of experienced programmers , These misbehaviors can be particularly low-level .
therefore , We want to Proud of parameter verification , Shame on running exceptions .
5. Take pride in design patterns , Shame on code repetition
On a daily basis , We should be proud of the design pattern .
such as The strategy pattern 、 Factory mode 、 Template method pattern 、 Observer mode 、 The singleton pattern 、 The chain of responsibility model wait , They are very common . In the right business scenario , Let's use design patterns . Design patterns can make our code more elegant 、 More extensible . But don't over design , Don't apply design patterns .
We still need to It's a shame to repeat the code . Duplicate code , I believe every programmer hates it , Especially sometimes your development tools will prompt you . We can Extract public methods , Extract common variables 、 Extend the inheritance class And other ways to eliminate duplicate code .

6. Take pride in optimizing your code , Shame on copy and paste
Daily development , Many programmers implement a function , If you see that the old code has similar functions , They love copying and pasting . This can easily lead to duplicate code , So we should be ashamed of copying and pasting . It is generally recommended to add your own thinking , How to optimize this part of the code , How to extract public methods , What design patterns to use, etc .

Personally feel , The process of optimizing code , You can make greater progress . So we should be proud to optimize the code , Shame on copy and paste .
7. Proud to define constants , Shame on magic numbers
In our daily work , Do you often see magic numbers . Magic number (Magic Number) It means having a special meaning , But it can not clearly show the meaning of the numbers . There are magic numbers in the program , Poor legibility , And very difficult to maintain .
as follows :
if(type==1){
System.out.println(" Official account : A little boy picking up snails ");
}else if(type==2){
System.out.println(" Official account : Programmer snail ");
}else{
System.out.println(" Pay attention to other official account numbers ");
}
In code 1、2
It means magic numbers , We can use Constants replace magic numbers , perhaps Define enumeration To replace magic numbers .
8. Take pride in summarizing and thinking , It is a shame to fish in troubled waters .
We should be proud of summarizing and thinking .
For example, after you read brother Tianluo's article , You can sum up and think about , Or take notes , Or put it in your favorites , Take a look after dinner . Another example is in your daily work , See a good piece of code , You can also think about the highlights , If you write it yourself , How to write better code . Anyway How to summarize , Think more , Review more , Consider the past you shall know the future Well .
We should be ashamed of fishing in troubled waters . For example, at work , Some friends like to fish in troubled waters , When a monk strikes a clock one day , The code is mostly copy and paste , Fish when you need it . In fact, this is not desirable .

We should grow in our work , By working hard , Make yourself more , In the future, you can get a higher salary by changing jobs , Right , Come on! , Young man , With I am proud to sum up and think , It is a shame to fish in troubled waters .
Last
If this article is helpful to you , Or if there's some inspiration , Ask for one key and three links : give the thumbs-up 、 forward 、 Looking at , Your support is my biggest motivation for writing .
边栏推荐
- Generics and reflection, this is enough
- Loss function~
- Lambda表达式:一篇文章带你通透
- 在SOUI里使用真窗口时使用SOUI的滚动条
- Stop slave is stuck -- the event of the transaction is not copied completely
- PotPlayer设置最小化的快捷键
- Xshell configuration xforward forwarding Firefox browser
- Pytorch training CPU usage continues to grow (Bug)
- 力扣刷题(2022-6-28)
- Realize the linkage between bottomnavigationview and navigation
猜你喜欢
Temperature measurement and display of 51 single chip microcomputer [simulation]
Construction of Hisilicon 3559 universal platform: draw a frame on the captured YUV image
情感对话识别与生成简述
海思 VI接入视频流程
景联文科技低价策略帮助AI企业降低模型训练成本
实现BottomNavigationView和Navigation联动
Xshell configuration xforward forwarding Firefox browser
设置单击右键可以选择用VS Code打开文件
Pandora IOT development board learning (HAL Library) - Experiment 4 serial port communication experiment (learning notes)
Strictly abide by the construction period and ensure the quality, this AI data annotation company has done it!
随机推荐
Use the scroll bar of souI when using the real window in souI
Application of containerization technology in embedded field
Detailed explanation and application of merging and sorting
Splunk audit 的设定
golang中new与make的区别
Jinglianwen technology's low price strategy helps AI enterprises reduce model training costs
潘多拉 IOT 开发板学习(HAL 库)—— 实验3 按键输入实验(学习笔记)
损失函数~
提交代码流程
Methods to solve the tampering of Chrome browser and edeg browser homepage
Construction of Hisilicon 3559 universal platform: rotation operation on the captured YUV image
景联文科技低价策略帮助AI企业降低模型训练成本
PMP project integration management
剑指 Offer II 099. 最小路径之和-双百代码
Call vs2015 with MATLAB to compile vs Project
数据标注典型案例,景联文科技如何助力企业搭建数据方案
Qt QScrollArea
4 special cases! Schools in area a adopt the re examination score line in area B!
Splunk audit setting
Distributed monitoring system ZABBIX