Bad Example
Here is an example of bad style written in Java
for(i=2;i<=num;i++){
meetsCriteria[i]=true;
}
for(i=-2;i<=num/2;i++){
j=i+i;
while(j<=num){
meetsCriteria[j]=false;
j=j+1;
}
}
for(i=1;i<=num;i++){
if(meetsCriteria[i]){
System.out.println(i+" meets criteria." );
}
}
Problems:
- The lack of white space makes it hard to read
- The lack of indentation makes it hard to infer logical structure
- The lack of good variable names makes it hard to figure out what the code does
- The too generic array name meetsCriteria could be anything
- In short, it's hard to figure out the purpose of this snippet of code
--
ShawnDB - 16 Jun 2008
Revision: r1.1 - 16 Jun 2008 - 04:11 - Main.guest