in reply to Re^6: I hate the leading underscores.
in thread I hate the leading underscores.

It is the official Perl way, as envisioned by Larry Wall. (I should have said "members" rather than "variables". Hiding variables is done by scoping.) Any other technique used to hide private methods and members constitutes an attempt to write C++ (or some other language) in Perl.


Do you have a link to that? Also, while I agree that Mr. Wall has done some amazing things, people can be different. Using other techniques would not constitute the attempt to write another language in Perl, it would be an attempt to write OO, which is precisely what Perl is trying to emulate with classes.

It really does just come down to a matter of preference, and the leading underscore really isn't the problem, it's the incomplete OO support. Although please note I have not delved in depth into Perl's OO support beyond simple class constructs, so please do correct me if I am wrong) People have issues in Java with underscores all the time.

Replies are listed 'Best First'.
Re^8: I hate the leading underscores.
by itub (Priest) on Feb 16, 2005 at 19:37 UTC
    The famous "shotgun quote" appears in perlmodlib:
    Perl does not enforce private and public parts of its modules as you may have been used to in other languages like C++, Ada, or Modula-17. Perl doesn't have an infatuation with enforced privacy. It would pre- fer that you stayed out of its living room because you weren't invited, not because it has a shotgun.

    The module and its user have a contract, part of which is common law, and part of which is "written". Part of the common law contract is that a module doesn't pollute any namespace it wasn't asked to. The written contract for the module (A.K.A. documentation) may make other provisions. But then you know when you "use RedefineTheWorld" that you're redefining the world and willing to take the consequences.

Re^8: I hate the leading underscores.
by Roy Johnson (Monsignor) on Feb 16, 2005 at 19:32 UTC
    Do you have a link to that?
    In perldoc perlmod, Larry laid out the conceptual basis of OO for Perl.
    Perl does not enforce private and public parts of its modules as you may have been used to in other languages like C++, Ada, or Modula-17. Perl doesn't have an infatuation with enforced privacy. It would prefer that you stayed out of its living room because you weren't invited, not because it has a shotgun.
    it's the incomplete OO support
    It is a misconception that strong data hiding is integral to OO, just as it is a misconception that strong data typing is integral to programming languages. The language is to serve the programmer, not to handcuff him.

    Calling an undocumented method is not an easy mistake to make. If some programmer does that, it's most likely intentional. The programmer is violating OO programming guidelines, it is not the language's fault for letting him do something that isn't OO.

    That said, here is what I think is a kind of clever way to hide private methods. Wow, was that not a good idea. There shouldn't be private methods, just private subs. And the easy way to hide them is to make them lexical coderefs.


    Caution: Contents may have been coded under pressure.