- Feature Articles
-
CodeSOD
- Most Recent Articles
- What a More And
- Hall of Mirrors
- Magical Bytes
- Contact Us
- Plugin Acrobatics
- Recursive Search
- Objectified
- Secondary Waits
- 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
Have to agree with @tgape there. While premature optimization is the root of all evil, being an idiot is the root of all slow programs.
Noob's just code by accident. They get something working and carefully step away lest it break. Since they don't know what they are doing, their attempts at optimization are sure to fail and just make the code YAWTF.
Good programmers (hopefully) try to write decent code all of the time, and part of that is avoiding things that they know are slow or performance killers. It's not a premature optimization if you're not writing code you know to be bad.
If that was the case, @MET, would you punish everyone using a StringBuilder without a performance test to validate it was necessary?
Admin
auuugghh my eyes!
===: is php :(
php is the language:
if ($a===true) { ... } else if ($a===false={ ... } else { fileNotFound(); }
:((
Admin
never coded PHP, but a 5 second google search would have me believe that the naieve way of doing this properly would be:
$spider_footprint = array('googlebot', 'crawler',...); if(in_array(strtolower($agent)),$spider_footprint) { $is_spider = 1; }
Admin
I wonder what the worst case complexity on that comparison is, perhaps we should just check if its somewhat equal and assume statistical luck.
Admin
is there an image meme for when something goes completely over someone's head?typing "woosh" sometimes doesn't do it enough justice.
Admin
That's hardly the point. Your profession is Software Engineering. You always cover your ass.
Like it's been pointed out a hundred times in the comments already, stripos would do just fine. What's with this dropping the first character bullshit? An efficiency hack has a time and place, and this is not it.
Admin
I actually has this problem a while back when trying to do a substring matching...
End up using stristr() instead.
Admin
===== is so equal that it overflows into testing inequality! So to prevent against such overflows, you should use a YesNoFactory.
Admin
Admin
Great, a function returning Unsigned Int, except when it returns Signed Int.
The real WTF is that people still think in-band signalling is appropriate 40 years after Captain Crunch.
Admin
Admin
===== : is irrigation system
Admin
No, you won't. Either way, substr_count() is actually designed for the job unlike either of those two.
Admin
Actually, it makes sense to distinguish between different kinds of equality. For example, Common Lisp has numerous equality operators. To name just a few (with rough semantics in parentheses): eq (is the same object as), eql (has the same value as), equalp (has the same value or contains the same values as), string= (case-sensitive string comparison), string-equal (case-insensitive string comparison).
Admin
does ==== == === ?
or ==== === === ?
Admin
This is also a nice way to not having to check for upper or lower case...
Admin
What about open-licensed code e.g. a BSD license? I know YUI is licensed under BSD but has named their global, Javascript object 'YAHOO.'
Admin
I have to admit I can't come up with a rational for using negative lengths off the top of my head, but I suppose you could make a similar claim for readability.
Admin
Said the lead COBOL programmer who decided that there was no way COBOL code would last long, and therefore two digit years were a good way to save space.
Admin
It's nice to write a post that generates so much traffic though ;)
Admin
You are wrong!
Here some examples: Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp) Yandex/2.01.000 (compatible; Win16; Dyatel; Z)
Do you think Yahoo have ill-behaved spider?
Admin
Brilliant! Persoanlly, I always kinda liked Spiders! LOL
RD www.FireMe.To/udi
Admin
Wow, I'm surprised how many negative responses I got to that post.
Let me see if I can sum up the criticism:
The scenario: We are checking a string that comes from an external source and which has no specific formatting rules. We want to identify strings that represent a certain attribute, i.e. robot vs browser, that is not explicitly identified by any rigorous attribute of the string. We decide to search for some likely substrings within that string in the hopes of making this identification reasonably reliably. So for example, we want to catch "Spider" and "spider".
Excellent, praise-worthy solution: Look for a match against the 6 characters "spider" using a case-insensitive compare.
Ignorant, stupid, worthless solution: Look for the 5 characters "pider" with a case-sensitive compare.
The reasoning here is apparently that the second solution might fail because someone might someday create a browser named "Tpider" which would then incorrectly look like a robot, while the first solution would handle this correctly. But of course it is absolutely impossible that anyone would ever create a browser called "InSPIderation", which would generate incorrect results on the first solution but correct results on the second solution.
When testing against external data that is not formulated according to a well-defined spec, any solution is inherently unreliable. The best you can do is look at examples of real data and come up with something that works with all the cases you are able to identify.
I'm not saying I would have used the "pider" solution, but it is not objectively worse than any other solution I have seen proposed.
Admin
TRWTF is the people who thinks this "clearly" works. Granted I don't have the spec, perhaps they want want to find things that match Tpider...
Admin
Stop the bus.
This is PHP we are talking about.
Surely there is a SpiderDetectionAndCoffeeBeanOptimization module, and he could just import that and use the currentUserAgentIsASpider() function.
I mean, really!
Admin
This code will catch other spiders too, which may or may not be desirable.
Admin
I don't really see a WTF here. Sure, in the unlikely event that "Foogle" comes out, someone will have to rewrite the code...Which shouldn't prove to be hard at all. No one here had trouble seeing what this guy was doing, right?
It wasn't the best way to do it, but it's a minor mistake at worst.
Admin
is it wrong that I misread the array name as $pider_footprint even before I read the rest of the article?
Admin
Ain't that smart! But it's wrong!
Using StringBuilder explicitly results in awfully cumbersome code, and string concatenation compiles into StringBuilder anyway.
So, according to the quoted posts, anyone using StringBuilder is a n00b
Admin
Ooops, forgot to quote.
Admin
Pbbly, the original codewriter just didn't know whether to capitalize or not the first legtter of each probable spider...
Nevertheless, the word
pider
in Russian means someone sexually incomprehent and having unordinary sexual oriantation (in the bad meaning of this sentence, of course)...So, who knows what David meant under
pider search
-gay search or smth else
...Admin
He is probably thinking "I don't know if it's Google or 'google', better safe than sorry"
Admin
===== : Case-sensitive version of ====
Admin
Is === equivilent to:
if(value==otherValue&&value==otherValue){}
Or
while(true) { if(value==otherValue) { //do stuff break; } else { value=otherValue; } }
I'd like to know before I start incorporating it into my source.
Admin
cider?
ps: new fav captcha of all time: transverbero !
Admin
Pharmacie sans ordonnance http://kamagraenligne.com/# pharmacie en ligne pas cher