博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JavaScript命名约定:注意事项
阅读量:2543 次
发布时间:2019-05-11

本文共 2946 字,大约阅读时间需要 9 分钟。

I find it amazing how many different meanings we can get from less than 30 characters. I’m talking about the alphabet with some well-placed punctuation, of course. From a love story to a computer program, writing has allowed us to create extraordinarily different worlds. And language, in general, provides a framework in which we can hang a stream of ideas.

我发现令人惊讶的是,我们从不到30个字符中可以得到多少种不同的含义。 当然,我在谈论带有适当标点符号的字母。 从爱情故事到计算机程序,写作使我们能够创造截然不同的世界。 通常,语言提供了一个框架,我们可以在其中悬挂思想流。

Most programming languages seem to have very strict standards — certain terms have to be used in certain places. But one area where there is an enormous amount of freedom is how we name those terms.

大多数编程语言似乎都有非常严格的标准-必须在某些地方使用某些术语。 但是,自由命名的一个领域是我们如何命名这些术语。

Take this simple program which creates a sentence from an array of words, adds a punctuation mark, and logs it to the console:

使用这个简单的程序,该程序从一组单词中创建一个句子,添加标点符号,然后将其记录到控制台:

Nothing too special, right? But what you may not have considered is how many terms you were responsible to name.

没什么特别的吧? 但是您可能没有考虑的是您负责命名的术语

There are 23 words (not including hard-coded values) in the above program. We controlled the names of 14 of those words. That is more than 60% of what was typed, was our responsibility to name!

上述程序中有23个单词(不包括硬编码值)。 我们控制了其中14个单词的名称。 那是我们输入名字的责任的60%以上!

Whether you are building an enterprise application or a simple Hello, World, you want your program to read like a Times Bestseller, not a Mad Libs workbook.

无论是构建企业应用程序还是简单的Hello,World,您都希望程序像《时代》畅销书,而不是Mad Libs工作簿那样阅读。

This is not a manifesto on how to structure an entire JavaScript application, but rather a chapter on how to choose names for those things in which you have the freedom to do so. I’ve included the various references at the bottom if you want to learn more. One last thing, the key takeaway of all of our conventions and standards is this:

不是关于如何构建整个JavaScript应用程序的宣言,而是关于如何为那些可以自由选择的事物选择名称的章节。 如果您想了解更多信息,我在底部提供了各种参考。 最后,我们所有约定和标准的主要要点是:

Most of these conventions are not for you today, but instead, for you and the people reading your code tomorrow.

这些约定中的大多数今天并不适合您,而是您和明天阅读您的代码的人。

参考资料和继续学习 (References and continued learning)

  1. A great read for all languages. It goes beyond naming conventions and proposes the entire structure of your program. The examples are in Java, but the principles apply to JavaScript.

    精通所有语言。 它超越了命名约定,并提出了程序的整个结构。 这些示例使用Java,但是原理适用于JavaScript。

  2. The above book, but remade for JavaScript. It is available online and is free.

    上面的书,但为JavaScript进行了重新制作。 它可以在线免费获得。

  3. Possibly the most comprehensive style guide for JavaScript. It contains not only the what, but also the why. (If you’re on a small device, you may need to click on “view all readme” to see the entire document).

    - 可能是最全面的 它不仅包含内容,还包含原因。 (如果您使用的是小型设备,则可能需要单击“查看所有自述文件”以查看整个文档)。

  4. — A short and concise guide.

    简洁的指南。

  5. Google’s style guide for JavaScript.

    JavaScript样式指南。

Thanks for reading!

谢谢阅读!

woz

沃兹

Follow me on .

在关注我。

翻译自:

转载地址:http://dvuzd.baihongyu.com/

你可能感兴趣的文章
软件架构学习小结
查看>>
C语言实现UrlEncode编码/UrlDecode解码
查看>>
返回用户提交的图像工具类
查看>>
树链剖分 BZOJ3589 动态树
查看>>
挑战程序设计竞赛 P131 区间DP
查看>>
【例9.9】最长公共子序列
查看>>
NSFileManager打印目录下的文件的函数
查看>>
JavaScript 循环绑定之变量污染
查看>>
poj 1038 Bugs Integrated, Inc. 三进制状态压缩 DFS 滚动数组
查看>>
zoj 1654 Place the Rebots 最大独立集转换成二分图最大独立边(最大匹配)
查看>>
Wordpress解析系列之PHP编写hook钩子原理简单实例
查看>>
怎样看待个体经济
查看>>
不明觉厉的数据结构题2
查看>>
面向对象编程思想概览(四)多线程
查看>>
二十三种设计模式及其python实现
查看>>
Math类、Random类、System类、BigInteger类、BigDecimal类、Date类、SimpleDateFormat、Calendar类...
查看>>
【设计模式】 访问者模式
查看>>
关于FFMPEG 中I帧、B帧、P帧、PTS、DTS
查看>>
request和response的知识
查看>>
bootstrap 表单类
查看>>