本文共 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.
这些约定中的大多数今天并不适合您,而是您和明天阅读您的代码的人。
— 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。
— The above book, but remade for JavaScript. It is available online and is free.
— 上面的书,但为JavaScript进行了重新制作。 它可以在线免费获得。
— 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).
- 可能是最全面的 。 它不仅包含内容,还包含原因。 (如果您使用的是小型设备,则可能需要单击“查看所有自述文件”以查看整个文档)。
— A short and concise guide.
— 简洁的指南。
— Google’s style guide for JavaScript.
JavaScript样式指南。
Thanks for reading!
谢谢阅读!
woz
沃兹
Follow me on .
在关注我。
翻译自:
转载地址:http://dvuzd.baihongyu.com/