belg4mit's Friends' Journals http://use.perl.org/~belg4mit/journal/friends/ belg4mit's Friends' use Perl Journals en-us use Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners. 2012-01-25T02:12:56+00:00 pudge pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 belg4mit's Friends' Journals http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~belg4mit/journal/friends/ use Perl; Shutting Down Indefinitely http://use.perl.org/~pudge/journal/40525?from=rss <p>See <a href="http://use.perl.org/article.pl?sid=10/09/08/2053239">here</a>.</p> pudge 2010-09-08T22:07:47+00:00 useperl use Perl; http://use.perl.org/~pudge/journal/40493?from=rss <p>I am no longer working for Slashdot/Geeknet as of September 30. I am actively seeking new employment. Unless you want to hire me, you don't need to care, unless you also care about <a href="http://use.perl.org/">use Perl;</a>, because it has been generously hosted by Geeknet since I started the site over 10 years ago, shortly after I was hired by Andover.Net to work on Slashdot.</p><p>Long story short, I have not done much with the site in recent years, so my options at this point are to do nothing; migrate the site to a new server and keep it running as-is; or take the data and do something with it on a new site. Or something I haven't thought of.</p><p>I am hereby accepting proposals for what to do with use Perl;. In short, I would like to donate it to someone who will give it a good home. If you're interested, give me your best pitch.</p><p>Cross-posted on <a href="http://pudge.net/glob/2010/08/use-perl.html">&lt;pudge/*&gt;</a>.</p> pudge 2010-08-11T23:34:11+00:00 journal Matt Trout, aka mst, is insane http://use.perl.org/~pudge/journal/40492?from=rss <p>Wow. I occasionally, but not too often, go into #perl. Very busy with family and life. So I go in today, and for no reason, <a href="http://www.trout.me.uk/">mst</a> bans me and tells me to not come back.</p><p>What's up with him being such an irrational dick?</p> pudge 2010-08-11T16:41:54+00:00 journal Summary of Celtics vs. Lakers NBA Finals History http://use.perl.org/~pudge/journal/40370?from=rss <p>There have been 60 NBA Finals. The Boston Celtics have won 17, and the Minneapolis/Los Angeles Lakers have won 15, which amounts to those teams winning more than half of all NBA Finals. This year, they play each other in the Finals again, making it 33 champions out of 61 being either the Lakers or the Celtics.</p><p>Additionally, 39 of the 61 Finals have included either the Lakers or the Celtics. Including this year, the Celtics and Lakers have played each other in the Finals a whopping 12 times (just under one-fifth of all Finals have been these two teams).</p><p>The Celtics have made 21 total Finals appearances, so have faced the Lakers more than half of the times they've been in the Finals. The Lakers have made 30 Finals appearances, facing the Celtics in two-fifths of those.</p><p>The Celtics won nine of those against the Lakers, which accounts for more than half of all their 17 championships. The Lakers' two victories over the Celtics came after the Celtics won their first eight encounters.</p><p>The longest streak without either team in the Finals was eight years from '92-'99. The longest streak <b>with</b> either the Lakers or Celtics in the Finals was 10 years, done twice (from '57-'66, in which the Celtics appears all 10 years, and the Lakers five of those; and '80-'89, in which the Lakers appeared eight times, the Celtics five).</p><p>The longest streak for one team appearing in the Finals was, as noted, Boston, in the 10 years from '57-'66. Boston won nine of those 10 years, including eight in a row (the longest winning streak from any one team) from '59-'66, and also won 10 in 12 years, from '57-'69.</p><p>The Lakers' longest appearance streak is "only" four, from '82-'85, winning twice; but they have also appeared three times in a row five additional times (including the current three-year streak). In two of those, they won all three years; in one, they lost all three.</p><p>The only other team to "threepeat" was the Bulls, winning three years in a row twice in eight years ('91-'98). No other team but the Celtics and Lakers have had four consecutive appearances. The only other team to have three consecutive appearances was the Knicks, losing all three from '51-'53.</p><p>The 2010 NBA Finals begin in Los Angeles on Thursday.</p><p>Cross-posted on <a href="http://pudge.net/glob/2010/05/summary-of-celtics-vs-lakers-nba-finals-history.html">&lt;pudge/*&gt;</a>.</p> pudge 2010-05-30T05:25:50+00:00 journal Unique http://use.perl.org/~pudge/journal/40329?from=rss <p>I wonder how long it will be before people start just putting together random letters for names of companies, bands, and so on, so they can be unique in Google searches.</p><blockquote><div><p>Your search - fobhwueufg8 - did not match any documents.</p></div></blockquote><p>^^ my new band name</p><p>(Hm, "Did Not Match Any Documents" would be a fun band name. Or the name of the debut album of the band fobhwueufg8.)</p><p>Cross-posted on <a href="http://pudge.net/glob/2010/04/unique.html">&lt;pudge/*&gt;</a>.</p> pudge 2010-04-26T17:45:28+00:00 journal My Slashroulette Videos http://use.perl.org/~pudge/journal/40290?from=rss <p>Today Slashdot did a spoof of Chatroulette, that we called Slashroulette. We prerecorded videos of ourselves and others. Here's five of the six I did (the sixth was me tuning the guitar, I didn't post that one on YouTube): <a href="http://www.youtube.com/watch?v=qHwz6sG37_Q">video 1</a>, <a href="http://www.youtube.com/watch?v=IQYgAxVo050">video 2</a>, <a href="http://www.youtube.com/watch?v=IlJBlObJnJY">video 3</a>, <a href="http://www.youtube.com/watch?v=GWxewYtRc48">video 4</a>, <a href="http://www.youtube.com/watch?v=TkVisbPXHVo">video 5</a>.</p><p>Cross-posted on <a href="http://pudge.net/glob/2010/04/my-slashroulette-videos.html">&lt;pudge/*&gt;</a>.</p> pudge 2010-04-02T05:15:16+00:00 journal Gone http://use.perl.org/~Ovid/journal/40243?from=rss <p>Like many others, I'm no longer posting here very much. You'll find my new technical journal at <a href="http://blogs.perl.org/users/ovid/">blogs.perl.org</a>. It's much shinier.</p><p> <a href="http://siteanalytics.compete.com/use.perl.org/">As you can see, use.perl visits have been dropping for a while</a> (blogs.perl.org is too new to show up on that search) and the <a href="http://use.perl.org/">front page of use.perl has been sadly neglected</a>. As for blogs.perl.org, after an initial rough start, <a href="http://blogs.perl.org/users/adam_kennedy/2009/12/migrating-from-useperlorg-to-blogsperlorg.html">plenty</a> <a href="http://blogs.perl.org/users/thefinalcut/2009/12/first-post-on-the-shiny-new-onion.html">of</a> <a href="http://blogs.perl.org/users/limbicregion/2009/11/goodbye-useperlorg-hello-blogsperlorg.html">people</a> are switching over and are very happy with the shiny.</p><p>I have fond memories of use.perl.org, but it's just too old and out-of-date. Come on over to our new platform and look around. Plus, <a href="http://github.com/davorg/blogs.perl.org/issues">tell us what you want changed about it</a>. (To be fair, while I was involved in the project to get it launched (mostly kibitzing and asking why things were stalled -- I'm such a marketroid<nobr> <wbr></nobr>:), the hands-on work was Dave Cross, Aaron Crane and the wonderful folks at <a href="http://www.sixapart.com/">SixApart</a>.)</p> Ovid 2010-03-14T08:02:43+00:00 journal dumping environment etc from batch perl script http://use.perl.org/~n1vux/journal/40205?from=rss <blockquote><div><p> <tt>use Data::Dumper;<br>print Dumper([&nbsp; &nbsp; &nbsp; &nbsp;# like<nobr> <wbr></nobr>...<br>&nbsp; &nbsp; &nbsp; &nbsp;{&nbsp; X=&gt;$^X},&nbsp; &nbsp;# which perl<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# but not fooled by #!<br>&nbsp; &nbsp; &nbsp; &nbsp;{V0 =&gt;&nbsp; "$]", # perl -v , ditto<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;V =&gt; $^V lt v5.9.0<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ? q(v).(join(q(.),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (map {ord}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; split(//,$^V))))<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : "$^V"}<nobr> <wbr></nobr>,<br>&nbsp; &nbsp; &nbsp; &nbsp;{ ENV =&gt; \%ENV} , # like env<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#&nbsp; but in actual context<br>&nbsp; &nbsp; &nbsp; &nbsp;{ INC =&gt;\%INC}&nbsp; , # incomparable<br>&nbsp; &nbsp; &nbsp; ]);</tt></p></div> </blockquote><p>The ugly version of V for Version is to handle 5.6-5.9 v strings and 5.10+ version objects without knowing which, if you don't want <code>$]</code> to mess up your syntax highlighting and don't want <code>\005 </code> to trip a terminal echoback string when it vString doesn't print.</p> n1vux 2010-02-24T05:37:29+00:00 journal My Netgear Router is Dumber Than It Thinks It Is http://use.perl.org/~pudge/journal/40163?from=rss <p>I upgraded the firmware on my Netgear router today and it wouldn't let me use the LAN IP I usually use for it, 10.0.1.1, because it thinks my ISP uses that subnet, because I set the router to read from my own internal DNS. Took me awhile to figure out <b>why</b> it thought what it did, because it didn't occur to me that it would care what DNS addresses I gave it.</p><p>Cross-posted on <a href="http://pudge.net/glob/2010/02/my-netgear-router-is-dumber-than-it-thinks-it-is.html">&lt;pudge/*&gt;</a>.</p> pudge 2010-02-07T02:09:27+00:00 journal Test::Class::Most http://use.perl.org/~Ovid/journal/40148?from=rss <a href="http://blogs.perl.org/users/ovid/2010/01/-package-sometestclass.html">Test::Class::Most</a>. Ovid 2010-01-31T19:25:10+00:00 journal Franchise Tag Whiners http://use.perl.org/~pudge/journal/40146?from=rss <p>There's a long line of players in the NFL who claim that it is a personal offense when their teams place the franchise tag on them.</p><p>These players are big fat babies.</p><p>The players agreed to the franchise tag for the owners, as a compromise. The players take advantage of everything available to them under the contract; why shouldn't the owners do the same?</p><p>Stop crying. Stop whining. Sure, you don't like it, but so what? Grow up. Those are the rules that you agreed to.</p> pudge 2010-01-30T18:52:27+00:00 journal Testing with PostgreSQL http://use.perl.org/~Ovid/journal/40145?from=rss <p>My new personal project has a PostgreSQL database. <a href="http://blogs.perl.org/users/ovid/2010/01/testing-postgresql.html">Here's how I'm handling testing</a>.</p> Ovid 2010-01-30T16:22:57+00:00 journal Roles without Moose? http://use.perl.org/~Ovid/journal/40127?from=rss <p> <a href="http://blogs.perl.org/users/ovid/2010/01/roles-without-moose.html">Milliseconds are important</a>.</p> Ovid 2010-01-25T14:04:31+00:00 journal Unless what? http://use.perl.org/~Ovid/journal/40103?from=rss <p> <a href="http://blogs.perl.org/users/ovid/2010/01/unless-what.html">Unless what?</a> </p> Ovid 2010-01-15T11:47:53+00:00 journal Dear Recruiters http://use.perl.org/~Ovid/journal/40100?from=rss <p> <a href="http://blogs.perl.org/users/ovid/2010/01/dear-recruiters.html">Dear Recruiters</a> </p> Ovid 2010-01-13T13:06:11+00:00 journal Moving 32-bit Intel Perl to Mac OS X 10.6 http://use.perl.org/~pudge/journal/40097?from=rss <p>Dear Google,</p><p>When you move a 32-bit x86 perl installation to a 64-bit Mac OS X 10.6 environment, you should edit $ARCH/Config_heavy.pl and add "-arch i386" to lddlflags, ldflags, and ccflags. The compiler and tools in Mac OS X 10.6 assume 64 bits unless you explicitly tell it otherwise, but some 32-bit installs don't bother putting in an -arch flag, because at the time it wasn't necessary.</p><p>Cross-posted on <a href="http://pudge.net/glob/2010/01/moving-32bit-intel-perl-to-mac-os-x-106.html">&lt;pudge/*&gt;</a>.</p> pudge 2010-01-12T17:39:58+00:00 journal Next QA Hackathon -- What Do You Need? http://use.perl.org/~Ovid/journal/40093?from=rss <p> <a href="http://blogs.perl.org/users/ovid/2010/01/next-qa-hackathon----what-do-you-need.html">Read about the next QA Hackathon</a>.</p> Ovid 2010-01-12T11:37:14+00:00 journal Most Popular Testing Modules - January 2010 http://use.perl.org/~Ovid/journal/40086?from=rss <p> <a href="http://blogs.perl.org/users/ovid/2010/01/most-popular-testing-modules---january-2010.html">Most popular testing modules as of January 2010</a> </p> Ovid 2010-01-07T21:46:46+00:00 journal Cool Things in Perl 6: Subsets http://use.perl.org/~Ovid/journal/40072?from=rss <p> <a href="http://blogs.perl.org/users/ovid/2010/01/cool-things-in-perl-6.html">They're going to be a lot of fun</a>.</p> Ovid 2010-01-04T13:11:31+00:00 journal Perl 6 Config::INI parser on github http://use.perl.org/~Ovid/journal/40060?from=rss <p> <a href="http://blogs.perl.org/users/ovid/2009/12/perl-6-configini-on-github.html">Details here</a>.</p> Ovid 2009-12-30T17:48:47+00:00 journal Improve My Perl 6! http://use.perl.org/~Ovid/journal/40051?from=rss <p> <a href="http://blogs.perl.org/users/ovid/2009/12/improve-my-perl-6.html">Collaborative filtering (user recommendations) in Perl 6</a>.</p> Ovid 2009-12-24T11:29:45+00:00 journal Gitpan languages http://use.perl.org/~Ovid/journal/40036?from=rss <p>What? You didn't know that <a href="http://blogs.perl.org/users/ovid/2009/12/gitpan-languages.html">SOAP::Lite was written in Visual Basic</a>?</p> Ovid 2009-12-18T14:15:32+00:00 journal Atom Feed Help http://use.perl.org/~Ovid/journal/40029?from=rss <p> <a href="http://blogs.perl.org/users/ovid/2009/12/atom-feed-help.html">Atom feed help requested</a> </p> Ovid 2009-12-17T10:40:35+00:00 journal MySQL and Oracle http://use.perl.org/~Ovid/journal/40020?from=rss <p> <a href="http://blogs.perl.org/users/ovid/2009/12/mysql-and-oracle.html">MySQL and Oracle</a>. (Despite teething pains, blogs.perl.org is holding up quite well on the new server)</p> Ovid 2009-12-14T12:56:02+00:00 journal What's In A Name? http://use.perl.org/~Ovid/journal/40012?from=rss <p> <a href="http://blogs.perl.org/users/ovid/2009/12/whats-in-a-name.html">The actual entry is at blogs.perl.org</a>. However, here's a few extra notes about that site:</p><p>It's much more stable than last time. Aaron moved it to a new server and Dave set up MT. <a href="http://github.com/davorg/blogs.perl.org">The templates are on github</a> along with <a href="http://github.com/davorg/blogs.perl.org/issues">an issue tracker</a>.</p><p>Barbie talked with Dave and myself at the London Perl Workshop (lpw2009) about the site and I wrote down all of his suggestions and they've now been added to the issue list. We look forward to more people trying it out and <a href="http://blogs.perl.org/users/dave_cross/2009/12/what-can-we-improve.html">Dave has a post asking for more feedback</a>. Also, he's aware that several people only made it partway through the registration process. Drop him a line if you're affected and he'll clear it up for you.</p><p>I can't thank Dave, Aaron and SixApart for all they're doing to create a modern blogging platform for us.</p> Ovid 2009-12-12T12:24:54+00:00 journal Regex Captures in Debugger http://use.perl.org/~Ovid/journal/39990?from=rss <p>Stumbled across this weird behavior today. Took a while to debug it. In the debugger, I'm not seeing the "dollar digit" regex capture variables set, even though the regex matches.</p><blockquote><div><p> <tt>$ perl -de 1<br> <br>Loading DB routines from perl5db.pl version 1.3<br>Editor support available.<br> <br>Enter h or `h h' for help, or `man perldebug' for more help.<br> <br>main::(-e:1):&nbsp; &nbsp;1<br>&nbsp; DB&lt;1&gt; ($foo) = ('abcd' =~<nobr> <wbr></nobr>/(bc)/)<br> <br>&nbsp; DB&lt;2&gt; x $1<br>0&nbsp; undef<br>&nbsp; DB&lt;3&gt; x $foo<br>0&nbsp; 'bc'</tt></p></div> </blockquote><p>Is this documented? I can't find it.</p><p> <strong>Update</strong>: Rafael explained it. The digit variables are lexically scoped. That's why you can assign to a package variable in a debugger, but not a lexical.</p><blockquote><div><p> <tt>&nbsp; DB&lt;6&gt;&nbsp; 'abcd' =~<nobr> <wbr></nobr>/(bc)/ &amp;&amp; print $1<br>bc</tt></p></div> </blockquote> Ovid 2009-12-08T14:02:43+00:00 journal The Implications of the Bug http://use.perl.org/~Ovid/journal/39986?from=rss <p> <a href="http://use.perl.org/~mscolly/">mscolly</a> correctly identified <a href="http://use.perl.org/~Ovid/journal/39985">the SQL bug I posted</a>. Sadly, no one discussed the implications of this bug and I think they're the most interesting part of this. Essentially, it comes down to the following:</p><blockquote><div><p> <tt>SELECT&nbsp; &nbsp; first_name,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last_name,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; order_date,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SUM(price) AS total&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- what if there's no price?<br>FROM&nbsp; &nbsp; &nbsp; customer<br>LEFT JOIN orders&nbsp; &nbsp; &nbsp;ON customer.id = orders.customer_id<br>LEFT JOIN order_item ON orders.id&nbsp; &nbsp;= order_item.order_id<br>GROUP BY&nbsp; first_name, last_name, order_date<br>HAVING&nbsp; &nbsp; total &lt; 15&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--&nbsp; what does NULL &lt; 15 evalute to?<br>ORDER&nbsp; &nbsp; &nbsp;BY order_date ASC;</tt></p></div> </blockquote><p>The proper solution (as mscolly pointed out) is to change the "SUM" line to this:</p><blockquote><div><p> <tt>COALESCE( SUM(price), 0 ) AS total</tt></p></div> </blockquote><p>The English language, as we know, is ambiguous. If you boss had come in and asked for all customers whose orders (more accurately, whose orders with order items) totaled less than &#163;15 pounds, then the above query would have actually been correct, but another programmer coming along to maintain it could be forgiven for thinking it's in error. If you ever write SQL which is likely to produce NULLs (e.g., outer joins), you should explicitly handle that case if you actually do anything with those NULLs.</p><p>But in this case, "customers whose orders total less than &#163;15" is significantly different in meaning than "customers who spent less than &#163;15" and the latter is what we want, but the former is what we have. While the above code <em>seems</em> logical, it gives a logically incorrect answer because it omits customers without orders (or order items), even though they're clearly intended. However, NULLs make it very difficult to identify what you actually mean because the database can't know why something is NULL.</p><p>Now consider a simpler, yet silly, example:</p><blockquote><div><p> <tt>SELECT first_name<br>FROM&nbsp; &nbsp;employee<br>WHERE&nbsp; salary &gt; 50000;</tt></p></div> </blockquote><p>What happens if the <tt>salary</tt> field is NULL? You'll get a list of employees whose <em>known</em> salary is NOT NULL. Why might they not have a salary? Maybe they're an hourly employee and the <tt>salary</tt> field is not applicable. Maybe they're the CEO and he doesn't think you need to know his salary. Maybe they're an ex-employee and they have no salary.</p><p>Taking this a bit further, imagine that all employees in the table are current and all have salaries (no hourly workers), but the <tt>salary</tt> field is still sometimes NULL because the board of directors doesn't want you to know their salaries. With me so far? In this scenario, it is the case that everyone has a salary; you just don't know what some of them are. So here's the kicker:</p><blockquote><div><p> <tt>SELECT first_name<br>FROM&nbsp; &nbsp;employee<br>WHERE&nbsp; salary = salary;</tt></p></div> </blockquote><p>That won't return anyone on the board of directors, even though you <em>know</em> they have a salary. Furthermore, most would think it's self-evident that <em>p&nbsp;=&nbsp;p</em>, but in three value logic of databases, this is sometimes true and sometimes false. Heck, because of this, the following does not always evaluate correctly, even though we would <em>think</em> it does:</p><blockquote><div><p> <tt>SELECT service_id,<br>&nbsp; &nbsp; CASE WHEN master_brand_id =&nbsp; master_brand_id THEN '='<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHEN master_brand_id != master_brand_id THEN '!='<br>&nbsp; &nbsp; END AS 'comparison'<br>FROM service</tt></p></div> </blockquote><p>Sure, you say, but you're comparing something to itself. You don't do that in the real world. No? So look at this:</p><blockquote><div><p> <tt>SELECT s.service_id,<br>&nbsp; &nbsp; CASE WHEN m.master_brand_id =&nbsp; s.master_brand_id THEN '='<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHEN m.master_brand_id != s.master_brand_id THEN '!='<br>&nbsp; &nbsp; END AS 'comparison'<br>FROM service&nbsp; &nbsp; &nbsp; s<br>&nbsp; &nbsp; &nbsp;master_brand m</tt></p></div> </blockquote><p>If the <tt>s.master_brand_id</tt> is allowed to be NULL, than the <tt>comparison</tt> field will always have a NULL value when <tt>s.master_brand_id</tt> is NULL. It's easy to debug in this simple example, but what if that was a subquery? It <em>looks</em> fine, but it all breaks down in the presence of NULL values.</p><p>I didn't start with that example because people would say it's silly, but starting with the "order" example shows how NULLs in databases can return logically incorrect data and the reduction down to the simple <em>p&nbsp;=&nbsp;p</em> case not holding shows why this happens.</p><p>At this point, I can see people saying "yeah, but we already know that about databases." And this is true. It's well-known that certain types of queries can generate NULLs even though there are no NULL values in the database. Regrettably, many people assume the database logic is, well, logical. The <em>p = p</em> failure is a strong rebuttal, but I suppose some people assume that hitting themselves in the head with a hammer is normal.</p><p>If you really want to have some fun, <a href="http://thoughts.j-davis.com/2009/08/02/what-is-the-deal-with-nulls/">read this blog entry about NULL values</a>. In the comments, the author even explains how to deal with NULLs in outer joins, but it requires a relational database (very few databases really are) and that people understand what first normal form is really about. (If you think you know, please define "atomic values" in the comments below).</p><p>I wonder how database design would look today if, instead of 3VL, databases threw an exception when you tried to apply an operator or aggregation ('=', '+', 'SUM', etc.) to NULL values?</p><p>Note: I've discussed <a href="http://use.perl.org/~Ovid/journal/27927">the problem with NULL values before</a>, but in realizing I had a better real-world example, I thought it would make more sense to readers.</p> Ovid 2009-12-07T15:38:13+00:00 journal Find the bug (sql) http://use.perl.org/~Ovid/journal/39985?from=rss <p> <strong>Update</strong>: You can ignore the <tt>order_date</tt> below. It's a red herring and I probably should have left it out, but I had liked the fact that by putting it in the query, I added more complexity, thus making the real bug more difficult to spot.</p><p>Assume you're a diligent programmer. You've designed your database carefully. Foreign constraints are correct, you have no null columns and you've kept a nice, simple design. Now your boss wants you to provide a list of all customers who've spent less than &#163;15 on your Web site because you want to offer them a special promotion. Here's the SQL you've written:</p><blockquote><div><p> <tt>SELECT&nbsp; &nbsp; first_name,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last_name,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; order_date,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SUM(price) AS total<br>FROM&nbsp; &nbsp; &nbsp; customer<br>LEFT JOIN orders&nbsp; &nbsp; &nbsp;ON customer.id = orders.customer_id<br>LEFT JOIN order_item ON orders.id&nbsp; &nbsp;= order_item.order_id<br>GROUP BY&nbsp; first_name, last_name, order_date<br>HAVING&nbsp; &nbsp; total &lt; 15<br>ORDER&nbsp; &nbsp; &nbsp;BY order_date ASC;</tt></p></div> </blockquote><p>The two left joins are there because a customer may never have placed an order before. Heck, they may have started an order but not added any items to it. The 'having' statement is required because you generally can't use aggregates in where clauses.</p><p>You run the SQL and hand-check the results very carefully. Choosing a random sampling of customers returned, you verify that none of them have spent more than &#163;15 on your site. Nonetheless, you have a bug. What is it? What are the implications of the bug?</p> Ovid 2009-12-07T07:43:40+00:00 journal Pitfalls in Converting Base Classes to Roles http://use.perl.org/~Ovid/journal/39977?from=rss <p>I should have responded to this a while ago, but didn't. Basically, nothingmuch <a href="http://blog.woobling.org/2009/10/roles-and-delegates-and-refactoring.html">has a blog post responding to some of my comments about roles</a> and it's worth reading. However, there's one problematic bit:</p><p><div class="quote"><p>If you take a working multiple inheritance based design and change every base class into a role, it will still work. Roles will produce errors for ambiguities, but if the design makes sense there shouldn't be many of those to begin with. The fundamental structure of the code hasn't actually changed with the migration to roles.</p></div><p>For the majority of code bases I see, this is doubtless true. However, I tend to get jobs where I work on large code bases. For example, just looking at our lib/ directory:</p><blockquote><div><p> <tt>$ find lib/ -name '*.pm' | wc -l<br>652</tt></p></div> </blockquote><p>That's not huge, but it's not particularly small, either. And it doesn't count our various scripts, tests, schemas, etc. So let's say I want to add a boolean attribute to an object and said attribute must be persisted in the database and must be readable/writeable via our API. That's a single attribute. Just one. I need to:</p><ul> <li>Write the database migration level</li><li>Update our RelaxNG schemas</li><li>Update our data extractors (extracts data from XML docs)</li><li>Add the column to our domain objects</li><li>Add the column to our resultsource classes</li><li>Possibly add the column to resultset classes</li><li>Update our XML builders</li><li>Write tests</li><li>And possibly more, depending on why we're adding the attribute</li></ul><p>That's a lot of work, but adding a single boolean attribute can take me an hour or two if I'm not interrupted. And, believe it or not, this is easier than it used to be. And, believe it or not, much of that isn't the silly grunt work that it appears to be because there's a lot of stuff that is hard to automate away safely (my unreleased <a href="http://www.google.co.uk/search?hl=en&amp;ei=ZAcZS4HHC8-24Qbtu4nmAg&amp;sa=X&amp;oi=spell&amp;resnum=0&amp;ct=result&amp;cd=1&amp;ved=0CAYQBSgA&amp;q=site%3Ause.perl.org+inurl%3AOvid+Bermuda&amp;spell=1">Bermuda</a> project was an attempt to do this). Some can and we've managed some of it, but not all.</p><p>In short, we have a complicated code base that has decades of programmer hours in it. We used to rely a lot on multiple inheritance, despite the well-known issues with MI. Now let's revisit the key sentence in nothingmuch's post: "If you take a working multiple inheritance based design and change every base class into a role, it will still work."</p><p>To nothingmuch's credit, he does point out that ambiguities will cause errors, but there's a lot more to it than that. As projects grow organically, things often get put into incorrect spots. We had all sorts of code shoved into base classes that our derived classes shouldn't inherit from, but did. Since tests tend to be written against expectations, it's easy to not write tests for things you don't expect.</p><p>The reason classes sometimes have inappropriate behavior is because abusing inheritance tends to mean that you're having classes manage both responsibilities and cross-cutting concerns. I've found that base classes often had to be broken up into two or more roles (nothingmuch has a great example of Test::Builder doing the same thing and that's a <em>small</em> code base). That can get really annoying when you find that each role requires the same private method and you're trying to figure out where to put it. As you juggle things like this, behaviors <em>will</em> change and you had better have a good test suite to catch them.</p><p>There's another, more subtle problem. Imagine that you have the following (it gets much worse when MI is involved):</p><blockquote><div><p> <tt>AbstractParent<br>&nbsp; &nbsp; &nbsp;^<br>&nbsp; &nbsp; &nbsp;|<br>AbstractChild<br>&nbsp; &nbsp; &nbsp;^<br>&nbsp; &nbsp; &nbsp;|<br>ConcreteClass</tt></p></div> </blockquote><p>In ConcreteClass we have this:</p><blockquote><div><p> <tt>sub clean_the_kitchen {<br>&nbsp; &nbsp; my $self = shift;<br>&nbsp; &nbsp; $self-&gt;SUPER::clean_the_kitchen;<br>&nbsp; &nbsp; $self-&gt;mop_the_floor;<br>&nbsp; &nbsp; return $self;<br>}</tt></p></div> </blockquote><p>What happens with that <tt>SUPER::</tt> call? If it's only in AbstractParent, you're fine, but if it's also in AbstractChild, converting AbstractChild into a role will break your code. Further, it might break your code in very subtle ways that are hard to detect. This might seem uncommon, but we actually had this happen quite a bit when we were converting over to roles. This means that our concrete class methods needed to be written as:</p><blockquote><div><p> <tt>after 'clean_the_kitchen' =&gt; sub {<br>&nbsp; &nbsp; my $self = shift;<br>&nbsp; &nbsp; $self-&gt;mop_the_floor;<br>&nbsp; &nbsp; return $self;<br>};</tt></p></div> </blockquote><p>That's easy to get wrong and, frankly, method modifiers such as <tt>before</tt>, <tt>after</tt> and <tt>around</tt> generally make me feel uncomfortable. Like role method aliasing and excluding, they're code smells suggesting your design needs work. However, as we were trying for "the simplest thing that could possibly work", we went with this with the intent of revisiting it later. We still haven't revisited it. We have work to do.</p><p>In short, converting bases classes to roles and resolving composition errors is often enough for small code bases, but as code bases get large and complex, it's much harder. There are plenty of pitfalls and they're not always obvious. Plus, despite having excellent code coverage for tests, you probably don't have great path coverage (few do). This means that switching from base classes to roles can easily introduce behavioral changes that you haven't been expecting.</p><p>See also <a href="http://use.perl.org/~Ovid/journal/38880">Tips For Converting Base Classes Into Roles</a>. <small>(gosh, tags would be useful)</small> </p> Ovid 2009-12-04T13:32:44+00:00 journal Why Should I Program in $Language? http://use.perl.org/~Ovid/journal/39967?from=rss <p>For the developer evaluating programming languages the question of which languages to learn rarely involves "can this language do what I want it to do?" This is because virtually all programming languages (except ANSI SQL, if you consider it a language) are Turing Complete. Instead, what I see, over and over, is discussions over two things:</p><ul> <li>Can I get a job in this language?</li><li>Do I like this language?</li></ul><p>So consider COBOL. Yes, I can get a job in that language, but do I like it? No. C is the same way for me. There are plenty of jobs out there, but I loathe how close it is to the metal because I like solving problems, not worrying about how to reallocate memory for a resized string. So if I were to assert that either COBOL or C is dead, that might be true<nobr> <wbr></nobr>... for me. If I assert they're dead on the basis of job stats, I'd be sorely mistaken.</p><p>Naturally, when I hear the old "Perl is dead" saw, I know the job stats and I know they're not referring to them. However, what they invariably refer to is the "buzz" around Perl, measured by TIOBE, Google Trends and other tools. The buzz can be important, but at the end of the day, buzz won't matter if the tool is useful enough. Consider how much people complain about Perl's sigils. Now look at the following code:</p><blockquote><div><p> <tt>$cssClass = "";<br>if ( $element-&gt;isOpen() ) {<br>&nbsp; &nbsp; $cssClass = ' class="selected"';<br>}<br>if ( !$element-&gt;isHiddenInNavigation() ) {<br>&nbsp; &nbsp; $filepath = $element-&gt;getId() . ".html";<br>&nbsp; &nbsp; if ( substr( $element-&gt;getFilePath(), 0, 4 ) == 'http' ) {<br>&nbsp; &nbsp; &nbsp; &nbsp; $filepath = $element-&gt;getFilePath();<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; $result<nobr> <wbr></nobr>.= '&lt;li'<br>&nbsp; &nbsp; &nbsp; . $cssClass<br>&nbsp; &nbsp; &nbsp; . '&gt;&lt;a href="'<br>&nbsp; &nbsp; &nbsp; . $filepath . '"&gt;'<br>&nbsp; &nbsp; &nbsp; . $element-&gt;getLabel() . '&lt;/a&gt;'<br>&nbsp; &nbsp; &nbsp; . $this-&gt;generate( $element-&gt;getChildren() ) . '&lt;/li&gt;';<br>}</tt></p></div> </blockquote><p>Assuming that has no errors, we know that it <em>looks</em> like Perl, but isn't (look closely if you don't see it). That's PHP code. So though people whine about sigils in Perl, you've got the same issue with PHP, but why has PHP <em>crushed</em> us in the Web space? Well, for one thing, people seem far happier with modphp than mod_perl. It's very easy to develop and deploy apps despite its inconsistencies and lacking many of the useful features that Perl 5 has.</p><p>A second issue, however, is the one which will continue to keep Perl 5 sneered at:</p><blockquote><div><p> <tt>public function setHiddenInNavigation($hideInNavigation) {<br>&nbsp; &nbsp; return $this-&gt;hideInNavigation = $hideInNavigation;<br>}</tt></p></div> </blockquote><p>That's PHP, too. Until we can make Perl 5 code that clean and simple <em>and in the core</em>[1], we'll continue to be sneered at. It's embarrassing to read through PHP code and, once again, sigh at basic, basic things Perl 5 is missing (yes, PHP is missing many things too, but I'll bet most 9 to 5 programmers would take method signatures over closures any day of the week).</p><p>So really, programmers <em>are</em> asking if a language can do what they want it to do; at least on a syntax level. That's because syntax is a large part of the aesthetic appeal of a language.</p><p>So in answer to the question "Why Should I Program in $Language?", what the language can do (functionally, not syntax!) isn't really the issue. Nor is the "are there jobs?" because we know there are plenty of Perl jobs out there (not in all areas, though). The real question is "will I like it?" and from the numerous Perl hate posts, this is very much an open question but Perl largely has itself to blame.</p><p> <small>1. We have a better object system than you do! Just install Moose (but be aware that it might have backwards-incompatible changes in a few months). Oh, to install it, you just need to configure CPAN. What? You don't have root? Here's how to configure CPAN to install in a local directory. And be aware that Module::Build and ExtUtil::MakeMaker take different arguments, and don't forget that<nobr> <wbr></nobr>...</small> </p> Ovid 2009-12-01T14:27:17+00:00 journal