Software Craftsmanship
Clean vs Messy Code
October 11, 2016
http://xkcd.com/844/
Clean code is the reward for elegant design, planning, and execution.
Messy code is a symptom of poor design or some other problem.
//Build Request for each and every Token
public String buildRequest(String npi,int npi_length) {
if (npi_length==9)
return "{\"value\":\"" + npi + "\", \"client\": \""+ProducerSSNTokenize.line_of_business+"\", \"type\": \""+ProducerSSNTokenize.SSNString+"\"}";
else if (npi_length==16)
return "{\"value\":\"" + npi + "\", \"client\": \""+ProducerSSNTokenize.line_of_business+"\", \"type\": \""+ProducerSSNTokenize.PANString+"\"}";
else
return null;
/* if (npi_length==9)
return "{\"SSN\":\"" + npi + "\", \"Client\": \""+ProducerSSNTokenize.line_of_business+"\"}";
else if (npi_length==16)
return "{\"PAN\":\"" + npi + "\", \"Client\": \""+ProducerSSNTokenize.line_of_business+"\"}";
else
return null;*/
}private JsonObject getPayloadBody(String npiData, String client, String type) {
JsonBuilderFactory factory = Json.createBuilderFactory(null);
JsonObject payloadBody = factory.createObjectBuilder()
.add(JSON_VALUE_KEY, npiData)
.add(JSON_CLIENT_KEY, client)
.add(JSON_TYPE_KEY, type)
.build();
return payloadBody;
}Mess builds, productivity of team decreases
Under pressure, the team makes more messes
Entropy - The amount of disorder in a system. When disorder increases in software, it is called "code rot".
The only way to develop quickly and meet deadlines is to keep the code as clean as possible at all times.
"A code smell is a surface indication that usually corresponds to a deeper problem in the system".
- Martin Fowler