The PBP suggests that boolean variables and subroutines should get special naming consideration, and be named in ways that read well. That may involve giving them names like “is_whatever” or “has_whaterver” or “can_whatever”, so that they make contextual sense.
Archive for the ‘Perl’ Category
This section of the PBP is a long one, and goes into great detail about how to think about naming important parts of your programs. It covers explicitly modules/namespaces, variables (several types of them), and functions.
I thought, at first glance, it was way too picky and specific, but the more I read it, the more I liked it.
The Best Practice is to get a tool to do the work for you; it’ll be regular, and not spend your time doing it.
My only concern is that Mr. Conway says, “You can take ugly code like this and turn it into something readable.” where the “readable” code isn’t, to my mind, that much better. Spaces around the parens and an extra blank line do not readable code make. (more…)
Lists need to be formatted to be readable. The suggestion is to always use parenthesis, indent after a parenthesis, and line things in columns, all with trailing commas.
The book provides clear examples, which I won’t duplicate here. (more…)
The book talks about how confusing the ternary operator can be and how much of a mess it can make. I’m almost surprised it doesn’t say, “Don’t use it.”
It suggests columns instead, with the condition, then the positive result.
The PBP suggests breaking assignments much like it suggests breaking other operators; the assignment leads the broken line:
my $thingy = $stuff + $hard_things + $foo;
This Practice is to break long expressions at lower-possible operators. It actually says “the lowest possible precedence”. At a glance, this sounds like a fine idea, and it, in general, is. The reason given is pretty solid, that you can easily confuse people about precedence by splitting things apart. This will be even more important on operators people may not be familiar with the precedence of. (Quiz: Which is higher precedence “&&” or “and”? Which is higher precedence, “~” or “^”?)
I’ve been watching the YAPC::NA presentations, and saw a mention of this Kickstarter:
This is a project to help get a system written in Perl to compete with WordPress. There is an existing system that’s close, all it needs is time, energy, and developers. It sounds like there’s a great core there, but it’s lost the commercial support it had before, and the one developer can’t go it alone.
The Kickstarter is to try and fund some key work on it, and make it more accessible and as easy to get started as WordPress.
Sadly, the Kickstarter’s getting close to no traction, and that makes it look kind of bleak.
Here’s a signal boost; have a look at the system, read the page (the video has lots of good stuff, but it’s a little wordy) and consider supporting this useful development.
If you can’t support the Kickstarter, maybe you have time to help them get the major new release unblocked and keep it from sinking into the murk of obscurity.
At the end of the video, they point out that a hundred people giving a hundred dollars each will fund it, and get it over some of these hurdles. A thousand people giving ten dollars each would work just as well.
This Best Practice is one that I’ve seen people argue horribly about, and I don’t get it. The suggestion is to avoid doing a big calculation, with sequences of complex operations, in the middle of a statement. Take that complexity, stick it in a variable, and use the variable. (more…)