This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bad | |
if (data.selected == true){ | |
// do staff | |
} | |
if (data.selected != true){ | |
// do staff | |
} | |
// Good | |
if ( data ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bad | |
if (foo !== undefined && foo != null && foo != '') { | |
// do something... | |
} | |
// Good | |
if (foo) { | |
// do something... | |
} | |
// will evaluate to true if value is not: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bad | |
public Employee getSingleEmployee(params...){ | |
String sql = ...; | |
TypedQuery<Employee> query = entityManager.createQuery(sql, Employee.class); | |
query.setParameter(...); | |
List<Employee> list = query.getResultList(); // can load more than one result | |
if (list == null || list.isEmpty()) { | |
return null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bad | |
public List<Employee> getEmployeesByManager(Employee manager){ | |
String sql = "SELECT e FROM Employee e WHERE e.manager = :manager"; | |
Query query = entityManager.createQuery(sql); | |
query.setParameter(...); | |
return query.getResultList(); // Warning "unchecked" | |
} | |
// Good | |
TypedQuery<Employee> query = entityManager.createQuery(sql, Employee.class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bad | |
public static final int MARITAL_SINGLE = 1; | |
public static final int MARITAL_MARRIED = 2; | |
public static final int MARITAL_DISVORCED = 3; | |
public static final int MARITAL_WIDOW = 4; | |
public static final String MARITAL_SINGLE_NAME = "Single"; | |
public static final String MARITAL_MARRIED_NAME = "Married"; | |
public static final String MARITAL_DISVORCED_NAME = "Disvorced"; | |
public static final String MARITAL_WIDOW_NAME = "Widow[er]"; |
NewerOlder