Avoid nesting too deeply and return early避免嵌套太深应尽早返回


当某个变量与多个值进行比较的时候
不要用多个if else 判断是否相等
将多个值放在数组里,然后用PHP函数in_array(mixed $needle,array $haystack),检查数组$haystack里是否存在某个值$needle


总之这个例子就是要让嵌套达到最小
Avoid nesting too deeply and return early避免嵌套太深应尽早返回的更多相关文章
- 用return关键字实现1——100累加求和,返回总和并接收输出
package com.Summer_0419.cn; /** * @author Summer * 用return关键字实现1——100累加求和,返回总和并接收输出 */ public class ...
- 代码优化之return 减少括号嵌套
代码优化之return 减少括号嵌套 例如下面的公共方法 // 优化 substring方法 解决边界越界问题 空指针问题 优化前 public static String subString ...
- mac 安装 报错 "/usr/local/include/stdint.h:2:10: error: #include nested too deeply"
报错详细信息 构建错误 - “#include嵌套太深” /usr/local/include/stdint.h:2:10: error: #include nested too deeply #in ...
- sonar rule
bug类型: 1.".equals()" should not be used to test the values of "Atomic" classes. ...
- Sonar 规则
bug类型: 1.".equals()" should not be used to test the values of "Atomic" classes. ...
- SonarQube规则之坏味道类型
1.Abbreviation As Word In Name (默认 关闭)坏味道 主要检查验证标识符名称中的缩写(连续大写字母)长度,还允许执行骆驼案例命名allowedAbbreviationLe ...
- [中英对照]Linux kernel coding style | Linux内核编码风格
Linux kernel coding style | Linux内核编码风格 This is a short document describing the preferred coding sty ...
- js编写规范
JavaScript编码规范 Bug----33条 1. 不要使用’==’和’!=’,使用’===’和’!==’替代 等级:Major 原因:==和!=在判断值相等前会判断类型是否相等.这容易因为类型 ...
- 闲话Promise机制
Promise的诞生与Javascript中异步编程息息相关,js中异步编程主要指的是setTimout/setInterval.DOM事件机制.ajax,通过传入回调函数实现控制反转.异步编程为js ...
随机推荐
- 华盟网公开课 office 宏 主讲Alex
powershell github: veil-evasion macroshop unicorn https://github.com/trustedsec/unicorn metasploit ...
- Error: member names cannot be the same as their enclosing type
在编译的时候会遇到如下问题:member names cannot be the same as their enclosing type 原因:方法名和类名不能一样,如果一样就是一个构造函数.而构造 ...
- python 获取exception 名字
def func(): list = [] usr = input('username:') pwd = input('password:') try: list[4] # 这个是调用不了的,因为列表 ...
- git原理:pack打包
git向磁盘中存储对象使用“松散(loose)”对象格式.比如文件a.txt第一个版本大小是10k,第二个版本向其中添加了一行代码,假如此时文件为10.1k,那么第二个版本会重新产生一个1.1k的文件 ...
- ubuntu常见错误--Could not get lock /var/lib/dpkg/lock解决(转)
通过终端安装程序sudo apt-get install xxx时出错: E: Could not get lock /var/lib/dpkg/lock - open (11: Resource t ...
- 007-搭建框架-开发AOP框架
一.代码地址 https://github.com/bjlhx15/smart-framework.git 二.代码编写 2.1.定义切面注解 增加Aspect注解 package com.lhx.s ...
- Shell字符串操作
@1:子串削除 ${string#substring} 从$string 的开头位置截掉最短匹配的$substring. ${string##substring} 从$string 的开头位置截掉最长 ...
- 常用mysql导入导出数据的命令
To export 导出指定db_name的数据: $ mysqldump -u [uname] -p[pass] db_name > db_backup.sql 导出整个库的数据: $ mys ...
- iOS 什么是函数式编程
前言:当前只做理解性的常规背书,根据不断深入学习会不断丰富解读内容,欢迎评论提意见 函数式编程:Functional Programming 1 基本解释: 函数式编程 是一种思维模式,一种编程思想, ...
- UI控件之UIScrollView
UIScrollView:提供了滚动功能,用来显示超过一屏的视图 创建滚动视图 UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame: ...