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
private static void runSomeAlgorithm(Graph graph) { | |
// do something with graph | |
} |
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
private static void runSomeAlgorithm(Graph graph) { | |
if (graph == null) { | |
return; | |
} | |
// do something with graph | |
} |
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. | |
// - Field names give little insight into what fields are used for. | |
class User { | |
private final int a; | |
private final String m; | |
... | |
} | |
// Good. |
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
private static final Logger logger = LoggerFactory.getLogger(Class.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
if (x == y && a > 10) // bad | |
if ((x == y) && (a > 10)) // good |
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
// simple constructor | |
// | |
private final int x; | |
private final int y; | |
private final String z; | |
| |
public MyClass(int x, int y, String z) { | |
this.x = x; | |
this.y = y; | |
this.z = z; |
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. | |
// - Line breaks are arbitrary. | |
// - Scanning the code makes it difficult to piece the message together. | |
throw new IllegalStateException("Failed to process request" + request.getId() | |
+ " for user " + user.getId() + " query: '" + query.getText() | |
+ "'"); | |
// Good. | |
// - Each component of the message is separate and self-contained. | |
// - Adding or removing a component of the message requires minimal reformatting. |
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
@Entity | |
@Table(name = "author", schema = "bookstore") | |
public class Author implements Serializable { | |
… | |
} |
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
@Id | |
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "authorSequence") | |
@SequenceGenerator(name = "authorSequence", sequenceName = "author_seq", initialValue = 1000) | |
@Column(name = "id", updatable = false, nullable = false) | |
private Long id; |
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
@Id | |
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "authorSequence") | |
@Column(name = "id", updatable = false, nullable = false) | |
private Long id; |