- 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
Contrary to what you might think, there are instances of language implementations that consider a bunch 'o spaces to be the same as a null string.
Back in oh around 1990, i had the displeasure of having to use Metaware's Pascal on Interactive IX/386 UNIX. Not only did it consider "andy " to be equal to "andy" (grr) but the developers (sic) of the compiler explained that it was there for PL/1 programmers (pounds head against wall). So I guess a bunch 'o spaces would compare equal to "".
So, had to "dis" (assemble) the offending RTL function, and re-assemble it (AT+T syntax of course) without any manuals.
(That and a length word for "Borland/UCSD" style strings game me a lot of unentertaining unsleep - porting a general ledger program from Borland).
Your consultant is clearly in need of deeply improving electroshock therapy..
Admin
I could actually understand if the code was actually supposed to count a bunch of whitespace as an empty string. If it is being used for input validation for a form, it makes sense. But if thats the case, the function was poorly named.
Admin
Um, first of all making the Parameter a String would eliminate the need for a check at all. If you need to check for whether its a String do it before the function.
Admin
wrong.
.Equals doesn't existt. String.Empty doesn't exist.
Admin
err.. ever heard of String intern?
String.Empty.equals(whatever) - doesn't exist.
Admin
now, why having already ascertaining that the object is a String, would you toString() it? Furthermore, why trim it?
Admin
yeah but you've changed the method signature
Admin
Admin
The best way of doing this would be:
public static boolean isEmptyString( String obj ){ return ((s != NULL) && (s.trim().length() == 0)); }
Also this isn't a real wtf. It could be used in a lot of situations (for example reading/validating a file).
Admin
Alex, I'm curious about your "non-WTF" job service. Do you warn potential employers that people who claim that code like this "could be used in a lot of situations" to run, not walk, but run away as fast as they can? Or do you simply suggest that they browse the website for ambulatory disaster areas waiting to happen?
Just wondering. It's a value-added sort of thing, really.
Admin
// Big Boss programmer tells me that I need to add // an isNotEmptyString function to compliment isEmptyString.
define IS_EMPTY_STRING 1;
public static boolean isNotEmptyString( Object obj ) { if (obj != null) { if (isEmptyString (obj)) { return false; } else { return !isEmptyString(obj); } } else { // I dont understand why, but without this part, // program sometimes crashes with a recursion error ??? if (obj == null) {
} }
// which allows to to now simplify the existing code
public static boolean isEmptyString( Object obj ) { if ( obj == null ) return (!isNotEmptyString(obj));
}
// Do we still need this function ? public static boolean checkForSpaces (String str) {
if (str.Equals (String(' ')) || str.Equals (String(' ')) || str.Equals (String(' ')) || str.Equals (String(' ')) || str.Equals (String(' ')) || str.Equals (String(' ')) || str.Equals (String(' ')) || str.Equals (String(' ')) || str.Equals (String(' '))) // That should be heaps enough to test for {
return true; } return false;
}
/* TODO
this program still crashes sometimes with a 'recursion error' .. like when obj is NOT a string.
So add additional helper functions for each type of object that we can think of, and make it return true or false, depending on whether it is sensible for that type of object to be an empty string or not.
eg: public static boolean isEmptyStringForIntegerType (Integer obj) { return true; }
I feel like I am really starting to pick up this whole computer programming thing - its not too hard once you grasp the basics. Once your programs start looking real complicated, and check every possible little thing, then you KNOW that you are on the right track :)
*/
Admin
The comments are much more wtf'ish than the code.
The poor guy just got true and false mixed up - done that plenty of times myself (without any further context, we can assume he wants a null or non-string object to be treated as an empty string). That both versions are logically identical (except for treating spaces as significant) is the original 'wtf', but somehow it's been blown rather out of proportion in the comments.
As an aside, If Java (and c-hash more-so) have such a large library of trivial functions that it takes forever to master them, i'm not sure it makes them better than simpler languages that do not.
Admin
Remember the days when TDWTF was not a competition to see who could come up with the best solution ?
We all know how to fix the issue......now we have little whipper snappers posting absolute crap up and actually think we want a solution from them.
Admin
mmmm, yeah.. no, .NET does not use typeOf. C# uses typeOf. .NET uses Object.GetType().
Admin
To the people recommending the use of String.IsNullOrEmpty be wary of the evil IsNullOrEmpty bug. If you use it in a loop it will throw a NullReferenceException for no reason:
What's real fun is that it will only throw the exception if it's in release mode and the IDE is NOT used to run the program. I let you imagine the fun of trying to find the cause of a mysterious crash that you can not replicate...
The kicker is that even though the bug has been known by microsoft since at least april 2006 it's still not fixed and won't be fixed until the next version of visual studio (aka orcas). Of course it will never be fixed in the current version and you'll have to pay for the new version to have the bug fixed.
see : http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=113102
Admin
In C++
Might be useful in meta-programming (templates) where you don't know what type you have.
Admin
Yanks eh?
Admin
In .NET you just do a simple:
return (value!="") & (value!=null);
Nothing more is required.
Admin
This WTF is BS. It is too absurd to be genuine. IMO the long story about consultants shows that the author knows full well what it takes to get a WTF put on the front page.
Admin
Remember the good old days when the internet was just a series of tubes?
kind of know what you mean though
Admin
The real WTF here is that there are 120 comments discussing this screwed-up validation method.
Admin
Now, I happen to be a C++ programmer by choice. There are good and bad things about the language. (I'm currently being forced to program in C as though it were C++, which certainly makes you appreciate the good things.) I've programmed in Perl, I've programmed in Python ... I'd even happily program in Java and C#.
Except.
I submit that all meaningful software is about choice. The problem I have with Java, C# and, for that matter, Visual Basic, is that someone has taken the choice away from you. Libraries do not a language make, nor should they be any more tightly coupled than, say, a linker. (I'd argue that there's a better case for the linker to be tightly coupled.)
It's purely a practical matter. Anyone who has tried socket programming in MFC would understand this ... at some stage, even a minimal library will get frustrating, or not do what you want it to do, or at least in a way that you can understand properly.
What you want is standards, and drop-in libraries. Curiously, Perl, with no standards to speak of, does quite well here. Java and C# suck at it -- and I'm not complaining about the language; I'm complaining about the environment. Several experienced developers on this site appear to agree with me. In my Hmbl Opn, someone fresh out of college doesn't stand a chance, unless they are in the top 10% of programmers -- which is precisely the 10% that these monolithic monstrosities are not supposed to reach, because "they do all the hard work for you."
No they don't.
</rant>Admin
Why don't you tell this the guy I replied to, you freak? I was not the one to bring up the discussion about integers, and you'd have noticed this if you were able to outsmart my doormat.
I was merely commenting on the idea that "".equals(x) needs special-casing if x is an Integer. If type constraints indeed prevent x from being an Integer, this does not invalidate my argument in any way.
Admin
You really don't think that this code could be used at all. WTF!!!
So you have never checked whether a required field (includes forms, configuration files,input files (for example testing whether a xml document is well formed), fields in a file and user/network input) was empty or skipped an empty line in a file (with a bit of string manipulation, you could also skip lines that contain only comments). WTF!!!. How did you get a job in programming (if you have a job, or even keep the job).
Admin
Not really, because I was talking of Java ;o)
But still the same holds true for both languages regarding interned string literals (or explicitely interned strings for that matter, though I'm not sure if you can do this in C#).
captch: ninjas ;o)
Admin
http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html#equals(java.lang.Object)
... unless you're additionally specifying that the method under scutiny should return true for Integer arguments, in which case, yes, it needs a special case. But you didn't say that.
I think you are a special case though, if that's any consolation.
Admin
Noooo! Reverse the order of the comparison. Always call the test function on the constant, so you don't randomly nullpointer on a bad input variable.
Admin
Far too many project managers. Far too much politics. Far too little actual development.
But, Brendie baby, should you ever want to escape from your current hell-hole of "it works, why change it?" may I suggest that you examine the previous 140-ish postings, which describe in painstaking detail why the first version of the code is an abortion, and the second version is akin to an abortion eating its own twin.
I'd love to spend more time having an erudite discussion with you on the subject of the original code, but, let's face it, you're a moron. And I have better things to do.
Like go back over the last twenty years:
Nah, validation ain't in my job description. I tried that with Fortran 77, and it was too difficult. Nowadays I just earn my crust ensuring that useless little farts like you get fired.
Much more satisfying.
And no: I really don't think this code could be used at all. I have no idea what the requirements/functional spec looked like, but it's hard to imagine this implementation being even vaguely adequate. And it's at such a low level (and conflicting with various bog-standard library calls) that it can only cause confusion, if not disaster.
A tiny bit of career advice, Brendan, from one who has been there:
Learn to unit test low-level functions.
That, or become a project manager.
Res ipsa loquitur.
Admin
per earlier...
I'm getting a strong sense that for you, "people skills" = "never making me feel bad" - if that's the case, don't ever expect to do anything critical... or even useful. It's not that you'll screw it up, necessarily; but that if you have, you'll neither believe it nor trust anyone to convince you of it - and that's dangerous, as this place illustrates all too regularly.
Not being unnecessarily cruel isn't the issue here; I'm all in favour of gentleness myself (I've been referred to as "the nicest person in the company" before, but I'm not sure that was a good thing) - but sometimes someone is just wrong, and it does nobody any good to pussyfoot around that.
gah... sorry about that.. What you say is very true. I've worked with people in the past who just couldn't seem to figure it out, period. Couldn't use the tools at their disposal to improve, to move forward.. But perhaps it was just a phase, how am I to know? But you are right, you have to make a decision when it affects the performance of the company in a negative way over a period of time where some reasonable measure of success should have been garunteed.
Pussyfooting can cost ALOT of money. :|
PS: sry to real_aardvark. Sometimes I just tend to think there are those out there who just jump to conclusions too quickly. The Daily WTF, atleast to me, seems like a telephone game at times. Most of it is hilarious, I enjoy it, don't get me wrong... But other times, it's "John Doe worked with John Smith and boy... he wrote some crap code!" and who really knows what happened for sure, the story is only being portrayed by John Doe, so I take it with a grain of salt.
Admin
Doh, like using quotes...
Admin
(Always assuming that you're the same person.)
I really should go back and apologise about linked lists, and not reading the post properly, and stuff ... but I just can't be bothered.
Blogs are ephemeral, you know? Just because I use strongly-worded and generally annoying language doesn't mean I'm really that way.
Now, all I have to do is to persuade the parole board of that...
Admin
Maybe you should read 'The Complicator's Gloves' : http://thedailywtf.com/Articles/The_Complicator's_Gloves.aspx
Admin
From the developers that need no introduction:
Admin
Girls, have fun, not boys
Admin
My cap kills my brain
Admin
wvsh ajgmnqeob cekotrwsb lrmxs kmgfzoiy bpyguatik kgoebi
Admin
want free sample of hydrocodone
Admin
want free sample of loratab
Admin
Holy Spammo batman! Validating Nothing!
Admin
God, look at all the spam! :o
Admin
if(obj != null && obj.toString().length() != 0) return true; return false;
Admin
well... what about this? isEmptyString boolean (String s){ return s.equals(""); }
one wants to test a String, doesn't one? so test for a String and not an object(which is an object, but... u know...). otherwise, the method has to have another name. or just use a wrapperClass to test everything that could be empty. but on the other hand, these tests are built-in-functions.
or use a list:
ArrayList<StringClassFromNoobDeveloper, Boolean> als = new ArrayList<String, Boolean>(); als.add("", true); als.add("i am horny", false); Iterator<StringClassFromNoobDeveloper, Boolean> its = als.iterator(); while(its.hasNext()){ System.out.println(its.next().getEmptynessOfCurrentString()) }
not that is wtf! i love you!
Admin
well... what about this? isEmptyString boolean (String s){ return s.equals(""); }
one wants to test a String, doesn't one? so test for a String and not an object(which is an object, but... u know...). otherwise, the method has to have another name. or just use a wrapperClass to test everything that could be empty. but on the other hand, these tests are built-in-functions.
or use a list:
ArrayList<StringClassFromNoobDeveloper, Boolean> als = new ArrayList<String, Boolean>(); als.add("", true); als.add("i am horny", false); Iterator<StringClassFromNoobDeveloper, Boolean> its = als.iterator(); while(its.hasNext()){ System.out.println(its.next().getEmptynessOfCurrentString()) }
not that is wtf! i love you!
Admin
Hello.
Admin
pharmacie en ligne france fiable https://kamagraenligne.shop/# п»їpharmacie en ligne france