The PBP suggests using different formats of case to help explain what a thing is.
By this, it means lowercase-only for subroutines, methods, variables, and labelled arguments. It means mixed case for module names, and all upper case for constants and file handles. (Actually it doesn’t mention file handles, but it ought to.) The book does note that standard abbreviations, etc., should keep their usual case.
This is tolerable, especially if you’ve got the underscores for word separation. It’s more useful than it might sound at first to be able to see a package or class name, and having that set of namespaces separate does help. It’s not a 100% reliable metric, because it’s helpful to use all-lowercase to write pragma-like modules.
The description in the book doesn’t mention file handles or labels. Maybe it assumes you shouldn’t use them. They seem to make sense in all uppercase.
The point made by the book is that this is a common and widespread format already, which helps make it familiar and useful, and makes your code fit the standards as a whole.
So, yeah, fine. Fit in well, be consistent.
Commenting individually on every PBP seems like either spam or self-promotion. Please stop.
That wasn’t the intent. The intent is not to make people crazy, either. Rather than try and have a discussion in the comments section of an unrelated post, where it will be missed by many, I’ve asked in a new post for input from people. Maybe there will be some suggestions on what would be useful.
Filehandles should be in variables, the variables should be ordinary lowercase ones. Using global symbols by symbolic reference for filehandles isn’t really called for anymore, except for the builtin globals like STDIN, STDOUT, and ARGV.
Oh, and ignore buzz :)
All the new code I write is this way; yay for lexical file handles! I don’t think doing “open(my $INPUT_FILE, ‘foo.txt’);” is useful, and I see it done. You’re right, it’s silly. They’re ordinary variables and use ordinary lower case names.
However, I often bump into code which is old or misguided and still does use file handles; those should be uppercase. Even if it’s just to scream REFACTOR ME!… but those file handles should be upper case.
Agreed.
Using capitalised package names and lowercase subs isn’t just for aesthetic reasons – it also means you can write Something->new without worrying about the trailing :: on the package name. Okay, maybe that’s an aesthetic reason as well…
A contrived example:
perl -e'{ package Something; sub new { print “constructor” } } sub Something { warn “not the constructor” } Something->new’
vs.
perl -e'{ package Something; sub new { print “constructor” } } sub Something { warn “not the constructor” } Something::->new’
As for variable names – doesn’t really matter there, it’s just nicer to deal with code that isn’t SHOUTING or Introducing Unnecessary Case Changes =)