Conrad (>): > Is there something more up-to-date concerning "Perl 6 best practices" that > are presently-recommended (by p6l or @Larry) than the following item on the > Perl 6 wiki?
If you ask me, "best practices" evolve as a countering force to enough people using less-than-ideal practices to create maintenance headaches or suboptimal solutions noticeable enough for someone to put together a collection of tips and insights. I use Perl 6 every day. My problem is not that I encounter badly thought-out Perl 6 code frequently -- it's that we're targeting incomplete Perl 6 implementations and have to go against what would ordinarily be seen as best practices in order to circumvent bugs and missing features in various layers of the Perl 6 implementation stack. The tricks we evolve to do this are far removed from best practices: they are closer to the worst advice you could give a Perl 6 beginner. (Because most of them solve a problem _without_ the help of some convenient Perl 6 feature.) That said, I do have one Perl 6-specific "best practice". I know you're looking for a collection, but one's a start. :) Here it is: Do not combine 'ne' and '|', like this: die "Unrecognized directive: TMPL_$directive" if $directive ne 'VAR' | 'LOOP' | 'IF'; One is tempted to assume that this means the same as "$directive ne 'VAR' || $directive ne 'LOOP' || $directive ne 'IF"", but it doesn't. Instead, it's a negated string comparison against three values, the results of which are then OR-ed together. The condition will always be true, because there's always at least two values that $directive is not string-equal to. The "correct" form using junctions would be this: die "Unrecognized directive: TMPL_$directive" if $directive ne 'VAR' & 'LOOP' & 'IF'; But my brain refuses to let me believe that this is what I want to write. ("If $directive is not string-equal to 'VAR' and 'LOOP' and 'IF'... well of course it isn't!") So instead, I'd use "eq", and negate the whole expression: die "Unrecognized directive: TMPL_$directive" if !($directive eq 'VAR' | 'LOOP' | 'IF'); The more general advice, then, would be not to use junctions together with negated equality operators. Instead, use the non-negated equality operator, and negate the whole expression. // Carl