当前位置:网站首页>Practice and some ideas on the transformation of sonarlint code specification
Practice and some ideas on the transformation of sonarlint code specification
2022-06-09 04:58:00 【It's me】
Sonarlint Code specification transformation practice and some ideas
1.Ternary operators should not be nested( Ternary operators should not be nested )

Official reasons :
Just because you can do something , Doesn't mean you should do , This is the case with nested ternary operations . The code generated by nested ternary operators may look very clear when you write , But in six months' time, the maintainer ( Or worse —— You in the future ) Scratch your head and swear .
contrary , For the sake of clarity , Another line should be used to represent the nested operation as a separate statement .
I don't agree with this rule , I don't think it's necessary to change something .
2. Instance methods should not write to “static” fields( Instance methods should not write “ static state ” Field )

The official reason is :
Updating static fields correctly from non static methods requires skill , If there are multiple class instances and / Or more threads are running , It can easily lead to errors . Ideally , Static fields are only updated from synchronous static methods .
however , I use this with the help of @PostConstruct Annotated , If you create another class to do , I feel that the amount of code is coming up again , Hold it down for a while , Think about it later .
3. Cognitive Complexity of methods should not be too high( The cognitive complexity of the method should not be too high )

Cognitive complexity is an incomprehensible measure of a method's control process . Methods with high cognitive complexity will be difficult to maintain .
Um. , This … It 's a long story
4. Utility classes should not have public constructors( Utility classes should not have public constructors )

Utility classes are collections of static members , It doesn't mean instantiating . Even abstract utility classes that can be extended , Nor should there be a public constructor .
Java Add an implicit public constructor to every class that does not explicitly define at least one . therefore , At least one non-public constructor should be defined .
Um. , It doesn't matter whether this feeling exists or not .
5. Resources should be closed( Resources should be closed )

The implementation can close the interface or its super interface AutoCloseable The connection of 、 flow 、 Files and other classes need to be closed after use . and , Must be in finally Block to complete this near call , Otherwise, an exception may occur that makes the call impossible . best , When a class implements AutoCloseable when , You should use “try-with-resources” Patterns create resources , And turn it off automatically .
If the resource cannot be closed properly , Will lead to resource leakage , First, it will crash the application , Then the machine may be paralyzed .
This feeling is still very important .
To be continued
边栏推荐
- openGL_01-創建窗口
- pytest_ Introduction to allure priority and fixture scope parameters
- Talk about 10 tips to ensure thread safety
- Smart curly bracket escape
- [006] [esp32 Development notes] burn firmware steps Using Flash Download Tool
- 2022年高处安装、维护、拆除特种作业证考试题库及模拟考试
- 拉下新项目代码爆红
- MySQL scheduled backup restore
- Make in-depth research and summary, go to a higher level, and make new year's resolutions
- Keepalived configure virtual IP
猜你喜欢

Win10 registry failed to save changes to permissions access denied

wps ppt背景图片如何换颜色

Win10注册表无法保存对权限所作的更改拒绝访问

wps ppt图片如何一张一张出来

2022年安全员-A证考试试题及在线模拟考试

ps如何给图像加白边

2022 test question bank and simulation test of special operation certificate for installation, maintenance and demolition at heights

Transformer裏面的緩存機制

2022年安全员-B证上岗证题目及在线模拟考试

How to calculate the rarity of NFT?
随机推荐
Soft keyboard appears search
Ultimate shell - Zsh
Devin round smart screen comes into the market
wps ppt背景图片如何换颜色
Mmdet modify the font size, position, color and fill box of the detection box
Example of name call obtained by ID (Tencent IM)
Faster RCNN
迪文圆形智能屏上市
2022年安全员-A证考试试题及在线模拟考试
Latest list of 955 companies that do not work overtime (2022 Edition)
[006] [ESP32开发笔记] 使用Flash下载工具烧录固件步骤
TypeScript学习【6】 接口类型
1030. distance sequence matrix cells ●
"Diwen Cup" electronic design competition of Hunan University of Arts and Sciences was successfully concluded
Win10 installing appium environment
P1779 Xiaohu's springboard
2022 welder (elementary) special operation certificate examination question bank and simulation examination
Ribbon和Feign的对比-带简易例子
ETF operation practice record: March 2, 2022
2022安全员-C证考试练习题模拟考试平台操作