zoukankan      html  css  js  c++  java
  • Change

    Change - Why we need coding standards

    I have the idea of coding standards when I have to review my team’s code.  I found it's painful to review others' code, for there was no official coding standards that time.  Somebody may say, though we don't have a coding standard, most parts are the same.  How most it is?  We don't know, and they didn't need to do code review that time.

    After I worked for an outsourcing company, I found strict coding standards were surprisingly effective and useful.  Nowadays, I believe every programmer is sure that coding standards are useful. Don't say that before I tell you what the coding standards is.  Give you a simple demo:  

     

    How about this time?

    At our company, we could look at any piece of code, anywhere in msstash, and we could read it. Could you easy to look at a piece of unfamiliar code and understand it?  You will found that it’s awful to read other teams’ code, even other people’s code in your team.  But why, do you think of that? 

    Do you have the standardization of style - indents, names, file structures, and comment conventions, for yourself, your team, and your company?

    After I read MarkCC’s article about coding standards, I think it covered most of the reason why people don’t like it.

    There's a suite of common objections to this, codify and simplify as below.

     

    It wastes time!

    I'm a good coder, and I don't want to waste time on stupidity.  I'm good enough that when I write code, it's clear and easy to understand.  Why should I waste my time on some stupid standard?

    I'm an artist!

    This is phrased facetiously, but it does reflect a common complaint.  We programmers have a lot of pride in our personal style.  The code that I write really does reflect something about me and how my mind works.  It's a reflection of my skill and my creativity.  If I'm forced into some stupid standard, it seems like it's stifling my creativity.

    One size fits all actually fits none!

    If you have a coding standard that wasn't designed specifically for your project, then it's probably non-optimal for your project.  That's fine.  Again, it's just syntax: non-optimal doesn't mean bad.

    I'm too good for that!

    This is actually the most common objection.  It's sort-of a combination of the others, but it gets at an underlying attitude in a direct way.  This is the belief on the part of the complainer that they're a better programmer than whoever wrote the standard, and lowering themselves to following the standard written by the inferior author will reduce the quality of the code.

    When you're coding against a standard, there are inevitably going to be places where you disagree with the standard.  There will be places where your personal style is better than the standard. But that doesn't matter.  As long as the standard isn't totally ridiculous, the comprehension benefits are significant enough to more than compensate for that.

    But what if the coding standard is totally ridiculous?

    Well, then, it's rough to be you: you're screwed.  But that's not really because of the ridiculous coding standard.  It's because you're working for idiots.  But it won’t happen in our company.

    Many questions we may meet:

    1. Our team has coding standards, it’s enough.

    Coding standards could be personal, team, department, company, industry.  The higher the better and the best is company level.  It makes easy to read code crossing teams and share.

    1. I know what the code meaning.

    Code is not for you.  At least it is for your team.

    In an agile team, we should conduct code review, pair programming, etc.  All these must base on coding standards.  I guess no one wants to review the code if it’s not your style, much more maintain it.  Buy why it’s your style, only when your style is equal to the company style.

  • 相关阅读:
    vue 路由嵌套 (子路由跳转报错或者失效解决方法)
    vue-cli3主题色系统
    vue项目哀悼日
    el-upload 文件上传显示进度
    课表
    uni-app 开发钉钉小程序
    Linux/Centos/Ubuntu crontab备份数据库
    【转】鲁迅为厦大题写校名,为啥4个字错了3个?专家:鲁迅故意写错的。
    计数单位资料汇总(个十百千兆京...,分厘毫丝忽微纤沙尘埃...)
    【转】如意算盘:中国的第五大发明
  • 原文地址:https://www.cnblogs.com/s021368/p/3183924.html
Copyright © 2011-2022 走看看