作为程序员,我们经常看到一些充满Bug、让我们头痛不已的丑陋代码。在过去五年中,《易读代码的艺术(影印版)》的作者博斯韦尔(Dustin Boswell)和富彻(Trevor Foucher)分析了许多这样的“糟糕代码”(这些代码有很多是出自于他们自己之手),他们试图厘清为什么这些代码如此糟糕以及如何改进这些代码。他们得出的结论是:你必须写出让他人(这里也包括你自己)花费最少时间能够理解的代码。
图书 | 易读代码的艺术(影印版) |
内容 | 编辑推荐 作为程序员,我们经常看到一些充满Bug、让我们头痛不已的丑陋代码。在过去五年中,《易读代码的艺术(影印版)》的作者博斯韦尔(Dustin Boswell)和富彻(Trevor Foucher)分析了许多这样的“糟糕代码”(这些代码有很多是出自于他们自己之手),他们试图厘清为什么这些代码如此糟糕以及如何改进这些代码。他们得出的结论是:你必须写出让他人(这里也包括你自己)花费最少时间能够理解的代码。 目录 PREFACE CODE SHOULD BE EASY TO UNDERSTAND What Makes Code "Better"? The Fundamental Theorem of Readability Is Smaller Always Better? Does Time-TilI-UnderstandinR Conflict with Other Goals? The Hard Part Part One SURFACE-LEVEL IMPROVEMENTS PACKING INFORMATION INTO NAMES Choose Specific Words Auoid Generic Names Like Imp and retual Prefer Concrete Names ouer Abstract Names Attachin9 Extra Information to a Name How Lon.g Should a Name Be? Use Name Formatting to Conuey Meaning Summary NAMES THAT CAN'T BE MISCONSTRUED Example: FilterO Example: Clip(text, length) Prefer rain and max for (Inclusiue) Limits Prefer first and last for Inelusiue RanRes Prefer herin and end for.lnclusiue/Exclusiue RanRes NaminR Booleans MatchinR Expectations of Users Example: EualuatinR Multiple Name Candidates Summary AESTHETICS Why Do Aesthetics Matter? BearranRe Line Breaks to Be Consistent and Compact Use Methods to Clean Up IrreRularity Use Column AliRnment When Helpful Pick a MeaninRful Order, and Use It Consistently OrRanize Declarations into Blocks Break Code into "Parafgraphs" Personal Style uersus Consistency Summary KNOWING WHAT TO COMMENT What NOT to Comment Becordin9 Your Thouyhts Put Yourself in the Reader's Shoes Final Thoughts--Getting Over Writer's Block Summary MAKING COMMENTS PRECISE AND COMPACT Keep Comments Compact Avoid Ambiguous Pronouns Polish Sloppy Sentences Describe Function Behavior Precisely Use Input/Output Examples That Illustrate Corner Cases State the Intent of Your Code "Named Function Parameter" Comments Use Information-Dense Words Summary Part Two SIMPLIFYING LOOPS AND LOGIC MAKING CONTROL FLOW EASY TO READ The Order of Arguments in Conditionals The Order of if/else Blocks The ?: Conditional Expression (a.k.a. "Ternary Operator") Avoid dogwhile Loops Returning Early from a Function The Infamous goto Minimize Nesting Can You Follow the Flow of Execution? Summary BREAKING DOWN GIANT EXPRESSIONS Explainin9 Variables Summary Variables Using De Morgan's Laws Abusing Short-Circuit Logic Example: Wrestling with Complicated Logic Breaking Down Giant Statements Another Creative Way to Simplify Expressions Summary VARIABLES AND READABILITY Eliminatinfg Variables Shrink the Scope of Your Variables Prefer Write-Once Variables A Final Example Summary Part Three REORGANIZING YOUR CODE EXTRACTING UNRELATED SUBPROBLEMS Introductory Example: findClosestLoeationO Pure Utility Code Other General-Purpose Code Create a Lot of General-Purpose Code Project-Specific Functionality Simplilying an Existing Interface Reshaping an Interface to Your Needs Taking Things Too Far Summary ONETASK ATA TIME Tasks Can Be Small Extracting Values from an Object A Larger Example Summary TURNING THOUGHTS INTO CODE Describing Logic Clearly Knowing Your Libraries Helps Applying This Method to Larger Problems Summary WRITING LESS CODE Don't Bother Implementing That Feature--You Won't Need It Question and Break Douan Your Requirements Keeping Your Codebase Small Be Familiar with the Libraries Around You Example: Using Unix Tools Instead of Coding Summary Part Four SELECTED TOPICS TESTING AND READABILITY Make Tests Easy to Read and Maintain What's Wrong with This Test? Making This Test More Readable Making Error Messages Readable Choosing Good Test Inputs Naming Test Functions What Was Wrong with That Test? Test-Friendly Deuelopment Going Too Far Summary DESIGNING AND IMPLEMENTING A "MINUTE/HOUR COUNTER" The Problem Defining the Class Interface Attempt 1: A Naiue Solution Attempt 2: Conueyor Belt Design Attempt 3: A Time-Bucketed Design Comparing the Three Solutions Summary FURTHER READING INDEX |
标签 | |
缩略图 | ![]() |
书名 | 易读代码的艺术(影印版) |
副书名 | |
原作名 | |
作者 | (美)博斯韦尔//富彻 |
译者 | |
编者 | |
绘者 | |
出版社 | 东南大学出版社 |
商品编码(ISBN) | 9787564134471 |
开本 | 16开 |
页数 | 190 |
版次 | 1 |
装订 | 平装 |
字数 | 250 |
出版时间 | 2012-06-01 |
首版时间 | 2012-06-01 |
印刷时间 | 2012-06-01 |
正文语种 | 英 |
读者对象 | 青年(14-20岁),研究人员,普通成人 |
适用范围 | |
发行范围 | 公开发行 |
发行模式 | 实体书 |
首发网站 | |
连载网址 | |
图书大类 | |
图书小类 | |
重量 | 0.32 |
CIP核字 | |
中图分类号 | TP311.1 |
丛书名 | |
印张 | 12.75 |
印次 | 1 |
出版地 | 江苏 |
长 | 233 |
宽 | 178 |
高 | 10 |
整理 | |
媒质 | 图书 |
用纸 | 普通纸 |
是否注音 | 否 |
影印版本 | 原版 |
出版商国别 | CN |
是否套装 | 单册 |
著作权合同登记号 | 图字10-2012-161号 |
版权提供者 | O'Reilly Media, Inc. |
定价 | |
印数 | |
出品方 | |
作品荣誉 | |
主角 | |
配角 | |
其他角色 | |
一句话简介 | |
立意 | |
作品视角 | |
所属系列 | |
文章进度 | |
内容简介 | |
作者简介 | |
目录 | |
文摘 | |
安全警示 | 适度休息有益身心健康,请勿长期沉迷于阅读小说。 |
随便看 |
|
兰台网图书档案馆全面收录古今中外各种图书,详细介绍图书的基本信息及目录、摘要等图书资料。