Changes between Version 8 and Version 9 of WebInspectorCodingStyleGuide


Ignore:
Timestamp:
Feb 4, 2014 11:21:01 AM (9 years ago)
Author:
BJ Burg
Comment:

Organize the various advices, add nits about forEach vs. for..of and forEach this-binding.

Legend:

Unmodified
Added
Removed
Modified
  • WebInspectorCodingStyleGuide

    v8 v9  
    22
    33(Note: Few if any of these guidelines are checked by `check-webkit-style`. There's a tracking bug for that: [https://bugs.webkit.org/show_bug.cgi?id=125045])
     4
     5== Tokens, spacing, indentation, syntax
    46
    57* No trailing whitespace
     
    79* The opening bracket `'{'` after a named, non-inlined function goes on the next line. Anywhere else, the opening bracket `'{'` stays on the same line.
    810* Style for object literals is: `{key1: value1, key2: value2}`.
     11* Add new lines before and after different tasks performed in the same function.
    912* Calling a constructor with no arguments should have no parenthesis `'()'`. eg. `var map = new Map;`
    1013* Inline anonymous functions, especially if they don't need a bound `this`-object (using `.bind()`). Example:
     
    1417    });
    1518}}}
     19
     20== Naming things
     21
    1622* Avoid using the "on" prefix where possible. The `_onFoo` methods can just be `_foo` or `_handleFoo`.
    1723* New class names should use the name of the base class as a suffix. (ex: `TimelinesContentView` < `ContentView`). Exceptions: classes extending `WebInspector.Object` (unless they are a represented object), and deep hierarchies such as `DebuggerSidebarPanel` < `NavigationSidebarPanel` < `SidebarPanel` < `Object`.
    18 * Add new lines before and after different tasks performed in the same function.
     24* Spell out `identifier` instead of `id` if not doing so would result in a name ending with capitalized `Id`. For example, just `this.id` is fine, but `this.breakpointId` should be `this.breakpointIdentifier`.
     25
     26== API preferences
     27
    1928* Consider using [http://people.mozilla.org/~jorendorff/es6-draft.html#sec-keyed-collection `Map` and `Set` collections] instead of plain objects.
    2029* Consider using `rgb()` over hex colors in CSS
     30* Use `for..of` syntax when performing small actions on each element. Use `forEach` when the function body is longer. Use a classical for loop when doing index math.
     31* When using `forEach` or `map`, supply the `this`-object as the optional second parameter rather than binding it.
     32
     33
     34== Layering and abstractions
     35
    2136* Firewall the protocol inside the Manager classes. JSON objects received from the protocol are called "payload" in the code. The payload is usually deconstructed at the Managers level and passes down as smart objects inheriting from `WebInspector.Object`.
    2237* Avoid accessing *View classes from *Manager or *Object classes. This is a layering violation that prevents writing tests for models.
    2338* Avoid storing DOM elements in *Manager or *Object classes. (see above.)
    24 * Spell out `identifier` instead of `id` if not doing so would result in a name ending with capitalized `Id`. For example, just `this.id` is fine, but `this.breakpointId` should be `this.breakpointIdentifier`.
     39
     40== New class skeleton
    2541
    2642The new Inspector object classes should have the following format: