- 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
[quote user="frits"]Me. I don't even understand what the coder is trying to do. Usually, the WTF has some kind of twisted logic, and I normally mentally translate unfamiliar code into one the coding languages I'm at least semi-familiar with, but this just doesn't make sense.
So: global $EmailAddress (etc) produces a preassigned global variable? Which is then assigned to another global $email variable, which if false (or null?) results in another preassigned global variable, and so on? What's the point?[/quote] If you can't figure this out, than your a moron. The email needs to get set from an ordered priority of places. The only thing is that they happen to be named similarly (except for case). Obviously, you could change the variable names elsewhere to this and it would be readible.
[/quote]So if "your" not familiar with PHP "your" a moron? Moron.
So global gives you local access to a global variable? Thanks Andrew (unregistered). Yes, it makes it clearer that the real WTF is allowing the users of the code to define the API. ("No, the email address goes into $Email. It won't work if you use something else. I don't care if you prefer $EmailAddress.)
Admin
Lookie. Someone's butthurt. Trying to make your very own meme?
Addendum (2010-11-03 10:43): For referenece:
http://thedailywtf.com/Comments/Sponsor-Appreciation,-Open-Source-Child-Care,-and-More.aspx#327230
Then this:
http://thedailywtf.com/Comments/Meet-Rod.aspx?pg=3#327672
Which is pretty funny, actually.
And now the quoted text. You sir, ma'am, it, are a loser. Find someone else to emulate.
Admin
function set_var($regex, $value) { foreach(preg_grep($regex, array_keys(get_defined_vars())) as $field) $$field=$value; }
function get_var($regex) { return array_intersect_key($x=get_defined_vars(), array_fill_keys(preg_grep($regex, array_keys($x)), ")); // TODO: Probably best to randomly grab one value }
Admin
What probably happened: -A has been writing PHP that uses an email address stored in the global variable $email. -B is assigned to work on a different part of the same project. Since his code doesn't interact with A's, he doesn't bother to look up what A did, and so independently decides he needs to store the email address in a global called $email_address. -C is working on another part of the code that used to match B's, but then he decides to change it to a more CamelCasey $EmailAddress. His code doesn't actually interact with B's, so nothing breaks. ... -H has to write or modify a function that is called by A, B, C, D, E, F, and G's code, and every single one of those puts the email address somewhere slightly different. Rather than search through the whole project for every place one of these is used to try to make them consistent, he says "screw it" and has his function just try every permutation he knows about until it finds one that works.
Admin
Admin
Here is an alternate explanation: In php variables submittet with a forms may be put directly into global scope* so this code may handle multiple different forms where the email field have been named different.
*Yes, that is a wtf. And a security nightmare when combined with the "Just use variables without declaring them, just assume they are empty if you have not used them yet.
Admin
Admin
TRWTF are globals. And procedural programming. And functional programming. And aspect oriented programming. And whatever other techniques I don't use.
Admin
TRWTF is where ignorance and arrogance converge.
Admin
That was quick. Nice catch, frits.
Admin
This should be a featured comment
Admin
The directive register_globals is deprecated and disabled by default in PHP5. In order to avoid this security nightmare, my form input elements have a different name than the variables I use in PHP. Also, all input should go through sanity checks before use.
Admin
One great thing about delphi is that names aren't case sensitive so you never run into problems like that. It actually saves a lot of time looking up variables in long functions/programs.
Also, what languages let you put a dash in a variable name? Won't that just subtract the second half?
Admin
Personally I have no problem with case-sensitive variable names and I actually shudder a little imagining a language without them. The plain fact of the matter is that 'a' and 'A' are completely different characters as far as the computer is concerned - different char code, different character. Given this fact, it is obvious that uppercase and lowercase versions of the same word are different - they are not the same string, so why should the computer (or I) consider them to be the same? I'm happy with "what you see is what you get" - I don't want the compiler trying to be clever on my behalf by pretending that upper and lower cases are the same, because they patently aren't.
Admin
Lisp. No.
Admin
ATLAS, for one. Mathmatical operations need a 'CALCULATE' statement
Admin
Admin
(defn my-var 3) (- 10 my-var)
Admin
Admin
Admin
WTF? PHP has no such option. The most you can do is emit an E_NOTICE for undeclared variables. I'd hardly call that "an option for explicit variables".
Admin
PHP? No they don't.
Admin
Admin
Admin
Admin
To, there are half a dozen or so PHP apps that all do some common thing with an email address, and someone decided to make them all point to the same include file and get that to do it. This would make sense if it was a lot of code that you just don't want repeating everywhere and have to dig around to update all of them when you make a change to just one. The problem, it would seem, is that they all named their email variables differently, and this tree simply grabs the first one it finds and puts it in the one it's going to use.
It's entirely possible that this is a precursor to some serious refactoring that has subsequently been completed, making this code no longer needed.
You can't blame PHP for this. Someone went to great lengths using Reflection to achieve a similar goal in a C# project I'm working on.
Admin
You shouldn't be forced to use the IDE, and rely on it to fix your casing. Besides, not all code originates in an IDE. For example, you might have a script that generates code.
On a personal note, since I've been a C/C++/C# programmer for so long, I'm just used to having case matter. It just seems more natural.
Admin
Admin
Admin
I'm amazed that, when presented with some PHP code, Alex didn't go for the old "variable variables" canard. (And ironically, a variable variable makes for an easier way to solve this particular problem.)
Admin
Admin
Doesn't work on lexicals though.
Admin
The fact that you aborted a perfect opportunity to use the word "quaternary" makes me sad...
Admin
Doesn't work on lexicals, though.
Admin
Seriously, who hasn't tried to do something like this?
Admin
Unfortunately TerminalSalt and TerminalsAlt /are/ different variables.
Admin
Admin
This is a WTF in itself, since this code will only work for C# and possibly J# (which is out of use) or managed C++. Why, you ask? Because it's not CLS compliant. VB requires case insensitivity, so "myInt" and "MyInt" are equivalent. The CLR will attempt to guess at the correct one to use by the access modifier (if one is private and one is public, obviously, the public one should be used), but there are times when that can fail (if they're both visible).
I too hate starting member variables with an underscore, so I end them with one instead. Example:
Admin
It isn't and you don't.
Admin
if ($comment) { $comment = first; if ($comment) { $comment = First; if ($comment) { $comment = fIrst; if ($comment) { $comment = fiRst; if ($comment) { $comment = firSt; if ($comment) { $comment = firsT; } } } } }
CAPTCHA: enim: the letters before ohpe.
Admin
hand up
And I've done a lot of PHP-work over the last years (I will even admit a certain fondness for it)! I've seen bad, but this is ridiculous.
CAPTCHA: eros (not that kind of fondness!)
Admin
This. And whoever said case sensitivity compiles faster has clearly never tried to compile 100K lines of C vs 100K lines of Delphi. ;) Case insensitive comparison may take some extra cycles, but it doesn't noticeably slow down compilation, at least in Delphi, because the compiler is fast enough that the limiting factor is disc access, not the actual compilation.
Case sensitivity was allowed on C, like so many of its other misfeatures, simply because it's easier to implement. Case sensitivity makes for simpler string comparisons and you don't have to store both original and allcaps versions of all the identifiers in your symbol table for proper error/warning reporting. And it remains in other languages mostly because of cargo-cult language design. (That's the way it is in C, so it must be good, right?)
Admin
Admin
Perhaps it'd run slightly more slowly, but dear god I hate it when developers create these godawful 100-deep nested if statement trees. Some of our code at work looks like this, about two dozen nested if statements.
A few of the blocks have code after the closing braces, and it's impossible to work out which if block it executes after when the opening statement is a hundred lines away and not necessarily at the same indentation.
So yeah, is the following really so bad?
Admin
Ahh....so we can all agree that TRWTF are the Turks.
Admin
So, what you're saying is.....TRWTF is VB!
Admin
Case-insensitivity is too much work for a PDP-11.
Admin
The trouble with this post is I can't tell whether the guy is serious, in which case it's hilarious, or whether he's trying to make a joke, in which case it's not.
Admin
Admin
Fixed?