Good Practices

No Code Block...


This really bugs me, a boolean logic statement with no code block...

 if(variable1 == variable2) DoSomething(); 

I know it is done all the time and it's OK. However, it lends itself to FatFingers which produces buggy code. Better solution?

 if(variable1 == variable2) {  DoSomething(); } 

A pain to add the code block, but much safer. This way if something is added at a later time, like...

 if(variable1 == variable2) {  DoSomething();  DoSomethingElse(); } 

...the code block is already there. Besides, the compiler has to add that code block anyway!

CREATED 2013-01-17 13:51:31.0

00-19-75

UPDATED 2013-01-17 14:01:40.0

Knotty Code...


OK, its NOT, but knot sounds better... or maybe looks better? It forces both the compiler and the JVM to do extra work. Maybe one knot seems OK but two, three, fourty... you can never eat just one. This is what I mean...

 if(! test){  DoSomething(); } 

...easier, but it will slow the code down. This is a better solution...

 if(test){ }else{  DoSomething(); } 

Empty statement... yes. But it is easier on the compiler and when you eliminate a thousand knots, the code runs faster.

CREATED 2013-01-17 14:02:19.0

00-19-76

UPDATED 2013-01-17 14:07:44.0

Knowledge

L
I
N
K
S

DBID: db.wam

Page Server: Ruger

©2012 Leistware Data Systems

      Hello anonymous