Well, I wan't to share my code style too, but with less rules, since I think that simple is better, and I will explain some:
2 spaces for ident.
Because you win horizontal space, is easier, and 2 is just the sufficient to identify the difference
of levels.
No table (\t) in the code, including index.
Table doesn't work well in all the editors and OS!
Open block in the same line: if (...) {
Do not declare else/elsif in the same line of previous close block!:
if (...) {
....
}
else { }
Blocks, with 1 group of statement, or small blocks, will be in one line:
if (...) { $x++ ;}
Always put the ";", even when is the last in the block: (use like the previous code).
Because if you put the ";" always, you can add codes after it without care to add the ; in the
prevoius. If you cut the ";" and need to put new codes after it, the probability to forget to check the previous line is
big, and this make bugs!
In foreach use for the scalar the same name of the array plus "_i":
foreach my $array_i ( @array ) {}
## Note that I have an editor that make this for me! ;-P
Separate the code in subs, and if make sence build it in OO, or better a Perl Module.
Spaces between strings and ",": (a , b, c). But not between string and "("! But for variables use the space:
( %hash , a , b)
Spaces when the code open and close alot "(","{": join("x", length( $hash{ $hash2{k}{k2} } )) ;
Put ";" separated of the last code: length($foo) ;
Because if you want to add or change the code ";" is already the position, and avoid the wrong cut
of chars:
length($foo) if $foo ;
Use $i,$j,$k... for index, $c for count, and $s for "tmp" string.
1 for true, undef for false, not 0!
Use $var shift only for objects, and variables that will be used a lot, or when directly access $_[0] doesn't bring speed!
Always Class->method, never method Class (this includes "new"!). (I agree with this too)
For q or qq, use "`": $var = q`fooo` ;
Since "`" is not much used for strings! Better than ~,/, or anoy other.
Always use parens: tie( %hans , 'pack' , arg ) ;
For returned data always use: return() ;
Before each sub make a comment box: (My editor make this for me, useful to mark the point and open a area for comments to:)
#######
# FOO # Some comment
#######
sub foo {
...
}
Well, I think that for now is just this!
Graciliano M. P.
"The creativity is the expression of the liberty".