zoukankan      html  css  js  c++  java
  • 《编写可读代码的艺术》第12章 把想法变成代码

        代码应当用“自然语言”编写

    1. 清楚地描述逻辑

     1 $is_admin = is_admin_request();
     2 if ($document) {
     3     if (!$is_admin && ($document['username'] != $_SESSION['username'])) {
     4         return not_authorized();
     5     }
     6 } else {
     7     if (!$is_admin) {
     8         return not_authorized();
     9     }
    10 }
    11 // continue rendering the page ...
    12 
    13 //自然语言的描述
    14 //1. 你是管理员
    15 //2. 你拥有该文档
    16 //否则,无法授权
    17 if (is_admin_request()) {
    18     // authorized
    19 } elseif ($document && ($document['username'] == $_SESSION['username'])) {
    20     // authorized
    21 } else {
    22     return not_authorized();
    23 }
    24 // continue rendering the page ...

    2. 了解函数库是有帮助的

     1 // 功能:在网站中循环显示下一个提示
     2 // 试想如果不用.next()库函数,代码肯定不会这么精简
     3 var show_next_tip = function () {
     4     var cur_tip = $('.tip:visible').hide();
     5     var next_tip = cur_tip.next('.tip');
     6     if (next_tip.size() === 0) {
     7         next_tip = $('.tip:first');
     8     }
     9     next_tip.show();
    10 };
  • 相关阅读:
    《让未来的你,感谢现在的自己》——自己努力
    老罗——《我的奋斗》
    1. opencv的初体验
    opencv初体验
    opencv的初体验
    python学习2——数据类型
    卷积的意义
    C#学习笔记一
    C++知识点
    二维数组作为参数传递
  • 原文地址:https://www.cnblogs.com/yyqng/p/14286464.html
Copyright © 2011-2022 走看看