1

1

1

https://github.com/google/styleguide

Google 编码风格/代码风格 手册/指南

Style guides for Google-originated open-source projects.

https://google.github.io/styleguide/htmlcssguide.xml

Google HTML/CSS Style Guide

General Style Rules

Protocol

link

Omit the protocol from embedded resources.(省略嵌入资源的协议。)

Omit the protocol portion (http:, https:) from URLs pointing to images and other media files, style sheets, and scripts unless the respective files are not available over both protocols.

Omitting the protocol—which makes the URL relative—prevents mixed content issues and results in minor file size savings.

<!-- Not recommended -->
<script src="https://www.google.com/js/gweb/analytics/autotrack.js"></script>
<!-- Recommended -->
<script src="//www.google.com/js/gweb/analytics/autotrack.js"></script>
/* Not recommended */
.example {
background: url(https://www.google.com/images/example);
}
/* Recommended */
.example {
background: url(//www.google.com/images/example);
}

https://google.github.io/styleguide/javascriptguide.xml

Google JavaScript Style Guide

Tips and Tricks

link

JavaScript tidbits

True and False Boolean Expressions

The following are all false in boolean expressions:

  • null
  • undefined
  • '' the empty string
  • 0 the number

But be careful, because these are all true:

  • '0' the string
  • [] the empty array
  • {} the empty object

This means that instead of this:

while (x != null) {

you can write this shorter code (as long as you don't expect x to be 0, or the empty string, or false):

while (x) {

And if you want to check a string to see if it is null or empty, you could do this:

if (y != null && y != '') {

But this is shorter and nicer:

if (y) {

Caution: There are many unintuitive things about boolean expressions. Here are some of them:

  • Boolean('0') == true

    '0' != true

  • 0 != null

    0 == []

    0 == false

  • Boolean(null) == false

    null != true

    null != false

  • Boolean(undefined) == false

    undefined != true

    undefined != false

  • Boolean([]) == true

    [] != true

    [] == false

  • Boolean({}) == true

    {} != true

    {} != false

Conditional (Ternary) Operator (?:)

Instead of this:

if (val) {
return foo();
} else {
return bar();
}

you can write this:

return val ? foo() : bar();

The ternary conditional is also useful when generating HTML:

var html = '<input type="checkbox"' +
(isChecked ? ' checked' : '') +
(isEnabled ? '' : ' disabled') +
' name="foo">';

&& and ||

These binary boolean operators are short-circuited, and evaluate to the last evaluated term.

"||" has been called the 'default' operator, because instead of writing this:

/** @param {*=} opt_win */
function foo(opt_win) {
var win;
if (opt_win) {
win = opt_win;
} else {
win = window;
}
// ...
}

you can write this:

/** @param {*=} opt_win */
function foo(opt_win) {
var win = opt_win || window;
// ...
}

"&&" is also useful for shortening code. For instance, instead of this:

if (node) {
if (node.kids) {
if (node.kids[index]) {
foo(node.kids[index]);
}
}
}

you could do this:

if (node && node.kids && node.kids[index]) {
foo(node.kids[index]);
}

or this:

var kid = node && node.kids && node.kids[index];
if (kid) {
foo(kid);
}

However, this is going a little too far:

node && node.kids && node.kids[index] && foo(node.kids[index]);

Iterating over Node Lists

Node lists are often implemented as node iterators with a filter. This means that getting a property like length is O(n), and iterating over the list by re-checking the length will be O(n^2).

var paragraphs = document.getElementsByTagName('p');
for (var i = 0; i < paragraphs.length; i++) {
doSomething(paragraphs[i]);
}

It is better to do this instead:

var paragraphs = document.getElementsByTagName('p');
for (var i = 0, paragraph; paragraph = paragraphs[i]; i++) {
doSomething(paragraph);
}

This works well for all collections and arrays as long as the array does not contain things that are treated as boolean false.

In cases where you are iterating over the childNodes you can also use the firstChild and nextSibling properties.

var parentNode = document.getElementById('foo');
for (var child = parentNode.firstChild; child; child = child.nextSibling) {
doSomething(child);
}

https://google.github.io/styleguide/angularjs-google-style.html

An AngularJS Style Guide for Closure Users at Google

https://google.github.io/styleguide/javaguide.html

Google Java Style Guide

https://google.github.io/styleguide/pyguide.html

Google Python Style Guide

https://google.github.io/styleguide/shell.xml

Shell Style Guide

https://google.github.io/styleguide/xmlstyle.html

Google XML Document Format Style Guide

Version 1.0
Copyright Google 2008

https://google.github.io/styleguide/cppguide.html#Formatting

Google C++ Style Guide

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

Google coding Style Guide : Google 编码风格/代码风格 手册/指南的更多相关文章

  1. Google C++ Style Guide的哲学

    Google C++ Style Guide并不是一个百科全书,也不是一个C++使用指南,但它描述适用于Google及其开源项目的编码指南,并不追求全面和绝对正确,也有许多人置疑它的一些规则.但作为一 ...

  2. python coding style guide 的快速落地实践——业内python 编码风格就pep8和谷歌可以认作标准

    python coding style guide 的快速落地实践 机器和人各有所长,如coding style检查这种可自动化的工作理应交给机器去完成,故发此文帮助你在几分钟内实现coding st ...

  3. electron教程(番外篇一): 开发环境及插件, VSCode调试, ESLint + Google JavaScript Style Guide代码规范

    我的electron教程系列 electron教程(一): electron的安装和项目的创建 electron教程(番外篇一): 开发环境及插件, VSCode调试, ESLint + Google ...

  4. 一张图总结Google C++编程规范(Google C++ Style Guide)

    Google C++ Style Guide是一份不错的C++编码指南,我制作了一张比較全面的说明图,能够在短时间内高速掌握规范的重点内容.只是规范毕竟是人定的,记得活学活用.看图前别忘了阅读以下三条 ...

  5. [Guide]Google Python Style Guide

    扉页 项目主页 Google Style Guide Google 开源项目风格指南 - 中文版 背景 Python 是Google主要的脚本语言.这本风格指南主要包含的是针对python的编程准则. ...

  6. [Guide]Google C++ Style Guide

    0.0 扉页 项目主页 Google Style Guide Google 开源项目风格指南 -中文版 0.1 译者前言 Google 经常会发布一些开源项目, 意味着会接受来自其他代码贡献者的代码. ...

  7. Google C++ Style Guide在C++11普及后的变化

    转 http://www.cnblogs.com/chen3feng/p/5972967.html?from=timeline&isappinstalled=0&lwfrom=user ...

  8. [中英对照]Linux kernel coding style | Linux内核编码风格

    Linux kernel coding style | Linux内核编码风格 This is a short document describing the preferred coding sty ...

  9. Google Shell Style Guide

    转自:http://google.github.io/styleguide/shell.xml Shell Style Guide Revision 1.26 Paul Armstrong Too m ...

随机推荐

  1. PHP 框架之一Laravel

    Laravel: Laravel The phpFramework for Web Artisans and one of the best php framework in year 2014. L ...

  2. list中map 的value值时间排序

    public static void main(String[] args) { String sys=DateUtil.getTime().substring(0,5); System.out.pr ...

  3. automake的简单使用

    https://blog.csdn.net/zhengqijun_/article/details/70105077 xxxxx https://blog.csdn.net/initphp/artic ...

  4. session和cookie自动登录机制

    cookie的存储 cookie是浏览器支持的一种本地存储方式.以dict,键值对方式存储. {"sessionkey": "123"} 浏览器会自动对于它进行 ...

  5. es5和es6的区别

    ECMAScript5,即ES5,是ECMAScript的第五次修订,于2009年完成标准化ECMAScript6,即ES6,是ECMAScript的第六次修订,于2015年完成,也称ES2015ES ...

  6. Golang简易版 网站路径扫描demo

    package main import ( "bufio" "fmt" "net/http" "os" "re ...

  7. Windows操作Redis及Redis命令

    Windows操作Redis及Redis命令 一.Windows下操作Redis 设置密码 打开redis服务 Windows 下的redis命令行 二.redis常用命令大全 key String ...

  8. eclipse中Tomcat修改项目名称

    1.打开你的项目目录,找到一个.project文件,打开后修改<name> test</name>中的值,将test修改成你要修改的名字: 2.在项目目录下,打开.settin ...

  9. docker启动脚本

    #!/bin/bash # 定义环境变量 export LANG="en_US.UTF-8" #统一格式化打印输出信息 printMsg(){ echo "$(date ...

  10. .net core 和 WPF 开发升讯威在线客服与营销系统:使用线程安全的 BlockingCollection 实现高性能的数据处理

    本系列文章详细介绍使用 .net core 和 WPF 开发 升讯威在线客服与营销系统 的过程.本产品已经成熟稳定并投入商用. 在线演示环境:https://kf.shengxunwei.com 注意 ...