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
if ( $user =~ m/^$loginName$/) {
if ( $password =~ m/^$password$/) {
return 1;
}
}
Becomes this:
if ( $user =~ m/^$loginName$/
&& $password =~ m/^$password$/ ) {
return 1;
}
Becomes this:
return 1 if $user =~ m/^$loginName$/
&& $password =~ m/^$password$/;
Then goes back in as this:
while ( <FH> ) {
my( $user, $password ) = ( split /\t/, $_ )[1, 2];
return 1 if $user =~ m/^$loginName$/
&& $password =~ m/^$password$/;
}
Figure 1: Transforming if statements for readability.