Code craft

Perlbuzz news roundup for 2012-02-06

February 6, 2012 Code craft, CPAN, Perl 5 No comments

These links are collected from the
Perlbuzz Twitter feed.
If you have suggestions for news bits, please mail me at
andy@perlbuzz.com.

Perl::Critic finds annoying little bugs in your code.

January 4, 2012 Code craft, Perl 5 No comments

My work colleague Mike O’Regan created a policy for the latest version of Perl::Critic.

Now if you have a line of code like this:


my $n += somefunc();
# Should be my $n = somefunc();

Perl::Critic will tell you


Augmented assignment operator '+=' used in declaration at line X,
column Y. Use simple assignment when initializing variables.

If you haven’t let Perl::Critic loose on your code yet, now’s a great time to try.

To the loyal Perl::Critic users, what’s the nastiest bug Perl::Critic found for you? Let me know in the comments.

Perlbuzz news roundup for 2011-12-19

December 19, 2011 Code craft, Community, CPAN, Perl 5, Perl Foundation No comments

These links are collected from the
Perlbuzz Twitter feed.
If you have suggestions for news bits, please mail me at
andy@perlbuzz.com.

Perlbuzz news roundup for 2011-11-14

November 14, 2011 Code craft, Conferences, CPAN, Perl 5, Perl 6 No comments

These links are collected from the
Perlbuzz Twitter feed.
If you have suggestions for news bits, please mail me at
andy@perlbuzz.com.

Perlbuzz news roundup for 2011-11-07

November 7, 2011 Code craft, Community, CPAN, Perl 5, Perl 6 2 comments

These links are collected from the
Perlbuzz Twitter feed.
If you have suggestions for news bits, please mail me at
andy@perlbuzz.com.

Perlbuzz news roundup for 2011-05-09

May 9, 2011 Business, Code craft, Community, CPAN, Perl 5, Perl 6

These links are collected from the
Perlbuzz Twitter feed.
If you have suggestions for news bits, please mail me at
andy@perlbuzz.com.

Perlbuzz news roundup for 2011-02-17

February 17, 2011 Code craft, CPAN, Perl 5, Perl 6 No comments

These links are collected from the
Perlbuzz Twitter feed.
If you have suggestions for news bits, please mail me at
andy@perlbuzz.com.

Develop sensible coding habits on the path to true Laziness

December 16, 2010 Code craft 7 comments

Whenever I walk in my front door, I walk straight to the kitchen, open the
first drawer, put in my keys and wallet and cell phone, and close
the drawer. Always, without fail, no matter how bad I might have
to take a leak. It is no less convenient for me to do this than
to drop my stuff any old place. It is a habit that I have maintained
for close to 30 years now. And I never ever ever have to wonder
where I put my keys, or my phone, or my wallet. Ever. Having to
do so would be extremely inconvenient. In fact, it would be EXTRA
brain cycles on my part to put them where they do not belong.
When the phone rings, I know where it is. I don’t run around
wondering “Where’s my phone?” trying to triangulate position. It’s
always there in the kitchen drawer. Always.
I also always put on my seat belt in the car. I never wonder if
it’s “necessary”. I just do. Thinking about if it is “necessary”
is also inconvenient. It takes brain cycles that I don’t need to
spend. I also know that the one time I need my seat belt and I
don’t have it on, I’m screwed.
Trying to decide to save three seconds by not buckling my seat belt
is false laziness. And so is worrying about when you can leave out
`warnings` and `strict` from your Perl programs.
Yesterday in IRC, someone was lamenting that Perl 6 effectively has
`warnings` and `strict` on by default. All variables must declared
before use. This person was one of those programmers who tried for
the premature optimization of saving some typing. He forgot that
typing is the least of our concerns when programming. He forgot
that programmer thinking time costs many orders of magnitude more
than programmer typing time, and that the time spent debugging can
dwarf the amount of time spent creating code.
He also forgot that he’s a human.
Checks like `warnings` and `strict` are there because we are fallible
humans. We type `$totl` instead of `$total`, and we want Perl to
tell us that. We try to dereference scalars and since we’re no
longer using Perl 4, we want Perl to tell us about that, too. We
want Perl, which is a program and doesn’t get sloppy and forget
things, to catch us when we are humans and get sloppy and forget
things.
Buy and read *The Pragmatic Programmer* and *Code Complete* and
develop a solid set of programming habits from them. Sensible
habits that are followed even when you might be able to get away
without them are the true Laziness.

