- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
At least it implements an if (Whitespace) then SetNull pattern automatically. That's the frist thing everyone wants to write anyway.
Admin
Oh boy, this mistake (mishandling
String
references and creating tons ofString
objects as a result) is covered even in OCJP material and exam questions. That should tell you something.Admin
Somebody needs to challenge him to actually write code to modify a string instance. Maybe he'll succeed, I know in C# you can maybe do something with reflection and unsafe points. But even if he does, he'll realise just how unlikely and illogical it is to protect against it.
Admin
Yup, you can do the same trick in Java - grab the
Field
holding the backingchar[]
suddenly you can mutate strings.But why stop there? The runtime maintains a cache of
Integer
instances for autoboxing (the process that converts a primitive int into an object), IIRC on the range of a signed byte. If you want to be really nasty you can reflectively replace one of thoseInteger
s and suddenly7 != (int) (Integer) 7
.There's a reason languages with reflection caution against using it willy-nilly, I suppose.
Admin
Yes, you can modify a string in Java with some (ab)use of reflection (at least in OpenJDK). What's funny is that
new String(otherString)
doesn't even copy the underlyingchar[]
array (relying on immutability of theotherString
); you have to donew String(otherString.toCharArray())
if you really want to protect against it.Admin
Don't tell him that! Imagine he hears about it and sprinkles the array duplication everywhere. That'd be a huge commit.
Admin
#define TRUE FALSE
Admin
Any developer who names an argument the same as a member variable, such that [s]he needs to disambiguate by qualifying one with the 'this' pointer (i.e. this.value = value;) needs to be taken behind the server rack and strangled with a Cat 5 cable.
Admin
Real hell for programmers is a terrible GUI framework, like Win32 MFC or the early Java frameworks.
Admin
Why? For constructors and setters, that's the normal approach. I can understand why you wouldn't like it in other contexts, but this is so standard it should be second nature to even moderately experienced developers.
Admin
So instead is should be this.value = thatOtherValue?
Admin
Tells me that the API is lacking, because the "obvious thing to do (for the untrained)" is the wrong thing to do. In this case, there's no actual reason for String to have a copy-constructor.
Admin
string _myString; public string myString { get {return string.IsNullOrEmpty(_myString) ? null : _myString; } set { _myString = value; } }
... but really a simple "public string myString {get; set; }" would do ...
Admin
... but really a simple "public string myString {get; set; }" would do ...
This forum needs a "preview" button. And some formatting instructions for noobs like me.
Admin
.length is a method, not a property of a Java string. He should call .length() instead
Admin
Sorry, my fault, while retyping this on TDWTF. In the original sources, it was "length()", of course.
Admin
Actually, the real WTF is that the author thinks an empty string is the same as a null string and a string consisting only of white space is the same as both.
Admin
Why don't you tone it down a notch there, buddy? That is a very strong opinion on a question not deserving of such a vitriol one way or another. It's not like it's tabs vs. spaces, is it?
And by the way, you are wrong and I'm willing to fight you about it! ;-)