《The Art of Readable Code》的原文摘录

  • 找到更有表现力的词 send -> deliver, dispatch, announce, distribute, route find -> search, extract, locate, recover start -> launch, create, begin, open make -> create, set up, build, generate, compose, add, new (查看原文)
    Yan 6赞 2012-11-12 23:16:16
    —— 引自第13页
  • Names like i, j, iter, and it are commonly used as indices and loop iterators. Even though these names are generic, they’re understood to mean “I am an iterator.” (In fact, if you used one of these names for some other purpose, it would be confusing—so don’t do that!) But sometimes there are better iterator names than i, j, and k. For instance, the following loops find which users belong to which clubs: (查看原文)
    forgetthisuser 1赞 2013-02-05 12:12:44
    —— 引自第12页
  • The goal of this book is help you make your code better. (查看原文)
    容貌焦虑主理人 2011-11-06 19:49:08
    —— 引自章节:vii
  • Keeping Your Codebase Small (查看原文)
    [已注销] 1回复 2011-11-25 11:59:13
    —— 引自第142页
  • Finding More "Colorful" Words (查看原文)
    duguguiyu 2012-04-01 23:11:01
    —— 引自第9页
  • Values with Units (查看原文)
    duguguiyu 2012-04-01 23:52:52
    —— 引自第16页
  • Test code should be readable so that other coders are comfortable changing or adding tests. (查看原文)
    duguguiyu 1回复 2012-04-02 00:23:17
    —— 引自第150页
  • Creating the Minimal Test Statement (查看原文)
    duguguiyu 1回复 2012-04-02 00:23:17
    —— 引自第150页
  • The Fundamental Theorem of Readability:Code should be written to minimize the time it would take for someone else to understand it. Remember, when in doubt, the Fundamental Theorem of Readability trumps any other rule or principle in this book. (查看原文)
    toby 2012-04-10 21:24:09
    —— 引自章节:1
  • A D V I C E The name tmp should be used only in cases when being short-lived and temporary is the most important fact about that variable. (查看原文)
    toby 2012-04-10 21:26:41
    —— 引自章节:2
  • If your variable is a measurement (such as an amount of time or a number of bytes), it’s helpful to encode the units into the variable’s name. (查看原文)
    toby 2012-04-11 10:04:19
    —— 引自第16页
  • 1. use specific words 2. avoid generic names, like tmp and retval 3. use concrete names 4. attach important details 5. use longer names for larger scopes. use word completion. 6. use capitalization, underscores and so on in a meaningful way. (查看原文)
    Evan 2012-04-23 22:29:43
    —— 引自章节:Chapter 2 Pack your informatio
  • Coders often state this rule as good code > bad code + good comments (查看原文)
    curer 2012-07-12 15:18:34
    —— 引自第49页
  • Code should be written to minimize the time it would take for someone else to understand it. (查看原文)
    curer 2012-07-21 10:59:15
    —— 引自第8页
  • Part of “packing information into names” is choosing words that are very specific and avoiding “empty” words. For example, the word “get” is very unspecific, as in this example: def GetPage(url) The word “get” doesn’t really say much (查看原文)
    curer 2012-07-21 10:59:15
    —— 引自第8页
  • So if an identifier has a large scope, the name needs to carry enough information to make it clear. (查看原文)
    curer 2012-07-23 13:56:55
    —— 引自第19页
  • What not to comment: • Facts that can be quickly derived from the code itself. • “Crutch comments” that make up for bad code (such as a bad function name)—fix the code instead. Thoughts you should be recording include: • Insights about why code is one way and not another (“director commentary”). • Flaws in your code, by using markers like TODO: or XXX:. • The “story” for how a constant got its value. Put yourself in the reader’s shoes: • Anticipate which parts of your code will make readers say “Huh?” and comment those. • Document any surprising behavior an average reader wouldn’t expect. • Use “big picture” comments at the file/class level to explain how all the pieces fit together. • Summarize blocks of code with comments so that the reader doesn’t get lost in the details. (查看原文)
    curer 2012-07-25 13:01:10
    —— 引自第57页
  • This way, if == is accidentally written as =, the expression if (NULL = obj) won’t even compile. Unfortunately, switching the order makes the code a bit unnatural to read. (As Yoda would say, “Not if anything to say about it I have.”) Thankfully, modern compilers warn against code like if (obj = NULL), so “Yoda Notation” is becoming a thing of the past. (查看原文)
    curer 2回复 2012-07-26 17:42:56
    —— 引自第71页
  • Engineering is all about breaking down big problems into smaller ones and putting the solutions for those problems back together. Applying this principle to code makes it more robust and easier to read. (查看原文)
    curer 2012-07-28 17:20:51
    —— 引自第110页
  • REMOVING UNUSED CODE (查看原文)
    curer 2012-08-02 23:28:39
    —— 引自第143页
<前页 1 2 3 4 后页>