http://qs321.pair.com?node_id=215696


in reply to My coding guidelines

I think it's no great use making guidelines in general. You'll have to agree on guidelines in one project and it's good to have concrete ideas. The actual decisions will depend on the group.

Some of the things you mention are in my eyes means of sane programming (system calls, exit code). I don't think you can work seriously with someone who has to be told these things. Also, I'd never say "SHOULD". Say "MUST", so first of all there is no doubt: "Use strict! No exceptions. That's it." Someone who _really_ knows when to disable strictness, will do it. Someone who doesn't will struggle for a solution and ask for help and then someone else may tell him "This is the exception, you may disable strict here."

So there are some general rules i'd make (and in general i agree with you):

  1. use strict! Always.
  2. use warnings! Always.
  3. Doing CGI? use CGI.pm! Always.
  4. Parsing commandline options? use Getopt::Long and Configure() it POSIXLY_CORRECT! Always.
  5. check system calls! Always.
  6. Use comments to comment, use POD to document. Don't mix these two.
  7. Avoid Globals!
  8. Globals are all variables with a scope that is larger (in the sourcecode) than an average screen.
  9. Name Globals wisely. Follow perlstyle rules
  10. Use spaces to make things clearer

These are the rules I consider "general". Other things are matter of personal taste but should be equal inside a project:

  1. open the curly on same line as keyword. Indent next line.
  2. closing curly on single line, indented as deep as keyword of opening curly.
  3. curly-rule exceptions are special short blocks (map,grep,sort)
  4. No space between function name and opening parens.
  5. No space between array identifier and opening square bracket.
  6. No space between hash identifier and opeing curly

Now finally the Tab-issue: I really think that one should use tabs, but only for indentation. Don't use tabs for alignement.

if( $a > $b ){ T---return T---T---cond1 ? val1 : T---T---cond2 ? val2 : T---T--- default T---; }

This way your alignement won't break in someone else's editor using a different tab-width, but logical indentation is still present. I am really convinced that this is a solution.

--
http://fruiture.de