当前位置:网站首页>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 a32Bit 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 .
边栏推荐
- 解决Chrome浏览器和Edeg浏览器主页被篡改的方法
- SharedPreferences 保存List<Bean> 到本地并解决com.google.gson.internal.LinkedTreeMap cannot be cast to异常
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验3 按键输入实验(学习笔记)
- ping域名报错unknown host,nslookup/systemd-resolve可以正常解析,ping公网地址通怎么解决?
- Sword finger offer II 099 Sum of minimum paths - double hundred code
- STM32串口DAM接收253字节就死机原因排查
- Ping domain name error unknown host, NSLOOKUP / system d-resolve can be resolved normally, how to Ping the public network address?
- 归并排序详解及应用
- 海思3559万能平台搭建:在截获的YUV图像上旋转操作
- Go语言sqlx库操作SQLite3数据库增删改查
猜你喜欢

China Academy of information technology, Tsinghua University, Tencent security, cloud native security, industry university research and use strong alliance!

Alibaba cloud award winning experience: how to use polardb-x
![[chestnut sugar GIS] ArcScene - how to make elevation map with height](/img/91/f3df0a7633263c6264cb5c27eb149f.png)
[chestnut sugar GIS] ArcScene - how to make elevation map with height

Deep analysis of data storage in memory - C language

Start from the bottom structure to learn the customization and testing of FPGA --- Xilinx ROM IP
![[favorite poems] OK, song](/img/1a/e4a4dcca494e4c7bb0e3568f708288.png)
[favorite poems] OK, song

MySQL reset password, forget password, reset root password, reset MySQL password

解决Chrome浏览器和Edeg浏览器主页被篡改的方法

Construction of Hisilicon 3559 universal platform: draw a frame on the captured YUV image
![[Yangcheng cup 2020] easyphp](/img/12/da28f738e50e625b0a66a94af3703d.png)
[Yangcheng cup 2020] easyphp
随机推荐
Mask R-CNN
Win11麦克风测试在哪里?Win11测试麦克风的方法
归并排序详解及应用
Xshell configuration xforward forwarding Firefox browser
Li Kou brush questions (2022-6-28)
用matlab调用vs2015来编译vs工程
P1007 single log bridge
Jerry's built-in shutdown current is 1.2ua, and then it can't be turned on by long pressing [chapter]
Splunk audit 的设定
Easyclick, EC Quanlang network verification source code
Construction of Hisilicon 3559 universal platform: rotation operation on the captured YUV image
Lambda表达式:一篇文章带你通透
Lambda expression: an article takes you through
海思 VI接入视频流程
潘多拉 IOT 开发板学习(HAL 库)—— 实验4 串口通讯实验(学习笔记)
严守工期,确保质量,这家AI数据标注公司做到了!
解决Chrome浏览器和Edeg浏览器主页被篡改的方法
Numerical solution of partial differential equations with MATLAB
LeetCode 968. Monitor binary tree
Redis expiration policy +conf record