3 ms·
I've seen a project that defined string constants like: public static String HTTP = "http"; public static String COLON = ":"; public static String SLA
by arethuza 13y ago
I've seen a project that defined string constants like:
public static String HTTP = "http";
public static String COLON = ":";
public static String SLASH = "/";
with code that looked like:
url = HTTP + COLON + SLASH + SLASH + ....
[NB I am NOT joking]
- marcelocamanho 13y agoThis is 'the daily wtf' level stuff, but I believe it to be true.
- tzs 13y agoIt can be fun with code like that to see if you can imagine situations where you could argue with a straight face that the code is OK. public static String HTTP = "http"; An argument for this might be that it allows you to easily change to https by changing that one line, although then the name of the string would be misleading. public static String COLON = ":"; public static String SLASH = "/"; These are harder. Maybe you don't want ":" and "/" to appear literally because for some reason you grep for ":" and "/" a lot looking for instances that are syntactically significant in your language and you got tired of hitting those characters in URL strings. All of these potential excuses fall, though, to the objection that all three of those could have been rolled into a single string, with a sensible name like URL_COMMON_PREFIX: public static String URL_COMMON_PREFIX = "http://";