当前位置:网站首页>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;使用同类的一种框架呢,还是流行两种解决方案的框架呢...这样团队中人员接手项目的成本就会降低,开发人员的心里减少排斥感~
边栏推荐
- random.normal() and random.truncated_normal() in TF
- Cookie、session、token
- abstract class or interface
- MySQL:错误1153(08S01):得到的数据包大于“ max_allowed_packet”字节
- AI Knows Everything: Building and Deploying a Sign Language Recognition System from Zero
- SQL语句及索引的优化
- RHEL7系统修复rm -rf /boot /etc/fstab
- CVPR22 Oral|通过多尺度token聚合分流自注意力,代码已开源
- [Graphic and textual] How to reinstall Win7 system
- FET Mosfet Leiditech corresponds to Infineon Infineon
猜你喜欢
APP自动化测试框架-UiAutomator2基础入门
万字总结:分布式系统的38个知识点
Wps下划线怎么弄?Wps添加下划线的最全方法
cad图纸怎么复制到word文档里面?Word里插CAD图怎么弄?
微软word怎么转换成pdf文件?微软word转换为pdf格式的方法
The kvm virtual machine cannot be started, NOT available, and the PV is larger than the partition
Word怎么制作双面席卡?使用Word制作双面席卡方法
Synchronization lock synchronized traces the source
Word第一页不要页眉怎么设置?设置Word首页不要页眉方法教程
Bean生命周期
随机推荐
SQLi-LABS Page-2 (Adv Injections)
LoRa Basics无线通信技术和应用案例详解
几种绘制时间线图的方法
laravel 表迁移报错[通俗易懂]
Shanghai Konan SmartRocket series product introduction (3): SmartRocket iVerifier computer interlocking system verification tool
Word怎么设置图片衬于文字下方?两种方法教你设置Word图片衬于文字下方
Technology Sharing | How to use the JSON Schema mode of interface automation testing?
cad图纸怎么复制到word文档里面?Word里插CAD图怎么弄?
leetcode:数组中的第K个最大元素
什么是IDE(集成开发环境)?
Endpoint mode for NetCore routing
万字总结:分布式系统的38个知识点
[Graphic and textual] How to reinstall Win7 system
Cookie、session、token
random.normal() and random.truncated_normal() in TF
微软Excel表格点击单元格行和列都显示颜色怎么弄?聚光灯效果设置
Leetcode 93 IP addresses
cadence中复制一部分PCB到另一个PCB中去
4D Summary: 38 Knowledge Points of Distributed Systems
Synchronization lock synchronized traces the source