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

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.

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

Replies are listed 'Best First'.
Re^8: Wassercrats::Improved Volume 0, Number 0
by stvn (Monsignor) on Aug 27, 2004 at 02:09 UTC
    If I say that DB->handle() returns the DBI handle or put the thing in $DB::handle, how does that differ?

    It is the same logic that is behind calling accessor and mutator methods on objects, it hides the underlying representation. This is not even really an OO concept either, it goes back to the days of structured programming and abstract data types even. If I call DB->handle() rather than access $DB::handle directly, then I can change my DB package from managing a single connection, to manage a pool of connections. Or I can verify that my connection is active before handing it to the calling function, and reconnect if it is not.

    Consider that your function itself is a global of a kind.

    Functions are no longer really global if you put them into packages, then you have a heirarchy of namespaces for them to occupy.

    -stvn
      Functions are no longer really global if you put them into packages, then you have a heirarchy of namespaces for them to occupy.

      How is that different than a variable that lives in a package? Isn't it also part of a heirarchy of namespaces?

        Unless variables and functions share the same namespace and syntax (as in the case of lvalue methods), functions are different in that they also encapsulate behavior. Variables merely encapsulate values.