---恢复内容开始---

 Meaningful Names:

 use Intention-Revealing Names //nice,Everyone who  reads your code (including you) will be happier if you do.

     The name of a variable, function, or class, should answer all the big questions. It
should tell you why it exists, what it does, and how it is used. If a name requires a com-
ment, then the name does not reveal its intent.//Good Name can help us . Choosing names that reveal intent can make it much easier to understand and change code Avoid Disinformation Programmers must avoid leaving false clues that obscure the meaning of code.We should avoid
words whose entrenched meanings vary from our intended meaning. Do not refer to a grouping of accounts as an accountList unless it’s actually a List.
The word list means something specific to programmers. If the container holding the
accounts is not actually a List, it may lead to false conclusions. So accountGroup or
bunchOfAccounts or just plain accounts would be better. Make Meaningful Distinctions It is not sufficient to add number series or noise words, even though the compiler is
satisfied. If names must be different, then they should also mean something different. In the absence of specific conventions, the variable moneyAmount is indistinguishable
from money, customerInfo is indistinguishable from customer, accountData is indistinguish-
able from account, and theMessage is indistinguishable from message. Distinguish names in
such a way that the reader knows what the differences offer. Use Pronounceable Names Humans are good at words. A significant part of our brains is dedicated to the concept of
words. And words are, by definition, pronounceable. In the absence of specific conventions, the variable moneyAmount is indistinguishable
from money, customerInfo is indistinguishable from customer, accountData is indistinguishable
from account, and theMessage is indistinguishable from message. Distinguish names in
such a way that the reader knows what the differences offer. If you can’t pronounce it, you can’t discuss it without sounding like an idiot. Use Searchable Names Single-letter names and numeric constants have a particular problem in that they are not
easy to locate across a body of text. My personal preference is that single-letter names can ONLY be used as local vari-
ables inside short methods 我在项目中大部分都是用的pronounceable names,因为关联的表越来多,涉及到东西也会比较多,名字---见名知意,不仅可以快速的理解代表的含义,也可以知道code的含义或着其目的。
Avoid Encodings

    We have enough encodings to deal with without adding more to our burden. Encoding
type or scope information into names simply adds an extra burden of deciphering Encoded namesare seldom pronounceable and are easy to mis-type. Hungarian Notation So nowadays HN and other forms of type encoding are simply impediments.
They make it harder to change the name or type of a variable, function, or class. They
make it harder to read the code. And they create the possibility that the encoding system
will mislead the reader. Member Prefixes
You also don’t need to prefix member variables with m_ anymore. Your classes and func-
tions should be small enough that you don’t need them. And you should be using an edit-
ing environment that highlights or colorizes members to make them distinct. Besides, people quickly learn to ignore the prefix (or suffix) to see the meaningful
part of the name. The more we read the code, the less we see the prefixes. Eventually the
prefixes become unseen clutter and a marker of older code. Interfaces and Implementations
These are sometimes a special case for encodings.
For example, say you are building an ABSTRACT FACTORY for the creation of shapes.
what should you name them?
I just want them to know that it’s a ShapeFactory.
So if I must encode either the interface or the implementation, I choose
the implementation. Calling it ShapeFactoryImp, or even the hideous CShapeFactory,
is preferable to encoding the interface. Avoid Mental Mapping Readers shouldn’t have to mentally translate your names into other names they already
know. This problem generally arises from a choice to use neither problem domain terms
nor solution domain terms. This is a problem with single-letter variable names. in most other contexts a single-letter name is a poor choice; it’s just a place
holder that the reader must mentally map to the actual concept. There can be no worse rea-
son for using the name c than because a and b were already taken. One difference between a smart programmer and a professional programmer is that
the professional understands that clarity is king. Professionals use their powers for good
and write code that others can understand Class Names A class name should not be a verb. Method Names
Methods should have verb or verb phrase names like postPayment, deletePage, or save.
Accessors, mutators, and predicates should be named for their value and prefixed with get,
set, and is according to the javabean standard. For example,
Complex fulcrumPoint = Complex.FromRealNumber(23.0);
is generally better than
Complex fulcrumPoint = new Complex(23.0); Don’t Be Cute
If names are too clever, they will be memorable only to people who share the
author’s sense of humor, and only as long as these people remember the joke. Cuteness in code often appears in the form of colloquialisms or slang. For example,
don’t use the name whack() to mean kill(). Don’t tell little culture-dependent jokes like
eatMyShorts() to mean abort(). Say what you mean. Mean what you say. Pick One Word per Concept Pick one word for one abstract concept and stick with it. The name leads you to expect two objects that have very different type as well as
having different classes. Sadly, you often have to remember
which company, group, or individual wrote the library or class in order to remember which
term was used. Otherwise, you spend an awful lot of time browsing through headers and
previous code samples. The function names have to stand alone, and they have to be consistent in order for you to pick the cor-
rect method without any additional exploration. A consistent lexicon is a great boon to the programmers who must use your code.

