This document is a guide to programming for the Guido project. It should be adhered to as strictly as possible to ensure uniformity of style and readability for new developers.
NO:
sub myfunc
{
#Do stuff
}
YES:
sub myfunc {
#Do stuff
}
NO:
sub myfunc{
#Do stuff
}
YES:
sub myfunc {
#Do stuff
}
NO:
print "Hi there" ;
YES:
print "Hi there";
NO:
print 5+5;
YES:
print 5 + 5;
NO:
print "Starting process 1"; #process 1 print "Ending process 1"; print "Starting process 2"; #process 2 print "Ending process 2";
YES:
print "Starting process 1"; #process 1 print "Ending process 1";
print "Starting process 2"; #process 2 print "Ending process 2";
NO:
if ($ready) {
print "I'm ready";
} else {
print "I'm not ready";
}
YES:
if ($ready) {
print "I'm ready";
}
else {
print "I'm not ready";
}
OK:
if ($ready) {
print "I'm ready";
}
else {
print "I'm not ready";
}
BETTER:
print $ready ? "I'm ready" : "I'm not ready";
NO:
$name = get_name ($first_name, $last_name);
YES:
$name = get_name($first_name, $last_name);
NO:
$name = get_name($first_name,$last_name);
YES:
$name = get_name($first_name, $last_name);
All others should use the function() syntax when called.
tr [abc] [xyz];
sub new {
my($class, %attribs) = @_;
my $self = {
name = $attribs{name},
file_path = $attribs{file_path},
};
return bless $self, $class; }
sub method {
my($self, %params) = @_;
#Do stuff here
}
open(FOO,$foo) or die "Can't open $foo: $!";
print "Starting analysis\n" if $verbose;
NO:
print "This is line 1\n"; print "This is line 2\n"; print "This is line 3\n"; print "This is line 4\n"; print "This is line 5\n"; print "This is line 6\n"; print "This is line 7\n";
YES:
print <<EOF; This is line 1 This is line 2 This is line 3 This is line 4 This is line 5 This is line 6 This is line 7 EOF
$IDX = $ST_MTIME; $IDX = $ST_ATIME if $opt_u; $IDX = $ST_CTIME if $opt_c; $IDX = $ST_SIZE if $opt_s; mkdir $tmpdir, 0700 or die "can't mkdir $tmpdir: $!"; chdir($tmpdir) or die "can't chdir $tmpdir: $!"; mkdir 'tmp', 0777 or die "can't mkdir $tmpdir/tmp: $!";
opendir(D, $dir) or die "can't opendir $dir: $!";
NO:
$MyVariable = 1; $MYVARIABLE = 1;
YES:
$my_variable = 1;
$Some_Caps_Here package-wide global/static $no_caps_here function scope my() or local() variables
NO:
$BUFFER_SIZE = 40;
YES:
use constant BUFFER_SIZE = 40;
NO:
package my_package_name;
YES:
package MyPackageName;
sub _private_sub {
#This sub is called only by its own package
}