in reply to Re^3: Wassercrats::Improved Volume 0, Number 0
in thread Perl::Improved Volume 0, Number 0

I don't see how my use of globals is unsafe.

Are you writing to them? If so, your use of globals is unsafe. At the risk of making an appeal to the majority, this fact is rather well-accepted among programmers that don't wear diapers anymore. The only accepted use of globals is for constant data. You can Google for "global variables dangerous" to get plenty of arguments as to why.

"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

  • Comment on Re^4: Wassercrats::Improved Volume 0, Number 0

Replies are listed 'Best First'.
Re^5: Wassercrats::Improved Volume 0, Number 0
by diotalevi (Canon) on Aug 26, 2004 at 20:50 UTC
    The other only accepted use of globals are for such things that are global like database connections or things that cross-cut into potentially every or many contexts.

      Hrm, I usualy pass my DBI handles around without globals. I could see making the handle a "global" part of a class, like Class::DBI does.

      I guess making a complex object a global (or just widely-scoped) isn't as bad as a simple string or number. You at least have finer-grained control of what is going on that way. I'd still prefer to pass it around, though.

      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

      Thats what Singletons and Factory classes are for, they are global without actually being global. Of if you are of the more functional persuasion you can use an Identity function. But there is always some way to avoid using globals.

      -stvn

        Yes... I've used singleton producing functions before but what's the point in that? If I say that DB->handle() returns the DBI handle or put the thing in $DB::handle, how does that differ? Consider that your function itself is a global of a kind. It is nameable by any code elsewhere in the running program just as your variable slot was.

        Anyhow, Factories are for Java programmers. That's what our untyped variables are for in perl and that's an entirely different discussion.