Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Namespaces contiguous in the entirety

by Tanktalus (Canon)
on Sep 28, 2005 at 04:45 UTC ( [id://495620]=note: print w/replies, xml ) Need Help??


in reply to Namespaces contiguous in the entirety

While you're at it, your lint process may want to catch that there should only be one package statement per file, and that package statement should match the filename, including path, from some entry in @INC, with directory separators becoming ::, and a .pm thrown on at the end. All of this is further convention that is usually a Good Practice (tm).

Or, you could embrace the freedom that perl gives to do what you think is right instead of what Larry thinks is right. Which means not following convention when convention is getting in the way of getting your job done. I've had cause to buck convention in the past, and your lint would probably give me problems over it. The key is to allow people to do what needs to be done, as long as they acknowledge they're doing something strange. Just like we always "use strict", but have the ability to lexically scope "no strict" (preferably with a modifier, such as 'refs').

  • Comment on Re: Namespaces contiguous in the entirety

Replies are listed 'Best First'.
Re^2: Namespaces contiguous in the entirety
by rir (Vicar) on Sep 28, 2005 at 13:14 UTC
    Tanktalus, your tone seems to disparage my intentions. If you read my post as a request to change Perl then I was not clear, I would just like that effect. Given the nature of the problem the easiest technically correct code-fix probably is to hack the perl source and add a check and fail to where package statements are handled. That would likely be a fairly localized patch.

    Collision of module names is a issue. In my code, client code is invited to partition a problem by creating sub-classes. It is very possible that the same namespace could be inadvertently reused. I am not trying to enforce the common conventions of a Good Practice(TM).

    Be well, rir

Re^2: Namespaces contiguous in the entirety
by QM (Parson) on Sep 28, 2005 at 22:12 UTC
    While you're at it, your lint process may want to catch that there should only be one package statement per file, and that package statement should match the filename, including path, from some entry in @INC, with directory separators becoming ::, and a .pm thrown on at the end.
    My (limited) reading of modules leads me to think this is overkill. I've seen multiple package statements in a module for classes/namespaces derived from the main module, but the package was too small to worry about creating separate files. (I wonder how many modules in the core distribution make use of multiple package statements?)

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

      That's actually kind of my point. Convention says this is what you're supposed to do. However, convention also allows for alternatives. Convention says that each package appears once, at the top of a .pm file of the same name where ::'s are converted to directory separators. Which means that you should only have one package per file, and that you should never overlap with others' packages.

      In reality, there can be valid reasons for bucking convention. Packages that are too small to worry about separate files is a valid one. Hiding a package is another one - e.g., how mirod hides XML::Twig::Elt inside the XML/Twig.pm. Although in this case, it may be partly because XML::Twig and XML::Twig::Elt are so tightly intertwined that there could be fun times in trying to compile them in separate units. Other cases may have tightly tied packages where using the wrong one first can't resolve BEGIN blocks appropriately. Or other tightly tied packages where the other packages would take longer to locate on disk than is worth it.

      I really don't have a problem with the OP's suggestion. As long as there is a clean and easy way to turn it off when I know what I'm doing. Such as what TimToady suggests.

      use CGI::Application; class CGI::Application is also { # stuff we want to add to the CGI::Application namespace. };
      This says, "Yes, I know there is already a CGI::Application, but I'm the human, and you're the dumb computer, so do what I tell you." Well, that's what it says if I do it. It might not be so snarky if others do it ;-) I don't have an issue with this - the extra typing required for the rare time I do it seems like a reasonable trade-off.

      I'm not sure if there will be any perl 6 diagnostics for packages classes in the wrong file, though, as I had suggested to the OP.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://495620]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (1)
As of 2024-04-25 03:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found