当前位置:网站首页>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;使用同类的一种框架呢,还是流行两种解决方案的框架呢...这样团队中人员接手项目的成本就会降低,开发人员的心里减少排斥感~
边栏推荐
猜你喜欢
浅谈Numpy中的shape、reshape函数的区别
TF generates uniformly distributed tensor
[Implementation of the interface for adding, deleting, checking, and modifying a double-linked list]
Several ways to draw timeline diagrams
SQL语句及索引的优化
别叫我玩,我要考PMP:考PMP选择机构需要了解的那些事儿
LoRa Basics无线通信技术和应用案例详解
[corctf 2022] 部分
Reinforcement Learning Weekly Issue 57: DL-DRL, FedDRL & Deep VULMAN
Word文档怎么输入无穷大符号∞
随机推荐
SQLi-LABS Page-2 (Adv Injections)
Synchronization lock synchronized traces the source
SecureCRT sets the timeout period for automatic disconnection
FET Mosfet Leiditech corresponds to Infineon Infineon
TF generates uniformly distributed tensor
MySQL:错误1153(08S01):得到的数据包大于“ max_allowed_packet”字节
小黑leetcode清爽雨天之旅,刚吃完宇飞牛肉面、麻辣烫和啤酒:112. 路径总和
浅谈Numpy中的shape、reshape函数的区别
AI Knows Everything: Building and Deploying a Sign Language Recognition System from Zero
TF uses constant to generate data
如何让您的公司内容满足 GDPR 合规性
TF中random.normal()与random.truncated_normal()
凸集与凸函数
Bean life cycle
RHEL7系统修复rm -rf /boot /etc/fstab
【云原生】4.2 DevOps 精讲篇
MySQL跨表、多表更新SQL语句总结
L3-2 至多删三个字符 (30 分)
Don't use array.length-1 to get the last item of the array
hdu 1333 Smith Numbers(暴力思路)