Willie Singletary
Welcome to Philadelphia!
This is a portion of a notice that was posted at my polling place this morning:
VOTES FOR THIS CANDIDATE WILL NOT BE COUNTED
DEAR VOTERS:
Willie Singletary, candidate for Democratic Council At-Large,
has been removed from the Primary Ballot by Court Order.
Although his name appears on the ballot, votes for this
candidate will not be counted because he was convicted of two
Class E felonies by the United States District Court for the
Eastern District of Pennsylvania, which bars his candidacy under
Article 2, Section 7 of the Pennsylvania Constitution.
[Other articles in category /politics]
permanent link
Super-obscure bug in my code
Say $dt is a Perl DateTime
object.
You are allowed to say
$dt->add( days => 2 )
$dt->subtract( days => 2 )
Today Jeff Boes pointed out that I had written a program that used
$dt->add({ days => 2 })
which as far as I can tell is not documented to work. But it did
work. (I wrote it in 2016 and would surely have noticed by now if it
hadn't.) Jeff told me he noticed when he copied my code and got a
warning. When I tried it, no warning.
It turns out that
$dt->add({ days => 2 })
$dt->subtract({ days => 2 })
both work, except that:
The subtract call produces a warning (add doesn't! and Jeff
had changed my add to subtract )
If you included an end_of_month => $mode parameter in the
arguments to subtract , it would get lost.
Also, the working-ness of what I wrote is a lucky fluke. It is
undocumented (I think) and works only because of a quirk of the
implementation. ->add passes its arguments to
DateTime::Duration->new , which passes them to
Params::Validate::validate . The latter is documented to accept
either form. But its use by DateTime::Duration is an undocumented
implementation detail.
->subtract works the same way, except that it does a little bit of
preprocessing on the arguments before calling
DateTime::Duration->new . That's where the warning comes from, and
why end_of_month won't work with the hashref form.
(All this is as of version 1.27. The current version is 1.51.
Matthew Horsfall points out that 1.51 does not raise a warning,
because of a different change to the same interface.)
This computer stuff is amazingly complicated. I don't know how anyone
gets anything done.
[Other articles in category /prog/bug]
permanent link
|