Skip to content

Instantly share code, notes, and snippets.

View tkfx's full-sized avatar

Alex Zhitnitsky tkfx

View GitHub Profile
// 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.
// 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;
if (x == y && a > 10) // bad
if ((x == y) && (a > 10)) // good
private static final Logger logger = LoggerFactory.getLogger(Class.class);
// Bad.
// - Field names give little insight into what fields are used for.
class User {
private final int a;
private final String m;
...
}
// Good.
private static void runSomeAlgorithm(Graph graph) {
if (graph == null) {
return;
}
// do something with graph
}
private static void runSomeAlgorithm(Graph graph) {
// do something with graph
}
private static int isOpt(int x, int y) {
int veryHardCalculation = 0;
if (x >= y) {
veryHardCalculation = x * 1000 + y;
} else {
veryHardCalculation = y * 1000 + x;
}
return veryHardCalculation;
}
private static int isOpt(int x, int y) {
int veryHardCalculation = 0;
if (x < y) {
// this would not require a jump
veryHardCalculation = y * 1000 + x;
return veryHardCalculation;
} else {
veryHardCalculation = x * 1000 + y;
return veryHardCalculation;
@tkfx
tkfx / jge.asm
Last active July 21, 2016 15:36
0x00007fd715062d0c: cmp %edx,%esi
0x00007fd715062d0e: jge 0x00007fd715062d24 ;*if_icmplt
; - Opt::isOpt@4 (line 117)