当前位置:网站首页>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;使用同类的一种框架呢,还是流行两种解决方案的框架呢...这样团队中人员接手项目的成本就会降低,开发人员的心里减少排斥感~
边栏推荐
- [Graphic and textual] How to reinstall Win7 system
- TF生成均匀分布的tensor
- MySQL:错误1153(08S01):得到的数据包大于“ max_allowed_packet”字节
- Word箭头上面怎么打字
- 数独 | 回溯-7
- Technology Sharing | How to Handle Header Cookies in Interface Automation Testing
- Referenced file contains errors 完美解决方法
- mysql配置参数详解[通俗易懂]
- 【Efficient Tools】Remote Control Software ToDesk (Favorites)
- json事例
猜你喜欢

PMP每日一练 | 考试不迷路-8.9(包含敏捷+多选)

kvm虚拟机出现启动不了,NOT available,PV大于分区

AI+医疗:使用神经网络进行医学影像识别分析

ACM MM 2022 | Cloud2Sketch: Painting with clouds in the sky, AI brush strokes

Bean生命周期

【云原生】4.2 DevOps 精讲篇

几种绘制时间线图的方法

抽象类 or 接口

FS4066耐高压1到4节内置MOS的锂电池充电管理芯片

论文解读(DropEdge)《DropEdge: Towards Deep Graph Convolutional Networks on Node Classification》
随机推荐
【云原生】4.2 DevOps 精讲篇
Leetcode 93 复原IP地址
AI识万物:从0搭建和部署手语识别系统
论文解读(DropEdge)《DropEdge: Towards Deep Graph Convolutional Networks on Node Classification》
LoRa Basics无线通信技术和应用案例详解
Endpoint mode for NetCore routing
Word怎么制作双面席卡?使用Word制作双面席卡方法
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
TF generates uniformly distributed tensor
【stack】【queue】【priority_queue】【deque】Detailed explanation
QGIS编译SIP的问题
Use zeros(), ones(), fill() methods to generate data in TF
【泛型编程】模板全详解
TF使用constant生成数据
[corctf 2022] section
Byte side: Can TCP and UDP use the same port?
Interpretation of the paper (DropEdge) "DropEdge: Towards Deep Graph Convolutional Networks on Node Classification"
角度和弧度的相互换算
2021(ICPC)亚洲区域赛昆明站(CGHIJLM)
宝塔实测-搭建LightPicture开源图床系统