“Programs are meant to be read by humans and only incidentally( 顺便;偶然地;附带地) for computers to execute.” —Donald Knuth

When a team is brought together(被放在一起) for the first time, everyone brings with them their own ideas about how code should be written. After all, each team member comes from a different background. Some may come from one-man shops where they could do whatever they wanted; others may have been on different teams that had particular ways of doing things that they liked (or hated). Everyone has an opinion about how code should be written, and it usually falls in line with(fall in line with 同意) how that individual would personally write it. Establishing style guidelines should always come as early in the process as possible.

The terms “style guidelines” and “code conventions” are often used interchangeably. Style guidelines are a type of code convention aimed at the layout of code within a file. Code conventions can also include programming practices, file and directory layout, and commenting. This book is actually a collection and discussion of code conventions for JavaScript.

Why Style Guidelines?

Figuring out style guidelines is a process that typically takes longer than it should.Everyone has an opinion and, when you’re going to be spending eight hours a day writing code, all  programmers want to do so in a way that is comfortable to them. It takes some compromise within the team and a strong leader to move the conversation forward. Once established, style guidelines allow the team to work at a much higher level, because all code looks the same.

Having all code look the same is incredibly important on a team, because it allows:

• Any developer to work on any file regardless of(不管) who wrote it. There’s no need to spend time reformatting or deciphering the logic of the file, because it looks the same as everything else. If you’ve ever opened a file and immediately fixed all the indentation before starting your work, you can understand the time savings consistency provides when working on a large project.

• Errors become more obvious. If all code looks the same, and you come across some code that doesn’t, you’ve likely found a problem.

It’s no wonder that large companies around the world have published style guidelines either internally or publicly.

Style guidelines are a personal thing and must be developed within a team to be effective. This section of the book lists recommended focus areas for the development of your JavaScript code conventions. In some cases, it’s impossible to tell you that one guideline is better than another, because some are just a matter of preference. Rather than trying to force my preferences upon you, this chapter highlights important aspects that should be covered in your style guidelines. My personal code style guidelines for JavaScript are included in Appendix A.

Maintainable JavaScript(编写可维护的JavaScript) PART I Style Guidelines的更多相关文章

  1. 《编写可维护的JavaScript》之编程实践

    最近读完<编写可维护的JavaScript>,让我受益匪浅,它指明了编码过程中,需要注意的方方面面,在团队协作中特别有用,可维护性是一个非常大的话题,这本书是一个不错的起点. 本书虽短,却 ...

  2. 编写可维护的Javascript读书笔记

    写在前面:之前硬着头皮参加了java方面的编程规范培训,收货良多,工作半年有余的时候,总算感觉到一丝丝Coding之美,以及造轮子的乐趣,以至于后面开发新功能的时候,在Coding style方面花了 ...

  3. 《编写可维护的javascript》读书笔记(中)——编程实践

    上篇读书笔记系列之:<编写可维护的javascript>读书笔记(上) 上篇说的是编程风格,记录的都是最重要的点,不讲废话,写的比较简洁,而本篇将加入一些实例,因为那样比较容易说明问题. ...

  4. 《编写可维护的javascript》读书笔记(上)

    最近在读<编写可维护的javascript>这本书,为了加深记忆,简单做个笔记,同时也让没有读过的同学有一个大概的了解. 一.编程风格 程序是写给人读的,所以一个团队的编程风格要保持一致. ...

  5. 编写可维护的JavaScript 收纳架

    如果你看过Nicolas C.Zakas写过的任何作品,你必须承认他是个不折不扣的天才.也只有天才级的才能写出<JavaScript高级程序设计>让所有的前端攻城师人手一本.Nicolas ...

  6. 【读书笔记】读《编写可维护的JavaScript》 - 编程实践(第二部分)

    本书的第二个部分总结了有关编程实践相关的内容,每一个章节都非常不错,捡取了其中5个章节的内容.对大家组织高维护性的代码具有辅导作用. 5个章节如下—— 一.UI层的松耦合 二.避免使用全局变量 三.事 ...

  7. 编写可维护的JavaScript之编程风格

    在团队中只有每个人的编程风格一致,大家才能方便的互相看懂和维护对方的代码. 1. 层级缩进 对于层级缩进目前有两种主张:1)使用制表符这种方法有两种好处,第一,制表符和缩进层级之间是一一对应关系,符合 ...

  8. 《编写可维护的JavaScript》 笔记

    <编写可维护的JavaScript> 笔记 我的github iSAM2016 概述 本书的一开始介绍了大量的编码规范,并且给出了最佳和错误的范例,大部分在网上的编码规范看过,就不在赘述 ...

  9. 编写可维护的JavaScript代码(部分)

    平时使用的时VS来进行代码的书写,VS会自动的将代码格式化,所有写了这么久的JS代码,也没有注意到这些点.看了<编写可维护的javascript代码>之后,做了些笔记. var resul ...

随机推荐

  1. 解决npm安装模块时 npm err! registry error parsing json

    最近还真是点背,从yeoman生成一个react项目或是github上克隆一个项目,在npm install的时候, 一直报npm err! registry error parsing json(就 ...

  2. 微软Hololens学院教程-Hologram 211-Gestures(手势)【微软教程已经更新,本文是老版本】

    这是老版本的教程,为了不耽误大家的时间,请直接看原文,本文仅供参考哦!原文链接:https://developer.microsoft.com/EN-US/WINDOWS/HOLOGRAPHIC/ho ...

  3. 带节假日JS万年历控件代码

    <form name="CLD" class="content"> <table width="100%" border= ...

  4. POj 2186 Popular Cows[连通分量]

    题目大意:给出N头牛,有M种关系u, v.代表u牛崇拜v牛.要求找出有多少头牛被所有牛崇拜着题目链接:http://poj.org/problem?id=2186解题思路:1>求出强连通分量,标 ...

  5. Handlebars 介绍

    最新项目用到了Ember.js前端框架,第一次使用这样的框架,准备国庆节花2天时间,研究一下它的用法. Ember框架的模板引擎用到了handlebars, 先看国外的一篇介绍文章:An Introd ...

  6. PIL(Python Image Library)生成验证码

    # -*- coding: utf-8 -*-#导入三个模块import Image,ImageDraw,ImageFontimport randomimport math'''基本功能'''#图片宽 ...

  7. c++ const char *c_str(); 坑的学习

    语法: const char *c_str(); c_str()函数返回一个指向正规C字符串的指针, 内容与本string串相同. 这是为了与c语言兼容,在c语言中没有string类型,故必须通过st ...

  8. 游戏文字自动断行需要,还得从 UTF-8 讲起

    UTF-8(8-bit Unicode Transformation Format)是一种针对Unicode的可变长度字符编码,也是一种前缀码. UTF-8使用一至六个字节为每个字符编码(尽管如此,2 ...

  9. asp.net上传图片(简单)

    FileUpload: protected void UploadButton_Click(object sender, EventArgs e) { : Convert.ToInt64(Reques ...

  10. hdu4655Cut Pieces

    http://acm.hdu.edu.cn/showproblem.php?pid=4655 先以最大的来算为 N*所有的排列数  再减掉重复的 重复的计算方法:取相邻的两个数的最小值再与它前面的组合 ...