代码大全也读了好几个月了,一开始读中文版,到现在慢慢尝试着读原版,确实感受到了“每天进步一点点”的魅力。遗憾的是没有从一开始就做阅读记录,总有不能尽兴和思路不清之感。确实,就像项目需要版本控制系统,读书也需要时时记录变化。所以,今天新开一贴,作为自己的阅读记录之用。
初步的想法是记录读到哪里,有什么疑问,以及原文中精炼的表述。
2014-01-27 190 Chapter 8 : Defensive Programming
问题:JAVA的断言是如何实现的?如果要写一个自己的断言类,如何实现?在生产环境下断言一定要关闭吗?
2014-01-28 199 Chapter 8 : Defensive Programming
断言和错误处理有什么区别?
——Use error-handling code for conditions you expect to occur; use assertions forconditions that should never occur。
问题:处理错误有几种方式?每种方式各在什么情况下适用?都有什么优点和缺点?
——These examplesalso illustrate that error processing generally favors more correctness or morerobustness.
2014-01-29 208 Chapter 8 : Defensive Programming
——Throw exception only for conditions that are truly exceptional.
——Throw exceptions at the right level of abstraction.
问题:Java应该只抛出Exception的子类吗?在其他语言中呢?
——Handling errors with exceptions just because your language provides exception handling is a classic example of programming in a language rather than programming into a language.
问题:隔离仓思想:在类的级别如何表现?仓外和仓内的程序应该使用断言还是错误处理?进攻式编程/防御师编程是反义词吗?
——Sometimes the best defense is a good offense. Fail hard during development so that you can fail softer during production.
问题:如何使用ant和make?
2014-02-02 213 Chapter 8:Defensive Programming
——Users don’t appreciate anything that results in the loss of their work, regardless of how much it helps debugging and ultimately improves the quality of the program.
——Code installed for defensive programming is not immune to defects, and you’re just as likely to find a defect in defensive-programming code as in any other code—more likely, if you write the code casually.
问题:什么是前条件和后条件?
——Defensive-programming techniques make errors easier to find, easier to fix, andless damaging to production code.
2014-02-03 223 The Pseudocode Programming Process
问题:什么是伪代码开发过程,测试先行开发和按合约设计?
创造一个类和一个子程序的一般步骤是什么?
——The Pseudocode ProgrammingProcess defines a specific approach to using pseudocode to streamline thecreationof code within routines.
伪代码原则:伪代码不应该限制实现语言。
——Avoid syntactic elements from the target programming language. Pseudocodeallows you to design at aslightly higher level than the code itself. When you useprogramming-language constructs, you sink to a lower level,eliminating themain benefit of design at a higher level, and you saddle yourself with unnecessarysyntacticrestrictions.
问题:什么样的伪代码可以直接变成注释?
——One of the keys to the success of a project is to catch errorsat the “least-value stage,” the stage at which the least effort has been invested.
——The single biggest way toimprove both the quality of your code and your productivity is to reuse good code.
2014-02-04 231 The Pseudocode Programming Process
——Don’t waste time scraping for incremental improvements until youknow they’re needed.
——Trouble in writing the generalcomment is a warning that you need to understand the routine’s role in theprogrambetter.
问题:设计好数据结构,算法往往就不言自明。如何充分设计?如何防止过度设计以至于“瘫痪”?
——Pseudocodecan make your assumptions and high-level mistakes more obvious than programming-language code does.
问题:如何将伪代码编程用于实际工作中?它会降低编程效率吗?
——Once you start coding, you get emotionallyinvolved with your code and it becomes harder to throw away a bad design and start over.
问题:从伪代码到真实代码的完整过程是什么?伪代码带来什么思维上的益处?在这里可以使用写作的隐喻吗?
——Mentally executing a routine is difficult,and that difficulty is one reason to keep your routines small.
——If you often find yourself suspecting that the compiler orthe hardware made an error, you’re still in the realm of superstition.
问题:为什么要在子程序完成后再编译?有什么思维陷阱?
2014-02-11 234 The Pseudocode Programming Process
问题:那些情况说明在堆砌代码,需要停下来使用PPP?
——Writing good pseudocode calls for using understandable English, avoiding features specific to a single programming language, and writing at the level of intent (describing what the design does rather than how it will do it).
2014-02-12 243 General Issues in Using Variables
——The first step in creating effective data is knowing which kind of data to create. A good repertoire of data types is a key part of a programmer’s toolbox.
问题:在Data Literacy Test测试中能得多少分?下一本书是否选择数据结构与算法方面的?
——Initializing variables as they’re declared is an inexpensive form of defensive programming.
问题:"keep related actions together"在那些情况下适用?有什么好处?
2014-02-13 254 General Issues in Using Variables
——Thus the main advantage of keeping references to variables together is that it improves program readability.
问题:变量的span和live time各指的是什么?
——Initialize variables used in a loop immediately before the loop rather than back at the beginning of the routine containing the loop. Begin with most restricted visibility, and expand the variable’s scope only if necessary.
问题:变量值写代码时帮绑定,编译时绑定,运行时绑定各代表什么情况?迟绑定有什么好处?有什么坏处?
——Because successful programming depends on minimizing complexity, a skilled programmer will build in as much flexibility as needed to meet the software’s requirements but will not add flexibility—and related complexity—beyond what’s required.
2014-02-25 258 General Issues in Using Variables
——Patterns in the code match patterns in the data.
——Your real data can be combinations of the sequential, selective, and iterative types of data. You can combine the simple building blocks to describe more complicated data types.
问题:复用“临时变量”是好的编程实践吗?
——The variable is stretched over two jobs, meaning that the variable is the wrong type for one of the jobs.
问题:为什么要最小化变量的作用域,并全力避免全局变量?
2014-02-26 267 The Power of Variable Names
——Programmers sometimes overlook using the ordinary words,which is often the easiest solution.
A good name tends to express the what more than the how.问题:对于变量名长度需要有一个固定的规范吗?如何掌握合适的度?
——When you give a variable a short name like i, the length itself says something about the variable-namely, that the variable is a scratch value with a limited scope of operation.
——If you modify a name with a qualifier like Total, Sum, Average, Max, Min, Record, String, or Pointer, put the modifier at the end of the name.
问题:将计算值修饰词后置有哪些好处?
——If you have several nested loops, assign longer names to the loop variables to improve readability.
——A flag should never have flag in its name because that doesn't give you any clue about what the flag does.
——It's OK to figure out murder mysteries, but you shouldn't need to figure out code.You should be able to read it.
In general, temporary variables are a sign that the programmer does not yet fully understand the problem.
2014-02-27276 The Power of Variable Names
——Keep typical boolean names in mind: done, error, found, success or ok.
问题:以上这些经典的布尔变量名称各代表什么含义,适用在什么场合?
问题:命名布尔变量名称时加前缀is,有什么好处,有什么缺点?
——Effective standards are some of the most powerful tools at your disposal.
问题:命名惯例有哪些具体的好处?
——Programming conventions can make up for the weakness of the language you're using.
——Different conventions have different degrees of formality.An informal convention might be as simple as "Use meaningful names".
——Identify a class's member data. Make it clear that the variable isn't a local variable and that it isn't a global variable either.
——Augmenting a language with a naming convention to make up for limitations in the language itself is an example of programming into a language instead of just programming in it.
问题:Java的一般性命名惯例有哪些?
2014-02-28 285 The Power of Variable Names
问题:变量名应包含的三种信息:内容、种类和作用域各代表什么?
——Although the Hungarian naming convention is no longer in widespread use, the basic idea of standardizing on terse, precise abbreviations continues to have value.
——Standardized prefixes are composed of two parts: the user-define type(UDT) abbreviation and the semantic prefix.
问题:UDT和Semantic Prefixes的含义各是什么?有哪些常用的Semantic Prefixes?
——Standardized prefixes add precision to several areas of naming that tend to be imprecise. The precise distinctions between min, first, last and max are particularly helpful.
——In modern languages like C++, Java and Visual Basic, you can create names of virtually any length; you have almost no reason to shorten meaningful names.
问题:创造略缩词时有哪些注意点?
——Apply the telephone test-if you can't read your code to someone over the phone, rename your variables to be more distinctive.
——The fact that a programmer can't create a new abbreviation without the overhead of checking the Standard Abbreviations document out of version control, entering the abbreviation, and checking it back in is a good thing. It means that an abbreviation won't be created unless it's so common that it's worth the hassle of documenting it.
2014-03-02 290 The Power of Variable Names
——Read code of your own that you haven't seen for at least six month and notice where you have to work to understand what the names mean.
——If you can switch the names of two variables without hurting the program, you need to rename both variables.
问题:什么是变量名的心理距离?
问题:为什么用Count或者Index代替Num是一个良好的习惯?
——Good variable names are a key element of program readability. Specific kinds of variables such as loop indexes and status variables require specific considerations.
——Code is read far more times than it is written.Be sure that the names you choose favor read-time convenience over write-time convenience.
2015-03-03 295 Fundamental Data Types
——This chapter contains tips for using numbers(in general),integers,floating-point numbers,characters and strings,boolean variables,enumerated types,named constants,and arrays.
——A good rule of thumb is that the only literals that thould occur in the body of a program are 0 and 1.Any other literals should be replaced with something more descriptive.
——Avoid mixed-typed comparisons. Do the conversion manually so that the compiler can compare two numbers of the same type and you know exactly what's being compared.
——Top programmers fix their code to eliminate all compiler warnings.It's easier to let compiler do the work than to do it yourself.
——When using floating-point numbers,avoid additions and subtractions on numbers that have greatly different magnitudes.
问题:用计算机做无穷级数相加,为什么要从最小的开始?
2015-03-04 307 Fundamental Data Types
——There is an exception to every rule.
——In some languages such as Java,all strings are Unicode.In others such as C and C++,handling Unicode strings requires its own set of functions.
——Having a convention minimizes mental overload and programming errors.
问题:如何避免C中出现无限长的字符串?
——Instead of merely testing a boolean expression,you can assign the expression to a variable that makes the implication of the test unmistakable.
——Anytime you see a numeric literal,ask whether it makes sense to replace it with an enumerated type.
——If your language doesn't have enumerated types,you can simulate them with global variables or classes.
2015-03-05 318 Fundamental Data Types
——If the way the code is written leaves any shadow of a doubt about its purpose,clarify it with a well-named constant.
——Be a fanatic about rooting out literals in your code.Use a text editor to search for 2,3,4,5,6,7,8,and 9 to make sure you haven't used them accidentally.
——Consider using container classes that you can access sequentially-sets,stacks,queues,and so on-as alternatives before you automatically choose an arry.
问题:尽量用容器类代替数组有什么好处?
——Are type names oriented toward the real-world entities the types represent rather than toward programming-language types?