zoukankan      html  css  js  c++  java
  • Code Reading chap2

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    +  

    +                     Chapter2: Basic Programming Elements

    +

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


    19. When examing a program for the first time, main can be a good starting point.(p20) 

         当第一次开始检查一个程序的时候, main 可以是一个好的起点。

    ---------------------------------------------------

    20.  Read a cascading if-else if-...-else sequence as a selection of mutually exclusive choices.(p23)
         将阅读一个瀑布式 if-else if-...-else 序列看作是一个互相排除的过程。

    ---------------------------------------------------
    21.  Sometimes executing a program can be a more way to unsderstand an aspect of its funtionality than reading its source          code.(P25)
          有时候执行一个程序比阅读其源代码对于了解其功能要来的方便。
    ---------------------------------------------------
    22. When examing a nontrivial program, it is useful to first identify its major constituent parts.(P25)
          当检查一个重要的程序的时候,首先确认其主要的构成部分对阅读代码是助益的。
    ---------------------------------------------------
    23. learn local naming conventions and use them to guess what varaibles and functions do.(P26)
          学习本地变量命名规范,并用这种规范经验去猜测代码中的变量和函数会去做什么。
    ---------------------------------------------------
    24. When modifying code based on guesswork, plan the process that will verify your initial hypotheses. this process can               involve checks by the compiler, the introduction of assertions, or the execution of appropriate test case.(p28) 
          当你在基于猜测的基础上去修改代码的时候,那么就去计划好会符合你最初的那个假设的过程。该过程会涉及到编译器的检查,断言的引入 ,       或者是适当的测试用例的执行。
    ---------------------------------------------------

    25. Understanding one part of the code can help you understand the rest.(P28)

         了解代码的一部分,那么对你了解其余部分也是会有帮助的。

    ---------------------------------------------------

    26. Disentangel difficult code by starting with the easy part.(P28)

         解决困难的代码自简单的部分始。(译注:柿子要捡软的捏?)

    ---------------------------------------------------

    27. Make it a habit to  read the documentation of library elements you encounter; it will enhance both your code-reading and       code-writing skills.(P28)

        使阅读你所遇到的文档库元素成为习惯;这会强化你的阅读代码和书写代码两种技巧。

    ---------------------------------------------------

    28. Code  reading involves many alternative strategies: bottom-up and top-down examination, the use of heuristics, and              review of components and extenal documentation should all be tried as the problem dictates. (P34)

         代码阅读涉及到许多其它策略:自底向上与自顶向下的检查,启发式的使用,当问题暴露出来时,应当去尝试回顾检查组件与外部文档。

    ---------------------------------------------------

    29. Loops of the form for (i=0; i< n; i++ ) execute n times; treat all other forms with cautions.(P34)

         带有形如for (i=0; i< n; i++ )的循环会严格的执行n次;所有其它类似的形式处理时必须保持警惕。

    ---------------------------------------------------

    30. Read comparison expressions involving the conjunction of two inequalities with one identical term as a range membership         test. (P39)

          将带有连接了两个不等式的比较表达式 作为范围成员资格测试。

    ---------------------------------------------------

    31. You can often understand the meaning of an expression by applying it on sample data.(P40)

         你常常可以通过将表达式应用到样例数据上去,来了解该表达式的意义。

    ---------------------------------------------------

    32. Simplify compilicated logical expressions by using De Morgan's rule.(P41)

          简化复杂逻辑表达式的一个有用的办法是使用所谓的德摩根律

    ---------------------------------------------------

    33. When reading a conjunction, you can always assume that the expression on the left of the expression you are examing           are true;when reading a disjunction, you can similarly assume that the expression on the left of the expression you are           examing are false.(P.42)

          当阅读一个连接 (译注:与操作符)时,你总是可以假定该连接之处于左方的表达式为真;当阅读到一个析取时(译注:或操作符),类似           的,你也总是可以假定该处于你所检查的表达式左方之另一个表达式为假(译注:作者提供了一种提升阅读速度,类似于浏览的技巧)。

    ---------------------------------------------------

    34. Recognize code you control to make it  more readable.(P46)

         识别出你所控制的代码,让它更加的可读。

    ---------------------------------------------------

    35.  Read expressions using the conditional operatinal operator ?: like if code. (p46)

          就像if 代码一样去读取使用条件操作表答符的表达式 ?:。

    ---------------------------------------------------

    36. There is no need to satisfy code readability for efficency.(P48)

         没有牺牲代码可读性来满足所谓效率的说法。

    ---------------------------------------------------

    37.  While  it is true that efficient algorithms and certain optimizations can make the code more complicated and therefor                more difficult to follow, this does not mean that making the code compact and unreadable will make it more effient.(P48)

          尽管有种说法不错:有效率的算法以及特定的优化会使得代码更加的复杂以及因此更加的难于追随。但这并不意味着:代码更加的紧凑以及不可读会使得代码更加的有效 。

    ---------------------------------------------------

    38. Creative code layout can be used to improve code readability.(P49) 

         创造性的代码布局可用于提升代码可读性。

    ---------------------------------------------------

    39. You can improve the readability of expressions using whitespace, temporary varaibles, and parentheses.(p.49)

          你可以通过使用空格键,临时变量以及圆括号来提升表达式的可读性。 

    ---------------------------------------------------

    40. When reading code under your control, make it a habit to add comments as needed.(P.50)

         当阅读你能控制的代码时, 让在需要的时候添加注释成为一种习惯。

    ---------------------------------------------------

    41.  You can improve the readability of poorly written code with better indentation and appropriate variable names.(P50)

          你可以通过更好的缩排以及恰当的变量名来提升写的很贫乏的代码的可读性。

    ---------------------------------------------------

    42. When you are examing a program revision history that spans a global reindentation exercise using the diff program, you         can often avoid the noise introduced by the changed indentation levels by specifying the - w option to have diff ignore             whitespace differences. (P51)

          当你检查一个程序版本的历史时,该历史版本使用了一个diff程序跨越了一全局重新缩排,你通常可以避开由变更"通过说明- w操作使diff忽         略空把的不同之处"这样级别的缩排所引入的噪音。(译注:diff 一个 *nix 命令行)

    ---------------------------------------------------

    43. The body of a do loop is executed at least once.(P51)

         一个do 循环体至少执行一次。

    ---------------------------------------------------

    44. When performing arithmetic, read a & b as a %(b+1) when b+1 = 2的N次方.(P53) (译注:打不出来效果,下同)

         当运算一个算术时,把a & b读成a %(b+1),当b+1 = 2的N次方的时候。

    ---------------------------------------------------

    45. Read a << n as a * k, where k = 2的n次方.(P53)

         把a << n 读成a * k, 其中k = 2的n次方。

    ---------------------------------------------------

    46.  Read a >> n as a / k, where k = 2的n次方.(P53)

          把 a >> n读成 a / k,其中k = 2的n次方。

    ---------------------------------------------------

    47. Examine one control structure at a time, treating its contents as a black box. (P54)

         一次只检查一个控制结构,并将其控制的内容看作是一个黑盒。

    ---------------------------------------------------

    48. Treat the controlling expression of each control structure as an assertion for the code it encloses.(P55)

          将各个控制结构的控制表达式看作是对其包括的代码的断言。

    ---------------------------------------------------

    49. The return, goto, break, and continue statements as well as exceptions interfere with the structured

         flow of execution. reason about their behavior separately since tehy all typically either terminate or

        restart the loop being processed.(P55)

        return, goto, break以及continue 状态以及带有结构化执行流的exceptions 接口,由于它们典型的都是要么是终止,要么是重新开始循环     处理,所以可用于推断出它们各自的行为。

    ---------------------------------------------------

    50. Reason about complex loops through their variant and invariant properties.(P56)

         通过复杂循环的变量以及不变量属性来推断这个复杂循环。

    ---------------------------------------------------

    51. Simplyfy code reasoning by rearranging code, using meaning-preserving transformations.(P58)

         通过重新排布代码来简化代码推理的过程, 要注意使用有意义的保留方式的转换。

    +++++++++++++++++++++++++++end of chap2++++++++++++++++++++++++++++++++++++++

  • 相关阅读:
    Java VS .NET:Java与.NET的特点对比
    .NET Core 快速入门教程
    System.Net.Mail.SmtpClient通过SSL/TLS协议发送邮件失败问题解决
    在CentOS 7上安装&配置PostgreSQL 12
    如何在团队中做好Code Review
    SonarQube部署及代码质量扫描入门教程
    Kafka集群部署指南
    ASP.NET Core 入门教程 10、ASP.NET Core 日志记录(NLog)入门
    ASP.NET Core 入门教程 9、ASP.NET Core 中间件(Middleware)入门
    ASP.NET Core 入门教程 8、ASP.NET Core + Entity Framework Core 数据访问入门
  • 原文地址:https://www.cnblogs.com/parsifal/p/2087780.html
Copyright © 2011-2022 走看看