ack 1.94 released

November 15, 2010 Code craft, Perl 5 No comments

Version 1.94 of ack, my source code searcher designed for programmers, has been released. This is the first release in almost
a year.
You can install it as [App::Ack](http://search.cpan.org/dist/ack) from the CPAN shell, or you can use one of the installation methods described at [http://betterthangrep.com/](http://betterthangrep.com/)
Here are the changes.
## Fixes
–man and –version now return with an exit code of 0. They
used to exit with a 1. Thanks to Bo Borgerson.
Fixed ack misbehavior when using –match or not specifying a regex:
ack –match Sue
cat foo | ack –perl
Fixed issue 74: analog to grep, ‘ack –count regex file’ now
only outputs the number of found matches, if only one file is
given.
Fixed issue 76: Giving both –line and a regex (with –match)
now leads to an error. The same is true for -f or -g in conjunction
with –match. (Torsten Blix)
Fixed issue 80: Piping into ack –count now works as expected.
ack always returned 0 when piped into, no matter how many matches
where found. (Torsten Blix)
Fixed issue 81: .ackrc now ignores leading/trailing whitespace.
(Torsten Blix)
## File type updates
Added –verilog, –vhdl and –clojure.
Files that match *.mk and *.mak as well as GNUmakefile are now included in
the ack filetype ‘make’ (issue 88).
Added RSpec’s .spec type to the –ruby list.
Added support for Go and Delphi.
Ignores Monotone’s _MTN directories.
Added .xsl to the list of –xml files.
## Enhancements
The –ignore-dir option now can ignore entire paths relative
to your current directory. Thanks to Nick Hooey. For example:
ack –ignore-dir=t/subsystem/test-data
Added –invert-file-match switch to negate the sense of the
-g/-G switches. Thanks, Lars Dieckow.
Updated the README to Markdown format. Thanks to Mark Szymanski
for the idea.
Added docs for -r, -R, –recurse options.
Added new switch –color-lineno and environment variable `ACK_COLOR_LINENO`,
which allow setting the line number color. (Marq Schneider)
Added option –show-types to output the types that ack considers
a file to have. (Torsten Blix)
`ack –count –no-filename regex` doesn’t output a list of numbers but a
sum of all occurences. This is NOT what grep does but is the more sensible
behavior.

Run PHP tests in your Perl test suite

August 17, 2010 Code craft, CPAN, Perl 5 5 comments

Sometimes you’ve got a big codebase that isn’t just Perl. Maybe you’ve got PHP mixed in with it, and you want to test the PHP along with all the Perl code, too. Perl’s *prove* program doesn’t care if the testing results it parses are from Perl, PHP or even static files, so long as they’re in the [TAP](http://testanything.org/) format. However, actually getting *prove* to run those PHP programs takes a little doing. Fortunately, Test::Harness 3.xx has hooks for source handlers.
David Wheeler has written about running PostgreSQL tests under *prove* [in his blog](http://justatheory.com/computers/programming/perl/tap-parser-sourcehandler.html) and I stole from his code shamelessly to create [TAP::Parser::SourceHandler::PHP](http://search.cpan.org/dist/TAP-Parser-SourceHandler-PHP/), released to the CPAN this morning.
So now, to run the Perl .t files and the PHP .phpt files all in one swell foop, here’s what we do at work:

prove -r 
-I/home/alester/proj/Lib 
--source=Perl --ext=.t 
--source=PHP 
--ext=.phpt 
--php-option=include_path=/home/alester/proj/Class 
--php-option=extension=.phpt

That --source=PHP tells *prove* to load up TAP::Parser::SourceHandler::PHP. The --php-option tells *prove* to pass those options through to the SourceHandler. If we had PostgreSQL tests or MySQL tests, we could use the SourceHandlers for those that David Wheeler has written as well.
Now we can test everything all in one run, and we get all the benefits of Test::Harness 3.xx, like parallel tests and TAP archiving and so on.