---恢复内容结束---

clean code meaningful names的更多相关文章

  1. “Clean Code” 读书笔记序

    最近开始研读 Robert C.Martin 的 “Clean Code”,为了巩固学习,会把每一章的笔记整理到博客中.而这篇博文作为一个索引和总结,会陆续加入各章的笔记链接,以及全部读完后的心得体会 ...

  2. [转]Clean Code Principles: Be a Better Programmer

    原文:https://www.webcodegeeks.com/web-development/clean-code-principles-better-programmer/ ----------- ...

  3. 代码整洁之道Clean Code笔记

    @ 目录 第 1 章 Clean Code 整洁代码(3星) ?为什么要整洁的代码 ?什么叫做整洁代码 第 2 章 Meaningful Names 有意义的命名(3星) 第 3 章 Function ...

  4. Clean Code – Chapter 3: Functions

    Small Blocks and Indenting The blocks within if statements, else statements, while statements, and s ...

  5. Writing Clean Code 读后感

    最近花了一些时间看了这本书,书名是 <Writing Clean Code ── Microsoft Techniques for Developing Bug-free C Programs& ...

  6. 说说怎么写clean code

    前两天参加了公司组织的一个培训,主题是“如何写出好的代码” ,刚看到这个主题,第一反应是又不知道是哪个培训机构来忽悠钱的!老大安排了,就去听听呗. 说实在的,课程内容没有什么新鲜的东西,就是讲讲如何发 ...

  7. 小课堂week13 Clean Code Part2

    Clean Code Part2 对象与数据结构 首先让我们进行一个严肃的思考,对象与数据结构的区别在哪里? 如下两段代码分别用数据结构和对象的方法来描述了一个Point. public class ...

  8. 小课堂Week12 Clean Code Part1

    小课堂Week12 Clean Code Part1 今天的主题是函数,让我们看一个函数,找一找其中的"不整洁". 我们也根据这段代码,讨论下对于整洁代码的两个重要原则. publ ...

  9. Clean Code–Chapter 7 Error Handling

    Error handling is important, but if it obscures logic, it's wrong. Use Exceptions Rather Than Return ...

随机推荐

  1. linux C学习笔记03--单链表

    单链表一直是程序员的基础,我也来复习下,下面是link.c中的代码,供main.c 调用,代码很简单,单链表的插入,删除,查找和遍历输出, #include <stdio.h> #incl ...

  2. Mysql错误信息汇总

    目录: 1. Every derived table must have its own alias 内容: 1. Every derived table must have its own alia ...

  3. fastJson java后台转换json格式数据

    什么事JSON? JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机器解析和生成. 它基于JavaScript Progra ...

  4. OpenShift:外国的免费云平台

    二.安装openshift客户端 对于怎么安装openshift客户端,我就不说了,网上有很多教程,连官网也有他自己的教程. 官网教程:https://developers.openshift.com ...

  5. singleton(单件)-对象创建型模式

    1.意图 保证一个类仅有一个实例,并提供一个访问它的全局访问点. 2.动机 对一些类来说,只有一个实例是很重要的.让类自身负责保存它唯一的实例,这个类可以保证没有其他实例可以被创建(通过截取创建新对象 ...

  6. 如何将PHP对象数组转换成普通数组

    /** * 对象数组转为普通数组 * * AJAX提交到后台的JSON字串经decode解码后为一个对象数组, * 为此必须转为普通数组后才能进行后续处理, * 此函数支持多维数组处理. * * @p ...

  7. POJ3694 Network

    题目大意:已知连通图G有N个点m条无向边,有Q次操作,每次操作为增加一条边,问每次操作后图上有几个桥. 如果添加一条边进行Tarjin搜索一次时间复杂度为m*m*q很大,会超时.真的超时,我试过.看了 ...

  8. Java核心知识点学习----多线程 倒计时记数器CountDownLatch和数据交换的Exchanger

    本文将要介绍的内容都是Java5中的新特性,一个是倒计时记数器---CountDownLatch,另一个是用于线程间数据交换的Exchanger. 一.CountDownLatch 1.什么是Coun ...

  9. IIS7中的站点、应用程序和虚拟目录详细介绍 (转)

    这里说的不是如何解决路径重写或者如何配置的问题,而是阐述一下站点(site),应用程序(application)和虚拟目录 (virtual directory)概念与作用,已及这三个东西在IIS6与 ...

  10. Daily Scrum 12.11

    今日完成任务: 解决了类型同时存在于两个自动生成的DLL中导致编译不通过的问题:修复了主页标签显示的BUG:修复异常,网站可以在服务器端正常运行. 明日任务: 黎柱金 解决上传文档时建立文档和标签联系 ...