Michele Flores e Ricardo Machado
Eduardo Pretz
Engenharia de Software I
The Software engineering is an area of computing focused in specification, development and maintenance of software systems, with application of technologies and project management practices and other disciplines, aimed at organization, productivity and quality.
More
work?
Waste of time?
Clean Code?
It serves no purpose!
My code is perfect!
This doesn't speed up the process!
Software engineering?
Intention-Revealing Names
public List<int[]> getThem() {
List<int[]> list1 = new ArrayList<int[]>();
for (int[] x : theList)
if (x[0] == 4)
list1.add(x);
return list1;
}public List<Cell> getFlaggedCells() {
List<Cell> flaggedCells = new ArrayList<Cell>();
for (Cell cell : gameBoard)
if (cell.isFlagged())
flaggedCells.add(cell);
return flaggedCells;
}Avoid Disinformation
int a = l;
if ( O == l )
a = 01;
else
l = 01;int number = value;
if ( ORIGINAL_VALUE == value )
number = 01;
else
value = 01;Pronunciable Names
class DtaRcrd102 {
private Date genymdhms;
private Date modymdhms;
private final String pszqint = "102";
/* ... */
};class Customer {
private Date generationTimestamp;
private Date modificationTimestamp;;
private final String recordId = "102";
/* ... */
};Searchable Names
for (int j=0; j<34; j++) {
s += (t[j]*4)/5;
}
int realDaysPerIdealDay = 4;
const int WORK_DAYS_PER_WEEK = 5;
int sum = 0;
for (int j=0; j < NUMBER_OF_TASKS; j++) {
int realTaskDays = taskEstimate[j] * realDaysPerIdealDay;
int realTaskWeeks = (realdays / WORK_DAYS_PER_WEEK);
sum += realTaskWeeks;
}Avoid Mental Mapping
List<Vehicle> v = vehicleService.list();
m.addAttribute("vehicles", v);
if(me == null){
me = "";
}
if(r == null){
r = RequestStatus.SUCCESS;
}
m.addAttribute("r", r);
m.addAttribute("me", me);
return "vehicle/list";List<Vehicle> vehicles = vehicleService.list();
m.addAttribute("vehicles", vehicles);
if(message == null){
message = "";
}
if(requestStatus == null){
requestStatus = RequestStatus.SUCCESS;
}
m.addAttribute("requestStatus", requestStatus);
m.addAttribute("message", message);
return "vehicle/list";Don't be Cute
HolyHandGrenade
whack()
eatMyShorts()
DeleteItems
kill()
abort()public class Assert {
static public void assertTrue(String message, boolean condition)
{
if (!condition)
fail(message);
}
static public void assertTrue(boolean condition) {assertTrue(null, condition);}
static public void assertFalse
(
String message,
boolean condition
) {assertTrue(message, !condition);
}
static public void assertFalse(boolean
condition)
{
assertFalse(null, condition);
}public class Assert {
static public void assertTrue(String message, boolean condition) {
if (!condition)
fail(message);
}
static public void assertTrue(boolean condition) {
assertTrue(null, condition);
}
static public void assertFalse(String message, boolean condition) {
assertTrue(message, !condition);
}
static public void assertFalse(boolean condition) {
assertFalse(null, condition);
}Make it Work, then make it right
MARTIN, Robert C. Clean Code, a Handbook of Agile Software Craftsmanship. Pearson Education, 2009.
REFACTORING. Available in <https://sourcemaking.com/refactoring>. Access November 18th, 2015.
Bibliography