Wednesday 6 June 2012

Clean Code again

Sometimes I have a time for code review... I run these sessions with my team.
It was popular trend to read a hundred books on legacy code or clean code and other Zen of programming. I did a lot as well. I'm lazy programmer, even more than other guys, but I can't stop refactoring if something smells.



Yesterday I found myself following already few years the same habits of opening the file. I read a lot of source code a day. Yep Im lazy and have to use configured IDE that makes for me navigation etc. Yes Im perfectionist and doing always 4 steps when opening new source code file:

1. Looking for size of code lines, last one 205. Not so bad, my screen allows me to see 75, my IDE compose all imports into one string with expand button.

2. Pressing PgDwn, I'm at the end of the file. Looks like the list of imports is too big. PgUp jumps me back to the header.

3. Expanding import's block shows me:

import bla.bla.bla.bla.ConfigRepository;
import bla.bla.bla.bla.ConfigRepositoryHome;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.rmi.RemoteException;

import javax.annotation.PostConstruct;
import javax.ejb.CreateException;
import javax.ejb.EJB;
import javax.ejb.EJBException;


import org.apache.axis.AxisFault;
import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.input.SAXBuilder;

import org.jdom.output.XMLOutputter;

import bla2.bla2.bla2.bla2.UuidHelper;
import bla2.bla2.bla2.bla2.client.ConsultSoapBindingStub;
import bla2.bla2.bla2.bla2.client.WSMessageHandlerServiceLocator;
import bla2.bla2.bla2.bla2.service.BlaBLayerException;
import bla2.bla2.bla2.bla2.service.EoriEOSService;

import com.google.common.annotations.VisibleForTesting; 

a lot - isn't it? IO + XML + WebService client + Configuration + Business

3. Looking into interface declaration - one method! Interface is ok, except required boilerplate of J2EE to declare non-Runtime exception into ejb method signature.


    boolean isValid(String countryCode, String number) throws BlaBLayerException

4 I have to read and refactor the code because of item 2!

5. Other actions, sonar, test coverage etc.



No comments:

Post a Comment