About Naming

命名那些事

命名的方式基本有三种,驼峰式蛇式匈牙利命名法

Alt text

其中使用驼峰和蛇式居多,而匈牙利命名法这种方法实在是反人类。

这里引用2位大师的吐槽

Robert C. Martin:

… 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, member or class. They make it harder to read the code. And they create the possibility that the encoding system will mislead the reader.

Linus Torvalds :

Encoding the type of a function into the name (so-called Hungarian notation) is brain damaged—the compiler knows the types anyway and can check those, and it only confuses the programmer.

在变量前面加入类型前缀这种做法没有任何帮助,只能让代码难以阅读,让大脑受伤.
编译器知道类型检测,无需画蛇添足.

MindMapping Source:

1
2
3
4
5
6
7
8
9
* Naming
** Camel(驼峰式)
*** lowerCamel(小驼峰)
*** UpperCamel(大驼峰)
也叫Pascal (帕斯卡)
** Snake(蛇式)
*** snake_case
** Hungarian(匈牙利)
*** c_Hungarian