Wednesday, 1 March 2017

"I know.. instead of typing a forward-slash in a string, I'll declare a static variable for the "/" character"

Was looking at some code someone else wrote and came across:

public static final String SLASH = "/ ";     

FML. Dude. WTF were you even thinking? Why even have a constant? To save us from typing? Instead of one character you now have 5, and then the "+" symbol. What are the odds of making an error on a forward slash?  You're just using it in other static declarations anyway *in the same class*.