I think I should quit... ;)
-
Just found this gem:
[code]String quit="quit".toUpperCase().trim();[/code]
-
I'd like to hope that javac would see that as a constant expression and only store "QUIT", but I doubt it does.
-
Nope, it doesn't. At least, not on the version of Java that I tested (1.5 or something).
To be fair to Java, it might not optimize something like .toUpperCase() due to internationalization issues.
-
Hmmm maybe the CAPS LOCK and shift key were broken on that person's computer, and so was the monitor so they were not sure if they typed any spaces...
It could happen. (But probably not)
-
Yes, that could happen.
They needed autocompletion to write 'String' and 'toUpperCase' though...
-
@rbowes said:
Nope, it doesn't. At least, not on the version of Java that I tested (1.5 or something).
To be fair to Java, it might not optimize something like .toUpperCase() due to internationalization issues.
Yep, that's exactly it. On Turkish systems, "quit".toUpperCase() == "QUİT".
Let's just say that way too many Java programmers have discovered unnoticed bugs involving case conversion by having Turks beta-test their software.
Maybe the developer of this program was just trying to avoid the Turkish-I problem, but if that's the case, there are much better ways to handle it (e.g., by specifying a locale for the case conversion)...
-
Or by putting the "QUIT" string in a resource, since I doubt "QUİT" is a word in any language.
-
It's coded with forward maintenance in mind!
The day someone want to change the string you'll be sure quit won't accidentaly contain lower cased characters. Brillant!
It goes without saying that I'll now start using this pattern throughout my code.
-
@matthewr81 said:
Hmmm maybe the CAPS LOCK and shift key were broken on that person's computer
Then how could he have typed toUpperCase()
-
by cutting an pasting all the letters he needed from this fine selection...
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
-
@bobday said:
by cutting an pasting all the letters he needed from this fine selection...
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
He could have written "QUIT" then. I think the selection was
"ABCDEFGHJKLMNOPRSUVWXYZabcdefghijklmnopqrstuvwxyz"
-
@Starfish said:
@matthewr81 said:
Hmmm maybe the CAPS LOCK and shift key were broken on that person's computer
Then how could he have typed toUpperCase()Code Completion FTW!
-
On Screen Keyboard. Check out the accessibility features build into XP. Fun stuff!
-
Sadly that is not a gem in the code I work with. It is more like a common pebble.