当前位置:网站首页>6 rules to sanitize your code
6 rules to sanitize your code
2022-08-09 23:14:00 【51CTO】
Readable code's maintainability!
1、注重命名
Named for an event is difficult.Although difficult but very necessary.
想象以下,将两个数组合并成一个数组,And generate a unique value array.So what would you name it?We may be so named?
The above named is not bad,But also is not very friendly.You can take a functions into two functions,This name is more friendly and function better reusability.
2、IF语句简化
Suppose we have the following code:
我们可以这样解决:
将乱七八糟的条件判断放到一个变量中存储,比看臃肿的表达式要好很多.
3、及早返回
有下面的代码:
Early returns makes our code more readable:
4、解构赋值
在javascript
中,我们可以对objects
和arrays
进行解构赋值.
例如:
5、童子军规则
童子军有一条规则:Always keep away camping cleaner than when you find it.如果你在地面上发现了脏东西,那么无论是否是你留下的,You have to clean it.你要有意地为下一组露营者改善环境.
我们编写代码也是这样子,If you are found in the code脏代码,那么你可以尝试去修改它,即使是一个没有被引用到的变量名.
6、代码风格
Used in your team一种代码风格,Such as limited code indentation specification is two Spaces or four Spaces;Using single quotes or double quotes;使用同类的一种框架呢,还是流行两种解决方案的框架呢...这样团队中人员接手项目的成本就会降低,开发人员的心里减少排斥感~
边栏推荐
- Leetcode 93 IP addresses
- 什么是IDE(集成开发环境)?
- DSPE-PEG-PDP, DSPE-PEG-OPSS, phospholipid-polyethylene glycol-mercaptopyridine reduce the immunogenicity of peptides
- 同步锁synchronized追本溯源
- Sudoku | Backtrack-7
- LeetCode26:删除有序数组中的重复项
- Install win virtual machine on VMware
- AI+医疗:使用神经网络进行医学影像识别分析
- 10个 Istio 流量管理 最常用的例子,你知道几个?
- 论文解读(DropEdge)《DropEdge: Towards Deep Graph Convolutional Networks on Node Classification》
猜你喜欢
Install win virtual machine on VMware
POWER SOURCE ETA埃塔电源维修FHG24SX-U概述
Don't tell me to play, I'm taking the PMP exam: what you need to know about choosing an institution for the PMP exam
STC8H开发(十五): GPIO驱动Ci24R1无线模块
Word第一页空白页怎么删除?删除Word第一页空白页方法教程
PMP daily practice | didn't lost a 8.9 (including agile + multi-select)
同步锁synchronized追本溯源
数独 | 回溯-7
抽象类 or 接口
筑牢安全防线 鹤壁经济技术开发区开展安全生产培训
随机推荐
Word怎么制作双面席卡?使用Word制作双面席卡方法
场效应管Mosfet之雷卯Leiditech对应英飞凌Infineon
同步锁synchronized追本溯源
Referenced file contains errors 完美解决方法
筑牢安全防线 鹤壁经济技术开发区开展安全生产培训
STC8H Development (15): GPIO Drives Ci24R1 Wireless Module
np中的round函数,ceil函数与floor函数
题解:Edu Codeforces 109(div2)
数独 | 回溯-7
浅谈Numpy中的shape、reshape函数的区别
Problems with compiling SIP with QGIS
Optimization of SQL Statements and Indexes
Simple questions peek into mathematics
角度和弧度的相互换算
【Efficient Tools】Remote Control Software ToDesk (Favorites)
random.normal() and random.truncated_normal() in TF
Hessian Matrix 海森矩阵
laravel 表迁移报错[通俗易懂]
上海控安SmartRocket系列产品推介(三):SmartRocket iVerifier计算机联锁系统验证工具
DSPE-PEG-Silane, DSPE-PEG-SIL, phospholipid-polyethylene glycol-silane modified silica particles