反例:

    正例:

    1. function hashIt(data) {
    2. var hash = 0;
    3. var length = data.length;
    4. for (var i = 0; i < length; i++) {
    5. var char = data.charCodeAt(i);
    6. hash = ((hash << 5) - hash) + char;
    7. // Convert to 32-bit integer
    8. hash = hash & hash;
    9. }
    10. }

    版本控制的存在是有原因的。让旧代码存在于你的 history 里吧。

    反例:

    1. doStuff();
    2. // doOtherStuff();
    3. // doSomeMoreStuff();
    4. // doSoMuchStuff();

    记住,我们可以使用版本控制。废代码、被注释的代码及用注释记录代码中的版本更新说明都是没有必要的。

    需要时可以使用 git log 获取历史版本。

    反例:

    1. * 2016-12-20: Removed monads, didn't understand them (RM)
    2. * 2016-10-01: Improved using special monads (JP)
    3. * 2016-02-03: Removed type-checking (LI)
    4. */
    5. function combine(a, b) {
    6. return a + b;
    7. }

    正例:

    1. function combine(a, b) {
    2. return a + b;
    3. }

    反例:

    正例:

    1. let $scope.model = {
    2. menu: 'foo',
    3. nav: 'bar'
    4. };
    5. let actions = function() {
    6. // ...
    7. }

    将你的 LICENSE 文件置于源码目录树的根目录。

    反例:

    1. /*
    2. The MIT License (MIT)
    3. of this software and associated documentation files (the "Software"), to deal
    4. in the Software without restriction, including without limitation the rights
    5. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    6. copies of the Software, and to permit persons to whom the Software is
    7. furnished to do so, subject to the following conditions:
    8. The above copyright notice and this permission notice shall be included in all
    9. copies or substantial portions of the Software.
    10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    13. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    14. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    15. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    16. SOFTWARE
    17. */
    18. function calculateBill() {
    19. // ...