- 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
So true. PHP took all the worst parts of Perl, C and more recently Java, blended them together and called it a "language"
(I'm allowed to say that because I write PHP for a living)
Admin
That's a Perlism and it really does make sense: interpolating can be slower, if you know you aren't going to be interpolating a variable it gives you a bit of a performance boost and the added security to know someone can't externally muck with your string. It's also convenient if you need literal $ signs in your string (and in perl more so since it uses other symbols like @ and % for arrays and hashes)
Admin
I would hate for anyone to have too look at my current code, much less the code I wrote in the period during or immediately after learning a new language.
Admin
So how are you at working in a team? In order to work effectively, you have to be able to let your peers review your current code.
Admin
Teams are so gay. Peer reviews even gayer.
Admin
With an attitude like that, I really wish you would put some of your code up on here. I'm sure we'd all enjoy it
Admin
You are so gay.
Admin
PHP == VB ??
Admin
WTF?!?!?
I suppose we should be grateful it's not "Rear Admirer, Left Half"...
Admin
Overall, it brings back so many memories of When the Web Web was Young. Mostly bad ones. My eyes hurt whether I look at the source or the rendered page. (Animated backgrounds? That are mostly the same color as the text? Webrings? A "best viewed in" blurb? Oh my!) If it hadn't been deliberate, it would have been perfect. As it is, it's slightly too clever. Scary too. It really was that bad. Still is in some parts of the 'net.
(Randall, if you're reading this... the blink tricks didn't work on Safari. More javascript was needed. I suppose that would have fitted in just perfectly with the rest of that monstrous masterpiece...)
Admin
Former statement's correct, latter is not. The dot in the middle is part of the string.
Nevertheless, this is bad coding practice, as a) it is unreadable, and b) the array key is parsed as a constant. If someone created a constant named "hostname", the code would most likely fail.
Finally, who the fuck names a variable $ainstall and all in lowercase?
Admin
Shouldn't that be:
In the proposed code, $type is clearly being set, but it may or may not be empty().
Admin
Admin
And to everybody who still didn't get the "$var[name]" problem:
It's a special case for the parser. PHP does NOT see a constant called "name" here.
PHP interprets one dimension of array keys in strings with no quotes. Two or more need to be put in curlies {} and quoted as usual.
I'd post a link to the manual, but apparently that makes me a spammer. Look for "string parsing" on php.net yourself.
Admin
I spent more than five years in teaching and developing using PHP and MYSQL. And I feel that I have a right to say that the most thing I hate in that domain is spending most of the time in discussing the code it self rather than what the code could do.
Admin
If you're only going to use the variables once, I agree... though I think in some cases it can improve code readability. This is especially true when either you use the same datum more than once or the array lookup is deep. In the former case, it saves you trying to figure out if two long array dereference sequences are actually identical or just similar.
Of course, since it's essentially a form of code self-documentation, it's subject to the usual worries about keeping documentation in sync with the actual code...
Admin
Admin
You could, you know, check. The point is though, that the original version does this:
What I'm proposing is:
No chances of throwing an error and no unused code branches. The original is simply nonsense. If you're paranoid about mistyping the $ainstall variable, do this:
Admin
Okay, sorry, scratch that part. !isset($type) is true if $type === null. What still holds true is that you'll get a warning for a missing array key in step one. So instead of getting a warning and dealing with it later I'm proposing a warning-less way, which should always be preferred.
Admin
So the WTF is what, that instead of hiring a trained programmer to develop the tool, they had some untrained guy who had simply read a "Learn ${Some_Language} in 21 Days" book do it? I'm curious what these managers think we are doing in the 4 years we spend getting a degree in college if they think programming can be learned in 21 days...
I wonder if I bought a "Learn People Management in 21 Days" book, would upper management would let me become a vice president of something?
Admin
Funny that you mention it. How come we never see WTFs written in real programming languages??? Always in Personal Home Page or visual "look look, I made a window with a textbox" basic!
Admin
He was not a dumbass. This was a clever solution from someone who has obviously no programming experience whatsoever.
The real WTF is not the programmer fucking up, but management allowing such a system to grow over the years without ANY feedback from real developers.
Programming is hard; allowing someone who is not a programmer to build a large and obviously important application is asking for trouble. Nobody does these things right the first time without some guidance.
Admin
Come one, we all know a computer guy is a computer guy. There's no real difference between a programmer, a dba and the guy who changes your keyboard when it's broken...
Admin
So the guy had an idea about automating the most dumbass tasks and have them online. He hacks a website that does exactly that. Then mister smartass shows up, takes a look at the code and sends it to thedailywtf. "OMG! Look, he stupid! He shouldn't be doing php!" But that's not all. Mr smartass shows how it should be done! Only he doesn't realize his code sucks too.
Now that's a wtf.
Admin
On some whim, I've always avoided PHP. Looking at all the code on this issue, I can see why. TRWTF really is the language, this time. The code from the "experienced" guy look almost as bad as the code from the newbie. Laughing at code from a newbie is really not cool.
CONSEQUAT: There will be
Admin
I see these kinds of examples posted a lot in discussions regarding php, and Ive never really understood why.
who cares? perfect logical inconsistency is a ridiculous goal in any language, and the advantages of php hugely outweigh the occasional linguistic oddity that no decent programmer ever has a problem with anyway because they just dont write code that looks like:
if($var['name']['name2'] != "$var[name][name2]")
its is inane to pretend that the existence of such linguistic oddities are sufficient in themselves to render a language good or bad.
Admin
Admin
Hello, I'm Stuart. I'd like to clarify some things:
Jim had a great idea, and his website is still in use today - now that it's cleaned up, we can trust the data in it, the pages load within a minute, and it's available for more than a couple of hours a day. It saves all the sysadmins huge amounts of time.
We have other websites developed by sysadmins who still have their jobs. The difference is they knew when to let go - they handed over their babies to the development team for ongoing maintenance and they got back to being good sysadmins rather than poor programmers.
Jim had several years to learn proper development practices, but he believed his tinkering was good enough programming. Nobody cared to look under the hook and challenge him about it, so he didn't bother learning any more. Nobody worried about this until things started coming unstuck. The code you see here is not a beginner's first attempts, it's from someone "with several years development experience".
Much of Jim's code is what you'd expect from a non-programmer, which is not a WTF in itself, but this snippet is such a complicated and convoluted way of doing a task that I couldn't work out why he'd ever choose to do it that way.
The example code is just there to show what Jim's code is trying to do, but in a concise fashion, so you can see what $aservers, $ainstall and $avalues mean. The code in production does a COUNT at the database instead. I apologise for the isset() rather than array_key_exists(), it's a Perlism taken over to PHP.
Admin
Well, most modern editors have functions like copy-paste.
It clearly could be better to do it once, but as Andy said, this code throws a warning. To be exact:
if the index does not exists. Ofc, maybe it always exists, and this discussion is pointless. But in most cases like this one, it MAY not exist.
Then, you can say that the notice error is not an error as-is and we can deal with it. In many cases you're right, but in a case of debugging and looking through logs the avalanche of notices can be overwhelming. And sometimes there's no good way of debug. I'm currently working with heavily AJAXed and framed spaghetti code, the only place I can use to debug are sometimes logs. Two pages of notices for one request can be a little bit disappointing, not to say it's hard to find something useful in there.
Admin
Admin
LOL @ xkcd!
Admin
That sentence is gibberish. Luckily, you are familiar with the context of the sentence so you are able to understand it and your brain doesn't see the error. The part your brain is unjumbling is easier to see as broken when it's outside the context of the sentence:
"transitioning the application the development team so"
Also, it has a nasty comma splice.
What the author meant to write:
Admin
I just read "Learn Open Heart Surgery in 21 Days". (I skipped a couple of chapters because all that stuff about blood was too gross.) Now I'm going to apply for a job as a surgeon.
Admin
In my current job I work in a development group for a large organization with many offices that often have amateur applications crop up in that we take over and fix when it becomes apparent they are useful on a larger scale.
If you were able to refactor this application and make it work, then it was a damn fine amateur effort and certainly not a WTF.
If I could share some of the code from the applications I've taken over (and had to rewrite from the step of requirements gathering), THEN you would know the true meaning of WTF.
Admin
Or better yet ... I think I'm going to call the publisher of these "Learn ... in 21 Days" books and tell them that I just read "Learn How to Write 'Learn in 21 Days' Books in 21 Days" and ask them if they'll give me a book contract with a big advance.
Admin
Admin
Admin
http://www.ietf.org/rfc/rfc1760.txt
The S/KEY system is designed to facilitate this manual entry without impeding automatic methods. The one-time password is therefore converted to, and accepted as, a sequence of six short (1 to 4 letter) English words. Each word is chosen from a dictionary of 2048 words;
Dictionary for Converting Between S/KEY 6-Word and Binary Formats
{ "A", "ABE", "ACE", ....."YELL", "YOGA", "YOKE" };
Admin
Ooops - I put my comment in the wrong thread.
Admin
That's why you have tests on application (like, unit tests and so). You have them, right? Ok, jokes over. You have in perfect world, but... If you want 'editor-safer' approach you can do it like that
Ah, 50% Opacity already wrote this
(in fact I write like that in more complex keys I have to use more than once)or, if you preffer dirty approach
But the overall approach should always be - FIRST test if something exists, THEN use it. It's better practice, other languages aren't as permissive as PHP.Admin
My word, the parallels of "PHP has an eval function like perl" here is unprecidented since we are needing to recode a number of 'systems' that had evolved just like this example. The fact that the guy who did it to us is also called Jim is spooky at best. Is it possible to discriminate against network admins that are named Jim?
Admin
I keep reading posts about sysadmins who don't know how to program. This puzzles me, given all the programming courses I'm taking in order to qualify as a sysadmin.
Admin
Admin
Arcane parsing rules are TRWFT.
Admin
Are you being serious? It gets interpolated, not eval'ed. Big difference.
Admin
There is a massive difference between copying the syntax from a book and learning a language.
But yeah, you can write bad code in any language if you try hard enough, try this beauty from the our application that I found just now in our mature, widely used java app (This is not a unique example).
StringBuffer sqlStmtStr = new StringBuffer(); .... sqlStmtStr .append("AND f.name = " + nameStr + " " ); ....
ahhh, what a day I have infront of me.
Admin
Admin
Admin