Slashdot Mirror


Ask Slashdot: Do Coding Standards Make a Difference?

An anonymous reader writes "Every shop I've ever worked in has had a 'Coding Style' document that dictates things like camelCase vs underscored_names, placement of curly braces, tabs vs spaces, etc. As a result, I've lost hundreds of hours in code reviews because some pedant was more interested in picking nits over whitespace than actually reviewing my algorithms. Are there any documents or studies that show a net productivity gain for having these sorts of standards? If not, why do we have them? We live in the future, why don't our tools enforce these standards automagically?"

19 of 430 comments (clear)

  1. After 42 yrs programming I say... by rs79 · · Score: 5, Insightful

    ...yes but not very much a all. Nothing beats clear thinking.

    --
    Need Mercedes parts ?
    1. Re:After 42 yrs programming I say... by man_of_mr_e · · Score: 5, Interesting

      Coding standards were largely developed to prevent developers from reformatting each others code in a format war.

      Joe works on code, checks it in. Bill gets a task to work on that code, doesn't like Joe's formatting, so he reformats, checks that in.. Joe works on the code again, finds it's been reformatted, then he reformats it again.

      This is hell when doing diff's and figuring out what changes from version to version. Coding standards help to prevent that.

      Another reason for coding standards is to set a level playing field for everyone.

    2. Re:After 42 yrs programming I say... by gantzm · · Score: 5, Insightful

      Can't agree with "not very much at all".

      I don't really care what coding standard you use, pick one any one. But here's the rub, pick one and stick with it.

      I get really exhausted and tired having to jump between 4 or 5 completely different coding styles in the same project. And I'm not just talking about indentation and formatting. I'm talking about how problems are solved.

      For example: If you're coding in Java and the "style" is to Using Apache StringUtils for what it does, then use that. Don't go create your own monster mess that does the same thing, then force me to take 15 minutes to figure out you re-wrote StringUtils for no damn good reason.

      I've watched developers struggle with this and waste hours upon hours tracking down bugs because of stuff like this. And, you know what? They never want to admit it's because the code is a typographical mess that puts your eyes into unending calisthenics.

      --


      Excessive forking causes un-wanted children.
    3. Re:After 42 yrs programming I say... by Decameron81 · · Score: 5, Interesting

      THE reaSON WHy coDiNg standards_exist is thatTheyIncrease THE_REaDABILITY oF YOur cODe.

      --
      diegoT
    4. Re:After 42 yrs programming I say... by BasilBrush · · Score: 5, Insightful

      Most diffs can ignore whitespace...
      I don't understand your second point.

      You didn't understand his first point.

    5. Re:After 42 yrs programming I say... by casings · · Score: 5, Insightful

      Assigning blame to people because of bugs is in fact one of the most detestable things you can do in software development. Bugs will always exist, no matter what coding style you use. If your first priority is to name and shame and not fix the code and move onto the next issue, then your teammates are going to hate you.

    6. Re:After 42 yrs programming I say... by blackm0k · · Score: 5, Insightful

      Not to name and shame, to know who to ask about what they were exactly they were doing when they changed that bit of code. You know, so my fix doesn't break there changes.

    7. Re:After 42 yrs programming I say... by IAmGarethAdams · · Score: 5, Funny

      (I know, I know, it means you must be a PHP developer)

    8. Re:After 42 yrs programming I say... by UnknownSoldier · · Score: 5, Insightful

      Exactly!

      After you use a few different coding standards an experienced developer doesn't care _what_ the actual standards (such as http://en.wikipedia.org/wiki/Indent_style ) , just as long as EVERYONE follows them.

    9. Re:After 42 yrs programming I say... by lgw · · Score: 5, Insightful

      Is it better to drive on the left side of the road, or the right side of the road? There might be some argument to be made that one is better due to most peopl ebegin right-handed, but it's not going to make much of a difference.

      But it's really important that everyone drives on the same side of the road.

      It's simply faster and easier to read code that has style standards followed throughout. Even when they're pretty stupid.

      --
      Socialism: a lie told by totalitarians and believed by fools.
  2. "a net productivity gain"..YES by who_stole_my_kidneys · · Score: 5, Insightful

    because when you leave\get fired\DIE, everyone can read your code and not have to interpret it, thus productivity gained.

  3. Yes, they do by Anonymous Coward · · Score: 5, Insightful

    I find it impossible to believe that anyone has actually lost hundreds of hours in reviews due to style, unless they were purposely not following what are usually pretty simple guidelines.

    The differences between one style and another are meaningless, but the value of having a consistent style across an entire codebase is, in my experience, enormous. If everyone can read your code as though it was their own, that does in fact save hundreds of hours of time across the team.

  4. Long story short... by beelsebob · · Score: 5, Funny

    Programmer doesn't like the coding standards that someone else set, decided to whine about it on slashdot.

    Yes, having consistent code makes a difference, it lets you make more assumptions when reading code. If you can't manage to even manage to follow a simple style guide, you're probably doing all kinds of other sloppy things that are unwanted in the code.

    Man up and spend a little while getting used to it, and using it properly.

    1. Re:Long story short... by Rakishi · · Score: 5, Insightful

      I think designing and writing code is a form of art, and you wouldn't tell a painter how to to draw his strokes, or a writer to always write sentences in a well defined style.

      Hahahahaha. When companies pay writers or artists to work on a shared piece they sure as hell mandate all those things.

      Do you think all the artwork in a game has consistent style by some black magic? Hell no, all the artists are told what style to adhere to and they do. Same with writing. Same when artists collaborate. Would you want to read a book that randomly switched fonts and writing styles every few paragraphs?

      If you want to do your own thing then fine but don't expect to do so on someone else's dime. They're paying you to work as part of a team, stop being a whinny immature child.

  5. It's your responsibility. by pclminion · · Score: 5, Insightful

    We live in the future, why don't our tools enforce these standards automagically?

    Some do. As the developer it's your job to make sure it happens, however you do it.

    As a result, I've lost hundreds of hours in code reviews because some pedant was more interested in picking nits over whitespace than actually reviewing my algorithms

    Was the nit picker correct? That is, was he pointing out true variances from the standard? If so, the fastest way to appease him is to cram your ego and make the changes. If you're arguing about something that is clearly spelled out in the coding standard, then YOU are the one who is wasting time by arguing about it. If not, and the nit picker is just slinging shit, then call him out for wasting time in meetings.

  6. Naming, sure. Whitespace? No. by TheNinjaroach · · Score: 5, Insightful

    Consistent naming is important. It lets you quickly call into libraries that other people have written without having to double check, "was that camel cased or underscored spaced?"

    But nit-picking over whitespace is simply annoying. Any person who insists on that much compliance might be trying to compensate for lack of performance in more important areas.

    --
    I went to eat some animal crackers and the box said, "Do not eat if seal is broken." I opened the box and sure enough..
  7. Most Java shops I've worked automate code style by neiras · · Score: 5, Informative

    We have always had standardized checkstyle and jtidy rules as part of our build system. We have eclipse formatting configuration that everyone uses as well. Commits don't happen unless checkstyle is happy.

    I thought everyone did this. I guess tooling is less developed in some languages, but it's not too hard to put this kind of thing into practice with a little bit of effort and buy-in.

  8. Ya to me sounds like "I'm special" syndrome by Sycraft-fu · · Score: 5, Insightful

    This guy thinks he's the shit programming wise and thus has to do his own thing. He's too good to be bound by the rules of everyone else. So he keeps fucking up and then crying about it.

    His company should just can him.

  9. It helps by Cro+Magnon · · Score: 5, Informative

    Once I was put on a project with rather strict standards. I didn't like their naming conventions, and the style was noticeably different from mine. But I soon found that whichever of their programs I was assigned to, it was relatively easy to follow because of the similarity with the other programs in that system. In contrast, the system I'd been on before had no standards, and everyone did things their own way (including me), and I had to study each new program before making any significant changes.

    --
    Slow down, cowboy! It has been 4 hours since you last posted. You must wait another few hours.