wiki:BadCodeExamples
Last modified 11 years ago Last modified on 07/07/09 17:07:23

Here we will put examples of bad code when somebody pass it to us for review and we find such stuff :)

  • Example for bad code :
    • Leaved TODOs generated from eclipse.
    • No JavaDoc on the class and strange "doc" over the package.
    • Semicolon in the middle of nowhere...
/**
 * 
 */
package org.sophie2.main.func.help.bugreport;

import org.sophie2.core.mvc.EventFilterBuilder;
import org.sophie2.core.mvc.OperationDef;
import org.sophie2.core.mvc.events.EventR3;

/**
 * 
 * 
 * @author somebody
 *
 */
public enum BugReportLogic implements OperationDef {
	;

	@Override
	public void defineFilter(EventFilterBuilder filter) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean handle(EventR3 event) {
		// TODO Auto-generated method stub
		return false;
	}

}
  • Don't put your curly brackets wherever you want like this:
            if(width < Page.MIN_PAGE_WIDTH || width > Page.MAX_PAGE_WIDTH)
            {
    		SwingDialog.this.verificationLabel.setText("Not correct width!");
    		return;
    	}
    
  • Don't swallow exceptions like that:
                    try {
    	            Reader r = new FileReader(txtFile);
    	            createText(r,text);
    	            r.close();
    	            txtResource.text().set(text);
    	            txtResource.text().set(text);
    	            txtResource.origin().set(txtFile.getAbsolutePath());
    	            return txtResource;
    	        } catch (Exception e) {
    	            return null;
    	        }