令程序员最头疼的事,“命名”这件事遥遥领先

众所周知,给孩子其名不是件轻松的事,有些长辈还要专门找起名专家。而程序员天天都要其名,各种变量、对象、类没完没了,按照代码规范还要求必须要有意义,但有时候真的很词穷,各种中文字母、数字都上去了。既然程序都用英语单词写,那么说英语的老外应该轻松多了吧?然而,据老外的一篇文章“如果你没有一个好词库,就不要去编程”中反馈,在关于对"程序员最难的事”投票中总共有4500个来自quora和ubuntuforums的投票,其中49%的票投给了“命名”,遥遥领先其它几项,比如测试、写文档、出方案、与人沟通协作、解析自己做什么等,这个结果令人很惊讶。看来编程代码中的命名,对于母语是英语的程序员也一样是件头疼的事,以后不要在怪自己英文不好了。

关于“命名”为什么是最难的事,下面有几段来自原文的引用:

"I do spend a lot of time as well worrying about the names of anything that can be given a name when I am programming."  willcodejavaforfood 
"I have to agree that naming is an art."  Otávio Décio
"...its one of the most important things if you want your code to be readable by others."  Geries Handal
"Often times, however, the inability to come up with a name may be a hint to something wrong with your design. Does your method have too many responsibilities? Does your class encapsulate a coherent idea?"  Brad Barker
"One lesson I heave [sic] learned, is that if you can't find a name for a class, there is almost always something wrong with that class: you don't need it, it does too much"  Toon Krijthe
"It's good that it's difficult. It's forcing you to think about the problem, and what the class is actually supposed to do."  JW.

下面是投票结果:

编码中最难的事情投票,命名占49%

数据来自: itword

结论

代码命名是最难且最重要的事

坚持正确的代码命名是值得的

发布了49 篇原创文章 · 获赞 32 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/CatherineJChen/article/details/104444473