• Me (unregistered) in reply to frits

    [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.

    if (!$email){
        global $primaryEmail; 
        $email=$primaryEmail; 
        if (!$email){ 
            global $secondaryEmail; 
            $email=$secondaryEmail;
            if (!$email){
                global $tertiaryEmail; 
                $email=$tertiaryEmail; 
                if (!$email){ 
                    global $email4; 
                    $email = $email4;
                    if (!$email){ 
                        global $email5; 
                        $email = $email5; 
                        if (!$email){ 
                            global $email6; 
                            $email = $email6; 
                        }
                    }
                }
            }
        }
    }
    
    [/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.)

  • (cs) in reply to frits
    frits(unregistered):
    This is literally the lamest WTF that has ever been posted.

    Seriously, who hasn't had to do something like this?

    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.

  • Bob (unregistered) in reply to no name
    no name:
    Kempeth:
    Now if we could only specify the variable name in RegEx that would solve our problems...

    That would be an awesome language feature - just imagine the potential for abuse...

    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 }

  • drusi (unregistered) in reply to Me
    Me:
    frits:
    This is literally the lamest WTF that has ever been posted.

    Seriously, who hasn't had to do something like this?

    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.

    I haven't, either, but it's very easy to understand for those of us who have ever collaborated on a project with someone who had a drastically different coding style and insisted on sticking to it in contradiction of already-written code. (I have a story about this that I may submit someday, which I mentally refer to as The Great mysql_close() War.)

    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.

  • Max (unregistered) in reply to Andy
    Andy:
    Bill's Kid:
    [There | there | THERE] [is | Is |IS] [SomeThing | Something | someThing | SOMETHING] [To | to | TO ] [Be | be | BE] [Said | said | SAID] [For | for] [Case | case | CASE] [Insensitivity | insensitivity | INSENSITIVITY]

    I think we should introduce word length / abbreviation insensitivity too, just in case people want to use $emailaddr...

    This 'feature' exists in Fortran 77. Variable names (case insensitive) are capped at 6 characters long. Any extra characters are just ignored by the compiler (as is whitespace). The result is that "Emailaddress", "email ADDRESS", and "EmAiLa" are all the same variable. Further, if you have a variable "TEMPERED" and a variable "TEMPERATURE", they will actually be the same variable "TEMPER". This is entirely fun and not at all frustrating to deal with.

  • An alternate explanation (unregistered)

    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.

  • Personal Home Page (unregistered) in reply to Schmalls
    Schmalls:
    Just so everyone knows, if this is PHP, which it looks like it is, there is no case sensitivity. So $Email and $email are the same variable, etc.
    Just so you know, you might want to actually test that assertion before sharing it so confidently. Keywords and function names are case insensitive, variables are not.
  • (cs)

    TRWTF are globals. And procedural programming. And functional programming. And aspect oriented programming. And whatever other techniques I don't use.

  • (cs) in reply to frits
    frits:
    TRWTF are globals. And procedural programming. And functional programming. And aspect oriented programming. And whatever other techniques I don't use.

    TRWTF is where ignorance and arrogance converge.

  • wtf (unregistered) in reply to hoodaticus
    hoodaticus:
    frits:
    TRWTF are globals. And procedural programming. And functional programming. And aspect oriented programming. And whatever other techniques I don't use.

    TRWTF is where ignorance and arrogance converge.

    That was quick. Nice catch, frits.

  • (cs) in reply to jonsjava
    jonsjava:
    if (!$comment){ //nobody has posted yet. Just to make sure, we'll check for posts as Comment, instead global $Comment; if (!$Comment){ //where did everybody go? global $posts; if (!$posts){ //I'm getting lonely global $lonely; //I didn't even like them anyways. global $drink; //I'm glad they are gone global $drink_more; // Hey, a lamp shade... global $drink_even_more; // Sosifre, I'm not as think as you drunk I am global $pass_ou

    This should be a featured comment

  • North Shore Beach Bum (unregistered) in reply to An alternate explanation
    An alternate explanation:
    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.

    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.

  • Ksevio (unregistered)

    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?

  • Anonymous (unregistered)

    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.

  • SomeAnonCoward (unregistered) in reply to Ksevio

    Lisp. No.

  • (cs) in reply to Ksevio
    Ksevio:
    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?

    ATLAS, for one. Mathmatical operations need a 'CALCULATE' statement

  • Patrick (unregistered) in reply to Geocities?
    Geocities?:
    Personal Home Page. That is all.
    You DO know that PHP has an option for explicit variables, right? Good coders use it.
  • SomeAnonCoward (unregistered) in reply to Ksevio
    Ksevio:
    Also, what languages let you put a dash in a variable name? Won't that just subtract the second half?
    Lisp for example. No it won't because it's based on s-expressions so it uses prefix notation:

    (defn my-var 3) (- 10 my-var)

  • SomeAnonCoward (unregistered) in reply to SomeAnonCoward
    SomeAnonCoward:
    (def my-var 3) (- 10 my-var)
    oops should be def instead of defn. please have mercy.
  • (cs) in reply to X
    X:
    Here is an argument. It forces the programmer to use the same capitalizations whenever a name is used. Thus information that may be conveyed through case, such as what kind of thing the name represents (whether it be a variable, function, macro, or template parameter), or the starts of words when using camel case, will be visible wherever that name appears.
    All of those things also apply to languages where case is preserved and the IDE does case-normalization. Great argument for a good IDE, bad argument for case sensitivity.
  • SomeAnonCoward (unregistered) in reply to Patrick
    Patrick:
    Geocities?:
    Personal Home Page. That is all.
    You DO know that PHP has an option for explicit variables, right? Good coders use it.

    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".

  • wtf (unregistered) in reply to Patrick
    Patrick:
    Geocities?:
    Personal Home Page. That is all.
    You DO know that PHP has an option for explicit variables, right? Good coders use it.

    PHP? No they don't.

  • Anonymous (unregistered) in reply to Larry
    Larry:
    Geocities?:
    Personal Home Page. That is all.
    Hypertext Preprocessor. That is all.
    TRWTF is renaming a language for the sole purpose of making it sound more legitimate and less like a hobbyist's toy. And renaming it to something that doesn't even match the acronym is exactly the sort of intelligent move I'd expect from the author of such an unholy mess.
  • kaalikas (unregistered) in reply to Lars
    Lars:
    Case sensitive is good. It's kind of annoying when Initialize and initialize is the same name for everyone except people in Turkey.
    this.
  • A Moron (unregistered) in reply to kaalikas
    kaalikas:
    Lars:
    Case sensitive is good. It's kind of annoying when Initialize and initialize is the same name for everyone except people in Turkey.
    this.
    Help a moron out by explaining this please.
  • Patrick (unregistered)

    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.

  • (cs) in reply to Jaime
    Jaime:
    X:
    Here is an argument. It forces the programmer to use the same capitalizations whenever a name is used. Thus information that may be conveyed through case, such as what kind of thing the name represents (whether it be a variable, function, macro, or template parameter), or the starts of words when using camel case, will be visible wherever that name appears.
    All of those things also apply to languages where case is preserved and the IDE does case-normalization. Great argument for a good IDE, bad argument for case sensitivity.

    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.

  • (cs) in reply to A Moron
    A Moron:
    kaalikas:
    Lars:
    Case sensitive is good. It's kind of annoying when Initialize and initialize is the same name for everyone except people in Turkey.
    this.
    Help a moron out by explaining this please.
    http://en.wikipedia.org/wiki/Dotted_and_dotless_I
  • Patrick (unregistered) in reply to Jaime
    Jaime:
    X:
    Here is an argument. It forces the programmer to use the same capitalizations whenever a name is used. Thus information that may be conveyed through case, such as what kind of thing the name represents (whether it be a variable, function, macro, or template parameter), or the starts of words when using camel case, will be visible wherever that name appears.
    All of those things also apply to languages where case is preserved and the IDE does case-normalization. Great argument for a good IDE, bad argument for case sensitivity.
    Case is the difference between EmployeeReSigned and EmployeeResigned. Caseless would require underscores.
  • (cs)

    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.)

  • A Moron (unregistered) in reply to JamesQMurphy
    JamesQMurphy:
    A Moron:
    kaalikas:
    Lars:
    Case sensitive is good. It's kind of annoying when Initialize and initialize is the same name for everyone except people in Turkey.
    this.
    Help a moron out by explaining this please.
    http://en.wikipedia.org/wiki/Dotted_and_dotless_I
    Brilliant, thank you.
  • (cs) in reply to Rick

    Doesn't work on lexicals though.

  • MZ (unregistered) in reply to frits

    The fact that you aborted a perfect opportunity to use the word "quaternary" makes me sad...

  • (cs) in reply to Rick
    Rick:
    no name:
    Kempeth:
    Now if we could only specify the variable name in RegEx that would solve our problems...

    That would be an awesome language feature - just imagine the potential for abuse...

    Perl rather than PHP, but...

    $eMailAddress = '[email protected]';
    
    foreach my $key (keys %main::) {
        if($key =~ /emailaddress/i) {
            $email = $$key;
        }
    }
    

    print "$email\n";

    Doesn't work on lexicals, though.

  • (cs) in reply to frits
    frits:
    frits(unregistered):
    This is literally the lamest WTF that has ever been posted.

    Seriously, who hasn't had to do something like this?

    Lookie. Someone's butthurt. Trying to make your very own meme?

    Seriously, who hasn't tried to do something like this?

  • Jordan Bray (unregistered) in reply to Steenbergh

    Unfortunately TerminalSalt and TerminalsAlt /are/ different variables.

  • frits (unregistered) in reply to The Enterpriser
    The Enterpriser:
    frits:
    frits(unregistered):
    This is literally the lamest WTF that has ever been posted.

    Seriously, who hasn't had to do something like this?

    Lookie. Someone's butthurt. Trying to make your very own meme?

    Seriously, who hasn't tried to do something like this?

    If that isn't irony, I don't no what is.

  • Some Guy (unregistered) in reply to Anon
    Anon:
    Zylon:
    What IS the argument for case-sensitive names, anyway?

    Because then I can do things like this:

    private int myInt; public int MyInt { get { return myInt; } set { myInt = value; } }

    Now I can easily tell whether or I'm using the property (MyInt) accessed through the getter and setter (which may do other things - especially notifications for binding in the setter) or the backing field (myInt).

    I know other people prefer to start their backing fields with an underscore, but I've never liked the way that looks.

    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:

    private int myInt_;
    public int MyInt
    {
    get { return myInt_; }
    set { myInt_ = value; }
    }

  • Death!Death!Die! (unregistered) in reply to frits
    frits:
    The Enterpriser:
    frits:
    frits(unregistered):
    This is literally the lamest WTF that has ever been posted.

    Seriously, who hasn't had to do something like this?

    Lookie. Someone's butthurt. Trying to make your very own meme?

    Seriously, who hasn't tried to do something like this?

    If that isn't irony, I don't no what is.

    It isn't and you don't.

  • Rich (unregistered)

    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.

  • Robert Kosten (unregistered) in reply to frits
    frits:
    This is literally the lamest WTF that has ever been posted.

    Seriously, who hasn't had to do something like this?

    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!)

  • (cs) in reply to Ksevio
    Ksevio:
    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.

    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?)

  • monkeyPushButton (unregistered) in reply to Patrick
    Patrick:
    Case is the difference between EmployeeReSigned and EmployeeResigned. Caseless would require underscores.
    So one is for those employees that have resigned and the other is for employees who are now negative?
  • Mr Jewish (unregistered)

    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?

    if (!$email) {
    	global $Email; 
        $email=$Email;
    }
    if (!$email) {
    	global $Email_Address;
    	$email = $Email_Address;
    }
  • Anon (unregistered) in reply to JamesQMurphy
    JamesQMurphy:
    A Moron:
    kaalikas:
    Lars:
    Case sensitive is good. It's kind of annoying when Initialize and initialize is the same name for everyone except people in Turkey.
    this.
    Help a moron out by explaining this please.
    http://en.wikipedia.org/wiki/Dotted_and_dotless_I

    Ahh....so we can all agree that TRWTF are the Turks.

  • Anon (unregistered) in reply to Some Guy
    Some Guy:
    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, what you're saying is.....TRWTF is VB!

  • corwin766 (unregistered) in reply to Zylon
    Zylon:
    What IS the argument for case-sensitive names, anyway?

    Case-insensitivity is too much work for a PDP-11.

  • wtf (unregistered) in reply to Mason Wheeler
    Mason Wheeler:

    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?)

    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.

  • TRWTF (unregistered) in reply to Anon
    Anon:
    Some Guy:
    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, what you're saying is.....TRWTF is VB!

    I knew it!

  • The Nerve (unregistered)

    Fixed?

    if (!$email){
        global $Email;      
        if ($Email) {
            $email=$Email; 
        } else {
            global $Email_Address;         
            if ($Email_Address) {
                $email=$Email_Address;
            } else {
                global $email_address;             
                if ($email_address){ 
                    $email=$email_address; 
                } else {
                    global $EmailAddress;                 
                    if ($EmailAddress){ 
                        $email = $EmailAddress;
                    } else {
                        global $emailaddress;                      
                        if ($emailaddress){ 
                            $email = $emailaddress;
                        } else {
                            global $EMailAddress; 
                            $email = $EMailAddress; 
                        }
                    }
                }
            }
        }
    }
    

Leave a comment on “The Email Tree”

Log In or post as a guest

Replying to comment #:

« Return to Article