- 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
Huh? Just because something makes you say WTF, don't refactor it to something semantically different. || would not be "more accurate" than !=, or less accurate. It would be completely different. The code above tests for "if they gave one name, they have to give both", whereas || would test for "they always have to search by name; it's against the rules to search by customer number (or something)".
I'll bet that the app this comes from has a search form where you can search by various criteria, and it's perfectly legal not to specify name AT ALL and just search by some other criterion, such as date or order number or what have you, but if you do give either a first or a last name, then you MUST give both.
I'd change the error message, though, to something that made that more clear, such as "Both First and Last Name are required when searching by name." (And then put soundex columns in the database so that Tie Wrecks would match Ty Rex.)
Good point about spaces. Change x == "" to isBlank(x) and keep the definition of that separate.
Admin
But have you considered that, on a superpipelined RISC machine, using register windows to pass parameters, if the code fits in the instruction cache, then YOU ARE OPTIMIZING USER INPUT VALIDATION! And arguing about optimization with no timing numbers anywhere in sight, and even if there were any it would be a microbenchmark, and what possible difference can it make if it takes one or two milliseconds to validate user input?
All your unpredicted branches and cache flushes and pipeline stalls are saying is "I'm a bigger geek than you", "No, I'm a bigger geek." Code bums! That's what you are! Code bums!
Admin
Nope. It's just that you don't understand the other person's English. Or, perhaps you really have some funky English. C'mon what does "You must both first name and last name or neither." mean?
Admin
That is what 'either...or' is for.
Admin
Doesn't anyone here actually test the snippets?
EXACTLY as described here (XOR)...