Coding for Readability
By Charles K. Clarkson, March 01, 2005
Coding style is key to making sure your programs are maintainable. What's more, it can reduce the errors in your code.
March, 2005: Coding for Readability
<b>(a)</b>
if ($^O ne "MSWin32") { flock(USERFILE, LOCK_EX); }
if (@fields[1]=~m/^$loginname$/) {
if (@fields[2]=~m/^$password$/) {
$matchokay='true'; # login name matches password
}
}
if ($matchokay) { return $matchokay; }
else { return ''; }
<b>(b)</b>
flock USERFILE, LOCK_EX if $^O ne 'MSWin32';
if ( $user =~ m/^$loginName$/) {
if ( $password =~ m/^$password$/) {
$matchOkay = 'true';
}
}
if ( $matchokay ) {
return $matchokay;
} else {
return '';
}
Example 2: (a) Poorly indented code; (b) Improved indenting.