• massemo (unregistered)

    FRIST maybe?

    TRWTF is Enterprisey PHP

  • stupid (unregistered)

    not frist because aksimet needs shooting...

  • Fyrilin (unregistered)

    This is why people don't like PHP; they see code like this.

    As a PHP supporter, I have to point out that PHP DOES allow OOP including some great frameworks.

    Just preempting the PHP bashing.

    captcha: damnum: my thoughts on this code

  • Shutterbug (unregistered) in reply to Fyrilin

    Agreed Fyrilin - PHP isn't as bad as that when it's used with an ounce of common sense.

    Given the option if presented with code like this to maintain, it's either being rewritten from the ground up or I'll be making sure the door doesn't hit me too hard on the way out.

  • Steve (unregistered)

    I don't do PHP, but rather C++ so I may be a little off here, but this is a prime reason why you don't use Global variables for anything (Variables that get allocated globally are a different matter - and yes, there is a difference).

  • JJ (unregistered)

    Real PHP WTF

    In no specific order

  • scott (unregistered)

    Yeah, general "rule of thumb", if you cannot count your globals on your fingers, there's probably something wrong. On that note, I once had a vendor BRAG to me that the next release of their software used over 6,000 global variables. The poor fool thought that it was a measure of the size, and therefore sophistication, of their product. To me, well, let's just say that data point explained a lot ;-)

  • michael (unregistered) in reply to Steve

    Variables that get allocated globally are a different matter - and yes, there is a difference."

    Are you speaking of heap variables? If so, it's far better to call them "heap variables" than "variables that get allocated globally." If you mean something else, please do educate us.

  • Why'd he turn it down? (unregistered) in reply to michael
    michael:
    Variables that get allocated globally are a different matter - and yes, there is a difference."

    Are you speaking of heap variables? If so, it's far better to call them "heap variables" than "variables that get allocated globally." If you mean something else, please do educate us.

    All global variables live in the heap, but not all heap variables are global.

    A global variable refers to a static, a singleton, a variable where every function/class refers to the same value.

    This is contrasted to a member variable, a local variable or a function argument.

    This definition, by convention, tends to exclude global constant primitives.

    An excess number of global variables is typically a sign something could be redesigned.

  • Ben Jammin (unregistered)

    I may be confused here. You have a global db connection that everything seems to be using. In several places it is switched to a testdb and then back. Is this for testing the code against a test environment vs a production environment (which the global variable should be changed to point to the test db) or is there some other reason for this?

  • (cs)

    TRWTF is that "fred" is used in the comment block, but not used as a temporary variable name.

    (one of my CS professors was in the habit of using "fred" as a temp/nonsense variable name in the same manner as "foo" is often used)

  • (cs) in reply to scott
    scott:
    Yeah, general "rule of thumb", if you have to count your globals, there's probably something wrong.
    FTFY
  • michael (unregistered) in reply to Why'd he turn it down?

    All global variables live in the heap, but not all heap variables are global.

    Global variables do not live in the heap. A compiler places them into a static section that is loaded straight into memory at load time. No malloc, no free, no heap.

    I was asking about what was meant by "variables that are allocated globally" but which are not global variables. I suspected, perhaps incorrectly, that this was a reference to heap variables, which can be made globally accessible (as opposed to stack and member variables, which can only be used in context).

  • Boog, I Am Your Father! (aka Behold The Return Of Zunesis!)! (unregistered) in reply to stupid
    stupid:
    not frist because aksimet needs sodomizing...
    Hear, Hear!
  • someone (unregistered)

    "What I did was to swap out the link identifier" so the real WTF is his/her solution to the problem imho.

    what would hinder him/her to create another global var for db2?

  • (cs)

    Globals can be declared INSIDE FUNCTIONS???

  • Rcxdude (unregistered) in reply to michael

    depends on the language. what you said is true for C and C++ but I suspect is not true for PHP, python, etc

  • Melnorme (unregistered) in reply to michael

    This is implementation dependent. "Global variable" is a description of semantic scope, not of generated code.

  • anonymous (unregistered)

    $GLOBALS['db2'] = ...; and its done -.-

  • fishdude (unregistered)
    Globals can be declared INSIDE FUNCTIONS???

    If you want to access a global variable from inside a function in PHP, you first have to run the statement

    global $variableName
    . If not,
    $variableName
    is treated as a local variable.

    There is also a supoerglobal array called $GLOBALS that would let you access it as $GLOABLS['variableName'].

    Good stuff, huh?

  • Not Jimmy Wales (unregistered) in reply to RichP

    No, that is a comment signed by someone named fred, who apparently worked on the code. It's not the name of a variable.

    Ob captcha: WTF is a laoreet? Can I buy one at a petstore? Or is something I shouldn't mention in polite company?

  • (cs)

    Global variable increase window of vulnerability. This is well known fact. They are necesary evil in our trade.

  • (cs)

    Is it just me that is shaken by the database calls directly in the page? Separation of concerns anyone?

    Someone in this thread mentioned something about PHP supporting OO concepts and all these are bad examples of PHP, and that PHP really is good, really honestly... Please, show an example of what "good" PHP would look like...

    Also, PHP is TRWTF, amirite?

    </obligatory PHP bashing>

  • Dazed (unregistered) in reply to scott
    scott:
    Yeah, general "rule of thumb", if you cannot count your globals on your fingers, there's probably something wrong.
    I do sometimes use more than that. But only in stand-alone run-to-completion applications, where I initialise them at the beginning and never change them after that.

    In server-side applications I generally reckon I can count the global variables on the fingers of one foot.

  • (cs) in reply to stupid
    stupid:
    not frist because aksimet needs shooting...
    Anything that frustrates morons such as yourself is a good thing.
  • Andrew (unregistered)

    What madness is this?! How can someone design an enterprise-y system with a whole mess of globals?!

    This reeks like a simple application became a general application became a cross-functional business corporate scorecard analytical engine...

  • Chris (unregistered)

    TRWTF is how many idiots think that they are clever or sophisticated because they bash PHP.

  • fuckingCommServerForgotMuUsername (unregistered) in reply to C-Octothorpe
    C-Octothorpe:
    Is it just me that is shaken by the database calls directly in the page? Separation of concerns anyone?

    Someone in this thread mentioned something about PHP supporting OO concepts and all these are bad examples of PHP, and that PHP really is good, really honestly... Please, show an example of what "good" PHP would look like... </obligatory PHP bashing>

    You could have a look at the symfony framework code, most of it is quite clean and dandy.

  • geoffrey (unregistered) in reply to Nagesh
    Nagesh:
    Global variable increase window of vulnerability. This is well known fact. They are necesary evil in our trade.

    I could not have said it better myself. When the job needs done, a can-do programmer understands that sometimes everything can't be pretty and perfect, and must resort to these necessary evils.

  • Darkstar (unregistered) in reply to Fyrilin

    Errhh FILE, anyone?

  • Metro Sauper (unregistered)

    Without discussing the pitfalls of globals, doesn't this have a direct refactoring pattern? replace the code of the function which uses globals with a function call to a new function passing in the globals as parameters. Implement the new function using the original code, replacing the global references with the parameters.

    This would work for all old invocations and the new code could just call the new function.

    Metro.

  • (cs) in reply to Metro Sauper
    Metro Sauper:
    Without discussing the pitfalls of globals, doesn't this have a direct refactoring pattern? replace the code of the function which uses globals with a function call to a new function passing in the globals as parameters. Implement the new function using the original code, replacing the global references with the parameters.

    This would work for all old invocations and the new code could just call the new function.

    Metro.

    And where is budget for code come from? Remember everything need money.

  • manu (unregistered)

    Search results in the screenshot seem to talk about instances of '$sql' ?

  • The name (unregistered) in reply to Nagesh
    Nagesh:
    Metro Sauper:
    Without discussing the pitfalls of globals, doesn't this have a direct refactoring pattern? replace the code of the function which uses globals with a function call to a new function passing in the globals as parameters. Implement the new function using the original code, replacing the global references with the parameters.

    This would work for all old invocations and the new code could just call the new function.

    Metro.

    And where is budget for code come from? Remember everything need money.

    Selling sex.

  • (cs) in reply to Why'd he turn it down?
    Why'd he turn it down?:
    An excess number of global variables is typically a sign something could be redesigned.
    We knew that! ;-) I'd take it beyond "could be" and "typically" but most often have seen "as if" and "rarely is"
  • Anonymous (unregistered)

    Not a single comment has pointed out that Amber is female????

  • (cs) in reply to Anonymous
    Anonymous:
    Not a single comment has pointed out that Amber is female????

    Ambar mean sky in Sanskrit. It is boy's name.

  • (cs) in reply to ekolis
    ekolis:
    Globals can be declared INSIDE FUNCTIONS???

    Not to best of my knowledge and my knowledge is best as far as I know.

  • (cs)

    I once read an article that stated that some companies make a mistake of "redesigning something from scratch" when the should have just fixed what was broken, and that there is rarely a reason to redesign from scratch.

    This I believe falls into the "redesign from scratch" catagory.

  • Nag-Geoff (unregistered) in reply to PiisAWheeL
    PiisAWheeL:
    I once read an article that stated that some companies make a mistake of "redesigning something from scratch" when the should have just fixed what was broken, and that there is rarely a reason to redesign from scratch.

    This I believe falls into the "redesign from scratch" catagory.

    Surely, you live in fantasy world.

  • Jeff (unregistered)

    TRWTF is not PHP, TRWTF how we allow armies of incompetent grunts to work as programmer.

    Im pretty sure one can create an enterprisey Fecosystem in any langage.

  • (cs) in reply to fishdude
    fishdude:
    Globals can be declared INSIDE FUNCTIONS???

    If you want to access a global variable from inside a function in PHP, you first have to run the statement

    global $variableName
    . If not,
    $variableName
    is treated as a local variable.

    Oh, so you're not actually declaring new ones, you're just importing existing ones... that makes sense... sort of...

  • Gibbon1 (unregistered) in reply to geoffrey
    geoffrey:
    Nagesh:
    Global variable increase window of vulnerability. This is well known fact. They are necesary evil in our trade.

    I could not have said it better myself. When the job needs done, a can-do programmer understands that sometimes everything can't be pretty and perfect, and must resort to these necessary evils.

    I often think that I'm choosing between two evils. Sometimes one is an orthodox evil, global's, goto's, functions with side effects, all these are evil, but sometimes to avoid them brings on worse evils.

  • Matt Westwood (unregistered) in reply to RichP
    RichP:
    TRWTF is that "fred" is used in the comment block, but not used as a temporary variable name.

    (one of my CS professors was in the habit of using "fred" as a temp/nonsense variable name in the same manner as "foo" is often used)

    In the UK (England in particular), "Fred" is used as a generic joke name. From what I understand from the lyric sheets of a certain Jefferson Airplane album, the same applies to a greater or lesser extent in the US too, yeah?

  • Matt Westwood (unregistered) in reply to Dazed
    Dazed:
    scott:
    Yeah, general "rule of thumb", if you cannot count your globals on your fingers, there's probably something wrong.
    I do sometimes use more than that. But only in stand-alone run-to-completion applications, where I initialise them at the beginning and never change them after that.

    In server-side applications I generally reckon I can count the global variables on the fingers of one foot.

    I take it you're a code monkey?

  • frotl (unregistered) in reply to Fyrilin
    Fyrilin:
    This is why people don't like PHP; they see code like this.

    As a PHP supporter, I have to point out that PHP DOES allow OOP including some great frameworks.

    Just preempting the PHP bashing.

    captcha: damnum: my thoughts on this code

    Someone could do significantly better than the above without using OOP. Bad programmers are bad whether its procedural programming or object oriented programming.

  • LOADING (unregistered) in reply to ekolis
    ekolis:
    fishdude:
    Globals can be declared INSIDE FUNCTIONS???

    If you want to access a global variable from inside a function in PHP, you first have to run the statement

    global $variableName
    . If not,
    $variableName
    is treated as a local variable.

    Oh, so you're not actually declaring new ones, you're just importing existing ones... that makes sense... sort of...

    Make sense. Javascript opts for var to declare a variable locally. PHP opts for global to import from the global scope. They are opposites...

  • Jack (unregistered) in reply to Nagesh
    Nagesh:
    Anonymous:
    Not a single comment has pointed out that Amber is female????

    Ambar mean sky in Sanskrit. It is boy's name.

    "Amber" means fossilized tree resin in English, and it is a girl's name. But why should someone want to point that out?

  • anon (unregistered) in reply to Nagesh
    Nagesh:
    Metro Sauper:
    Without discussing the pitfalls of globals, doesn't this have a direct refactoring pattern? replace the code of the function which uses globals with a function call to a new function passing in the globals as parameters. Implement the new function using the original code, replacing the global references with the parameters.

    This would work for all old invocations and the new code could just call the new function.

    Metro.

    And where is budget for code come from? Remember everything need money.

    ...and the bugs that stem from such ridiculous code cost money too.... it's a pretty easy argument to forge IMHO. You could also implement changes bit by bit, that is the true way of getting old code improved, don't try to justify doing it in one big hit... most of that can be done "out of scope" with other development too

  • Kasper (unregistered)

    Seems many languages permit global variables and few languages prevent global variables. Is that because we are using really old languages from before anybody knew how to structure code? Or are new languages still designed with support for global variables?

Leave a comment on “Globally Coupled”

Log In or post as a guest

Replying to comment #:

« Return to Article