- 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
$Frist = "Frist" If (isset($Frist)) { if (frist == "") { $Frist = "Frist" } }
Admin
My guess would be, that the commented-out ones are the ones that are actually used. :p
Admin
TRWTF is rules given without supporting context.
Admin
And then they check a post variable without confirming that it's set...
Something really nice about PHP in this regard, however, is that you can write if(isset($var) && $var=='x')); without any issues. Or even write a function that you can pass in the variable name and (using variable variables!) have it return null if it doesn't exist.
Admin
Cargo-cult programming in PHP? I am shocked! Shocked to my core!
Admin
Submitted from...
Submitted from where? Don't leave us hanging! I have to know where it was submitted from!
Anxiously awaiting your reply, Mike5
Admin
Nonono, this is perfectly fine code! This guy is just making his code multi-thread safe! Because then the scheduler might interfere exactly in between the first set command, schedule a different thread, which then unsets the variable again, and as soon as the first thread is scheduled again, it of course cannot rely on the variable still being set. So he needs to check that again. You see, this is totally great code!
Except...he should really add another check after the first check, because the scheduler could interrupt him right AFTER the check, but before the actual use. And then another check after this check. And another. And another. And another. And another.
Phew. So that's why they all say that multi-threading is damn hard!
Admin
This is not at all junk code.
It guarantees that the variables are 0, even if they arrived as an empty string. Otherwise the empty string could carry forward into a numeric calculation, or a DB Update to a numeric column, and crash. PHP will likely handle the numeric issue with its datatype-less methodology (turning "" into 0) but I don't have the time to try and prove something I never do. DB updates (and it SURE looks like that's where these guys are headed) WILL crash for example if they issue an:
"Update tblMonthlyXXX SET colDIDSthisMonth = , WHERE whatever=whatever"
Admin
"See if you can guess each ones!"
It's becoming more and more obvious that the apparent horrendous spelling and absolute lack of editing in these posts is actually just an attempt to drive additional comments to make the blog look popular.
Admin
Erm, that's not really how it works. If you have an assignment line setting a variable to 0, it will be 0. No empty string values are going to "carry forward" from somewhere else...
Admin
Admin
So is this the first Monday of the month, so I can declare a fizzbin?
Admin
Forget all that logic crud... best Spock line Nimoy ever delivered:
"I would advise youse to keep dialin', Oxmyx."
Admin
Actually, Leonard Nimoy was in an episode of The Untouchables in 1962. Maybe the line wasn't hard to deliver!
Admin
Interesting that Bela's last name was clearly "Okmyx"; it was even written out on the wall, but everyone calls him "Oxmyx". Not one of the better writing efforts in TOS.
Admin
There were better writing efforts in TOS?
Admin
I think TRWTF is Appalled again.
Admin
OK, I freaking read it backward. I thought it said IF (!(isset(whatever))) ................... I'm too old for this. I can code it but I can't read it unless it's my own.
Admin
Actually the first two years of TOS are generally considered well written. After the second season the network was going to cancel it but fan letters and petitions convinced them to reverse course. However it brought new oversight and forced a sequence of truly awful 'kirk goes to planet - beautiful woman falls in love with Kirk - aliens attack - kirk defeat aliens but woman is lost to him' shows that sealed the fate of TOS. After that season not many wanted to do another letter writing campaign.
Admin
My favorite was in an excel spreadsheet which had a formula not working as desired. After some time puzzling over it, I come back and say "so, the number in this cell represents the number of hours worked in a day, right?" to which the reply was, "I don't know, the last guy that did it just told me to put an 8 there, so I did."
Admin
Man, for some reason I really want to buy some fancy watches so I can look stylish while I write my next essay.
Admin
I rest my case.
Admin
Turns out an easier way to guarantee that the variables are 0 is to just set them to 0. That tends to work.
Admin
Did this developer need to meet a quota for LOC per day or something?
Admin
You are an absolute idiot who misses any sense of humour which makes this site look bad.
Admin
I think you are so wrong! That's impossible
Admin
TRWTF here is that the coder forgot the else branch - in case the variable wasn't set to an empty string, but the set op failed altogether.
And to be really sure they ought to have used a loop ending in
until (isset(varname) && (varname==<desiredValue>))