Carmack concluded in 2005 about Java on cell-phones: "The biggest problem is that Java is really slow. On a pure cpu / memory / display / communications level, most modern cell phones should be considerably better gaming platforms than a Game Boy Advance.
I had to maintain java code, where most of the Exception handling was like:
catch( Exception e ) {}
Once I encountered 'singleton' exception:
class Singletons {
public static final MyException myException = new MyException();
}
class Test {
public void doSomething() throws MyException {
throw Singletons.myException;
}
}
Same instance of exception was thrown each time ... with exact same stacktrace, which had nothing to do with real code flow :-(
Six really bad examples;
System.exit
without warning. e.g.if(properties.size()>10000) System.exit(0);
buried deep in a
library. synchronized("one") { }
.synchronized(object) { object = ...; }
.try { Integer i = null; i.intValue(); } catch(NullPointerException e) { e.printStackTrace(); }
.new Integer(text).intValue() or worse new Integer(0).getClass()
if{
if{
if{
if{
if{
if{
if{
if{
....
I hate it when people create interfaces just for hanging a set of constants on:
public interface InterfaceAntiPattern {
boolean BAD_IDEA = true;
int THIS_SUCKS = 1;
}
—Interfaces are for specifying behavioural contracts, not a convenience mechanism for including constants.
Not related strictly to Java, but calling an expensive function over and over instead of storing the result, when you know it won't change. Example:
if (expensiveFunction() > aVar)
aVar = expensiveFunction();
for (int i=0; i < expensiveFunction(); ++i)
System.out.println(expensiveFunction());
The worst Java practice that encompasses almost all others: Global mutable state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With