Skip to topic | Skip to bottom
Home
TModeling
TModeling.BadExampler1.1 - 16 Jun 2008 - 04:11 - Main.guesttopic end

Start of topic | Skip to actions
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
to top


Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback