当前位置:网站首页>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 .
边栏推荐
- 提交代码流程
- China Academy of information technology, Tsinghua University, Tencent security, cloud native security, industry university research and use strong alliance!
- 海思3559万能平台搭建:在截获的YUV图像上旋转操作
- 設置單擊右鍵可以選擇用VS Code打開文件
- Innovation strength is recognized again! Tencent security MSS was the pioneer of cloud native security guard in 2022
- 景联文科技低价策略帮助AI企业降低模型训练成本
- Go multithreaded data search
- SQL进阶语法
- Jerry's prototype will trigger shutdown after multiple touches [chapter]
- Mask R-CNN
猜你喜欢

P1007 single log bridge

设置单击右键可以选择用VS Code打开文件

Use of recyclerview with viewbinding
![[npuctf2020]ezlogin XPath injection](/img/6e/dac4dfa0970829775084bada740542.png)
[npuctf2020]ezlogin XPath injection

FOC矢量控制及BLDC控制中的端电压、相电压、线电压等概念别还傻傻分不清楚

Construction of Hisilicon 3559 universal platform: rotation operation on the captured YUV image

Realize the linkage between bottomnavigationview and navigation

最小生成树 Minimum Spanning Tree

【Redis笔记】压缩列表(ziplist)

4 special cases! Schools in area a adopt the re examination score line in area B!
随机推荐
[Solved] Splunk: Cannot get username when all users are selected“
AES高级加密协议的动机阐述
Lc173. Binary search tree iterator
Stop slave is stuck -- the event of the transaction is not copied completely
Submit code process
Value sequence < detailed explanation of daily question >
Lambda expression: an article takes you through
2016. 增量元素之间的最大差值
Use of recyclerview with viewbinding
The first batch of Tencent cloud completed the first cloud native security maturity assessment in China
FOC矢量控制及BLDC控制中的端电压、相电压、线电压等概念别还傻傻分不清楚
Niuke network: maximum submatrix
Is 408 not fragrant? The number of universities taking the 408 examination this year has basically not increased!
Start from the bottom structure to learn the customization and testing of FPGA --- Xilinx ROM IP
Data analysis learning records -- complete a simple one-way ANOVA with Excel
[adjustment] postgraduate enrollment of Northeast Petroleum University in 2022 (including adjustment)
China Academy of information technology, Tsinghua University, Tencent security, cloud native security, industry university research and use strong alliance!
密码技术---密钥和SSL/TLS
设置单击右键可以选择用VS Code打开文件
剑指 Offer II 099. 最小路径之和-双百代码