2019独角兽企业重金招聘Python工程师标准>>>

Removing Nesting by returning early(编写易读代码)
1:
if (user_result == SUCCESS) {
if (permission_result != SUCCESS) {
reply.WriteErrors("error reading permission");
reply.Done();
return;
}
reply.WriteErrors("");
}else {
reply.WriteErrors(user_result)
}
reply.Done();
use return
if (user_result != SUCCESS) {
reply.WriteErrors(user_result);
reply.Done();
return;
}
if (permission_result != SUCCESS) {
reply.WriteErrors("error reading permission");
reply.Done()
return;
}
reply.WriteErrors("");
reply.Done();
2:
for (int i=0;i<results.size();i++){
if (result[i] != NULL){
non_null_count++;
if (result[i]->name != ""){
count << "Considering candidate..." << endl;
}
}
}
use continue inside loops
for (int i=0;i<results.size();i++){
if (result[i] == NULL) continue;
non_null_count++;
if (result[i]->name == "") continue;
cout << "Considering candidate..." << endl;
}

---摘自<The art of readable code>

转载于:https://my.oschina.net/u/249000/blog/75783

Removing Nesting By Returning Early相关推荐

  1. Practical Go: Real world advice for writing maintainable Go programs

    转载地址:Practical Go: Real world advice for writing maintainable Go programs Table of Contents Introduc ...

  2. python重构_重构Python应用程序以简化操作

    python重构 Do you want simpler Python code? You always start a project with the best intentions, a cle ...

  3. 云原生小课堂|Envoy请求流程源码解析(三):请求解析

    ​ 前言 Envoy 是一款面向 Service Mesh 的高性能网络代理服务.它与应用程序并行运行,通过以平台无关的方式提供通用功能来抽象网络.当基础架构中的所有服务流量都通过 Envoy 网格时 ...

  4. Asterisk AGI 详解

    Introduction The AGI facility allows you to launch scripts, written in just about any language, from ...

  5. 国际展会常见专业术语翻译

    国际展会常见英文专业术语 Affixed merchandise--Exhibitor'sproducts fastened to display-- 参展商携带的,与参展有关的辅助用品 Air fr ...

  6. Ribbon源码3-负载均衡算法源码分析

    0. 环境 nacos版本:1.4.1 Spring Cloud : Hoxton.SR9 Spring Boot :2.4.4 Spring Cloud alibaba: 2.2.5.RELEASE ...

  7. Ribbon客户端负载

    文章目录 Ribbon客户端负载 客户端负载均衡 RestTemplate详解 GET请求 POST请求 PUT请求 DELETE请求 源码分析 执行流程 @LoadBalanced: LoadBal ...

  8. vvvvvvvvvvvvvvvvvvvvvvvvv

    Java Concurrency In Practice Brian Göetz Tim Peierls Joshua Bloch Joseph Bowbeer David Holmes Doug L ...

  9. Ribbon负载均衡 算法

    1.Ribbon 简介 Ribbon是Netflix发布的负载均衡器,它有助于控制HTTP和TCP客户端的行为.为Ribbon配置服务提供者地址列表后,Ribbon就可基于某种负载均衡算法,自动地帮助 ...

  10. TI Cortex-M4 USB Host CDC 驱动详解及源代码

    1. USB CDC介绍 USB的CDC类是USB通信设备类(Communication Device Class)的简称.CDC类是USB组织定义的一类专门给各种通信设备(电信通信设备和中速网络通信 ...

最新文章

  1. oracle数据库删除百万级数据库,数据库SQL优化大总结之 百万级数据库优化方案...
  2. sqlserver 触发器 update_运维日记| SQL server 那点事——DML触发器
  3. macOS Big Sur 配置 jdk
  4. 调用ICodeCompiler来计算字符串表达式
  5. jenkins邮件配置(系统邮件和插件)
  6. Windows平台下编译FFmpeg
  7. java基础 -- Apache POI将PPT转换成图片
  8. java excel 批注_Java 添加、读取和删除 Excel 批注
  9. windows图片和传真查看器的调出
  10. yii2 使用gii生成mongo模型 控制器以及YII2 多MongoDB配置和使用
  11. 在Visual Studio代码内部调试节点应用
  12. 阿里云和腾讯云服务器哪个好用?
  13. Unity任意轴向朝向某目标实现LookAt功能
  14. 【CCF】公共钥匙盒
  15. python猜字小游戏
  16. 数学 - 已知三角形三边长度求面积
  17. 低代码amis学习笔记(表单)
  18. android编程从零开始,从零开始学习android开发
  19. java是自由软件吗_开源LGPL——如何宣告自己的程式为自由软件
  20. 乘性散斑噪声理论及其仿真实例分析

热门文章

  1. sql中的日期函数和case函数
  2. VMware虚拟机更换根用户( su: Authentication failure问题)
  3. 【计算机网络基础】URI、URN和URL的区别
  4. scrapy-redis3
  5. 一个在线排版小工具:中文、英文、数字、符号中间加个空格
  6. Django自身安全机制-XSS和CSRF
  7. viewport总结
  8. 使用Reflexil修改类库
  9. C# sqlDataReader区别Dataset
  10. 推荐一款弹出窗口插件 lhgdialog 4.2.0 正式版