当前位置:网站首页>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 .
边栏推荐
- 情感对话识别与生成简述
- Jerry's built-in short press and long press, no matter how long it is, it is a short press [chapter]
- 创新实力再获认可!腾讯安全MSS获2022年度云原生安全守护先锋
- 2016. 增量元素之间的最大差值
- 海思调用接口之Makefile配置
- Strictly abide by the construction period and ensure the quality, this AI data annotation company has done it!
- Ping domain name error unknown host, NSLOOKUP / system d-resolve can be resolved normally, how to Ping the public network address?
- Win11麦克风测试在哪里?Win11测试麦克风的方法
- golang入门:for...range修改切片中元素的值的另类方法
- 用matlab调用vs2015来编译vs工程
猜你喜欢

Introduction to the latest plan of horizon in April 2022

MySQL queries nearby data And sort by distance

Value sequence < detailed explanation of daily question >

Odoo13 build a hospital HRP environment (detailed steps)

Boot actuator - Prometheus use

Mask R-CNN

設置單擊右鍵可以選擇用VS Code打開文件

地平线2022年4月最新方案介绍

The motivation of AES Advanced Encryption Protocol

【Redis笔记】压缩列表(ziplist)
随机推荐
Numerical solution of partial differential equations with MATLAB
SQL进阶语法
Use the scroll bar of souI when using the real window in souI
Sword finger offer II 099 Sum of minimum paths - double hundred code
MySQL queries nearby data And sort by distance
easyclick,ec权朗网络验证源码
在SOUI里使用真窗口时使用SOUI的滚动条
Set right click to select vs code to open the file
Tronapi wave field interface - source code without encryption - can be opened twice - interface document attached - packaging based on thinkphp5 - detailed guidance of the author - July 1, 2022 08:43:
Boot actuator - Prometheus use
Troubleshooting the cause of the crash when STM32 serial port dam receives 253 bytes
Antd component upload uploads xlsx files and reads the contents of the files
阿里云有奖体验:如何使用 PolarDB-X
20220524_ Database process_ Statement retention
4 special cases! Schools in area a adopt the re examination score line in area B!
2016. 增量元素之间的最大差值
情感对话识别与生成简述
Splunk audit 的设定
门牌制作 C语言
深度剖析数据在内存中的存储----C语言篇