http://www.perlmonks.org?node_id=777269


in reply to Why Create Coding Standards and Perform Code Reviews?

I'm becoming increasingly convinced that good coding and good writing have a lot in common. Structure, clarity of names, use of comments all work together to tell a story on two levels: one to the machine that will compile it and one to the person reading or maintaining it.

If you write a paper for a scientific journal, magazine or a university course there are clear guidelines for formatting, footnote and citation style, length of abstract, and so forth. All of these are meant to speed up the reading and review process. None of these pretend to try to make the article into a better article.

I think we ask too much of coding standards. We want to them to create good code. They can't. Only clear thinking about the code and how to explain it to other readers down the line can. Comments, variable names, structure are all tools that can work together in this effort. Sometimes they are interchangable. Sometimes they are not. Trying to come up with fixed rules about how they should be used actually impedes the writing process rather than helping it.

When I started out leading teams I used to get very fussy about how people coded. I've grown up since then and have moved more to a minimal set of standards focused entirely on readability and error detection. I try to focus on those that make it easier to skim code and leave the quality of code issues to other parts of the team process (e.g. code reviews). These are some of the standards that have worked for me and my teams (YMMV):

Anything else is up for discussion. Over time I've come to believe that things like cuddling vs. not-cuddling don't have a huge impact on readability, so long as one approach or the other is used consistently within a code sample. We can learn to read code either way and probably should. The items listed above seem to matter more because they reduce the time spent searching up and down a file to figure out what someone meant.

Best, beth

Replies are listed 'Best First'.
Re^2: Why Create Coding Standards and Perform Code Reviews?
by Your Mother (Archbishop) on Jul 04, 2009 at 21:43 UTC
    I'm becoming increasingly convinced that good coding and good writing have a lot in common.

    Not only is this generally true, I think its veracity is proportional to a language's expressiveness. Perl being what it is, this might be more true for Perl than any other language. It's either a weakness or a strength, like many other parts of Perl, depending on who is on the console.