<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Keith's Web Blog RSS Feed</title>
<language>en-us</language>
<link>http://www.keithwatanabe.net/index.php</link>
<description>Keith Watanabe's Website</description>
<item>
<title>mod_perl DSO installation</title>
<link>http://www.keithwatanabe.net/blogs/2004/2/12/75dd605e1405c3f214cb360377cfb599.html</link>
<description><![CDATA[perl Makefile.PL USE_APXS=1 WITH_APXS=/usr/local/apache/bin/apxs EVERYTHING=1 --enable-EAPI
make
make install

Be sure to change the WITH_APXS location depending on your apache root directory location.]]></description>
<pubDate>Thu, 12 Feb 2004 13:21:44 -0700</pubDate>
<guid>http://www.keithwatanabe.net/blogs/2004/2/12/75dd605e1405c3f214cb360377cfb599.html</guid>
</item>
<item>
<title>HTML::Mason & Apache::Request</title>
<link>http://www.keithwatanabe.net/blogs/2004/8/30/437913452914dce6568f8ac5e2d061e9.html</link>
<description><![CDATA[Had a problem involving getting HTML::Mason to work with Mod_perl.  The issue was that despite having mod_perl installed, you need another library that really isn't talked about much.  That library is libapreq.  I'm a little surprised that the mod_perl guys haven't integrated this into the regular mod_perl distribution, but I guess it's just an extension at this point.  But this library is a C/XS library that has Apache::Request and Apache::Cookie interfacing to the actual Apache C libraries.  In turn, this makes the routines for accessing apache requests and cookies faster.

HTML::Mason allows the user to either choose the normal CGI.pm module or Apache::Request.pm for handling these types of routines.  With Apache::Request.pm, there is less memory usage and faster access.  Hence, I chose this path.

However, the basic libapreq install off of CPAN is a little buggy.  Instead, you need to utilize the cvs repository to get the version with the corrected makefiles, etc.:

cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic login
CVS password: anonymous
cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic co httpd-apreq

as I am using mod_perl version 1, i'm going with this version.  after grabbing it, just run perl Makefile.pl & make & make install.  The good thing is that it should test properly so you probably want to run make test on top of that.]]></description>
<pubDate>Mon, 30 Aug 2004 22:59:05 -0600</pubDate>
<guid>http://www.keithwatanabe.net/blogs/2004/8/30/437913452914dce6568f8ac5e2d061e9.html</guid>
</item>
<item>
<title>Storable's Many Uses</title>
<link>http://www.keithwatanabe.net/blogs/2005/5/23/79c0f830142e169b5054e43c2cc7a433.html</link>
<description><![CDATA[Found an interesting copying technique when you have a large data structure that contains code references.  Use storable's dclone method:

use Storable;

# these lines are necessary for the code refernces to be copied; also it only works for certain versions.  

$Storable::Deparse = 1;
$Storable::Eval = 1; 

%my::data:structure = %{Storable::dclone(\%your:data:structure)};

this allows me to replicate the two data structures.  i encountered a problem where if i just tried to copy one hash to another like:

%my:data::structure = %your::data::structure;

that you would encounter a problem when dealing with references (not just code references).  both are pointing to the same spot in memory, so your copy, if you want to localize it, won't work without a little aid.]]></description>
<pubDate>Mon, 23 May 2005 21:04:57 -0600</pubDate>
<guid>http://www.keithwatanabe.net/blogs/2005/5/23/79c0f830142e169b5054e43c2cc7a433.html</guid>
</item>
<item>
<title>interesting bit of perl</title>
<link>http://www.keithwatanabe.net/blogs/2005/8/18/4ebf4991fed8fcb05834e352c8e1510d.html</link>
<description><![CDATA[#!/usr/bin/perl  <br />
<br />
my @first = qw( Reina Norika Kaori Ryoko Shiho Aya Hitomi ); <br />
my @last = ( 'Miyauchi', 'Fujiwara', 'Kawai', 'Yonekura', undef, 'Matsuura', 'Kuroki' );  <br />
@names{ @first } = @last;  <br />
print &quot;$_ is $names{$_}\n&quot; foreach sort keys %names;  <br />
<br />
my @hotties = ( 'Naoko Kido', 'Michiyo Seki', 'Hisaki Nakamura', 'Shoko Kanemura', 'Keiko Iino' );  <br />
@h{ @hotties } = (1) x @hotties;  print &quot;$_ is $h{$_}\n&quot; foreach sort keys %h;]]></description>
<pubDate>Thu, 18 Aug 2005 11:12:22 -0600</pubDate>
<guid>http://www.keithwatanabe.net/blogs/2005/8/18/4ebf4991fed8fcb05834e352c8e1510d.html</guid>
</item>
<item>
<title>'our' is a good thing</title>
<link>http://www.keithwatanabe.net/blogs/2005/9/20/f6371b366818965cdaab55b26cb82ce8.html</link>
<description><![CDATA[the 'our' scope indicator in perl helps eliminate namespace issues easily so that you don't have to fully qualify global variables in packages.  for instance:

package myPackage;

use yourPackage;
use strict;

our @ISA = qw(yourPackage);

in the past, you'd be forced to fully qualify the @ISA variable.  here, you're able to reduce the amount of text as 'our' appends the variable name to the namespace the item is being declared.  also, it helps eliminate annoying warnings related to variables only declared once.]]></description>
<pubDate>Tue, 20 Sep 2005 13:36:28 -0600</pubDate>
<guid>http://www.keithwatanabe.net/blogs/2005/9/20/f6371b366818965cdaab55b26cb82ce8.html</guid>
</item>
<item>
<title>Test::Unit.pm unit testing framework</title>
<link>http://www.keithwatanabe.net/blogs/2005/9/27/150c7ad9397b30c607f5470c2e598748.html</link>
<description><![CDATA[this is a nice, little framework that you can use for building either OOP or scripted tests.  the basics:

use Test::Unit::Procedural;

create_suite();
run_suite();

sub test_comparison
{
  $a = 1;
  $b = 1;
  $c = 2;
  print "$a == $b\n";
  assert($a == $b);
  print "$b == $c\n";
  assert($b == $c\n";
}

this will create a test suite based on subroutines you define here.  the most important elements are the "assert" function calls which test for boolean cases.  if a test fails, the script will die.  i like this because it does exactly what you need and can be used to test in bulk large numbers of things like data objects, etc.]]></description>
<pubDate>Tue, 27 Sep 2005 16:32:07 -0600</pubDate>
<guid>http://www.keithwatanabe.net/blogs/2005/9/27/150c7ad9397b30c607f5470c2e598748.html</guid>
</item>
<item>
<title>Java Is NOT An Agile  Language</title>
<link>http://www.keithwatanabe.net/blogs/2007/8/7/9fd8a694e22bb98e7c67f3707bcf2279.html</link>
<description><![CDATA[My big boss asked me why my side of the project has been taking so long.  Why would a business layer be so hard to code up?  Why is the testing ridiculously slow?<br />
<br />
My answer: Java doesn't help this.<br />
<br />
Perhaps, it's my level of expertise in the language, but after dealing with this project, I've come to realize just how HEAVY Java can be.  I haven't had a chance to work in detail with the latest version, so I can't say that some of the newer features have made it better (I'm sure it has, but there are still deficiencies in the language).  It could be my lack of experience with Eclipse.  Maybe I'm not utilizing the right plugins and doing far too much &quot;hand coding&quot; in terms of boilerplate code.<br />
<br />
No, the problem is that the language is too bulky and takes itself too seriously.<br />
<br />
Read that statement again.  Especially the last part.<br />
<br />
Let me provide an example.<br />
<br />
Let's say you have a primitive type that's supposedly a char and is saved into the database as a number (0 or 1).  so in reality you need an int.  But let's say another object requires it either as an int or be turned back into a string.  So if you try to parse it, you might get an exception rather than letting the language auto-convert it.  So you're doing many things here: 1) checking if the value is null; 2) checking if the type can be converted; 3) potentially converting it over to another type; 4) converting it again.  And you may have to wrap all these operations in a big try/catch block.  If you're working with a database that may contain null values, and you're forced to use primitive types, you're royally screwed.  I mean, all you're trying to do is guarantee a value type, but you still need hundreds of checks.<br />
<br />
This is just awful.  And it's just for one value.<br />
<br />
What if you have 40-50 values?  How much of this do you have to deal with?  What if you have to deal with several operations that require you to do this 40-50 times?  What if there's no easy way to loop through the parameters in your object without having to take out the equally bulky Reflection API?<br />
<br />
In perl, since objects are glorified (or blessed more specifically) forms of hashes, arrays, scalars or globs, you could, especially if you use a hash, provide a method that can loop through, utilize the Fields pragma, and easily get the same benefit.<br />
<br />
In PHP, you can utilize variable interpolation by doing something like this for a dynamic method call:<br />
<br />
$obj-&gt;$method()<br />
<br />
You're pretty much out of luck with Java (at least in doing some easily the same way).  You can't naturally take advantage of in-built features to really help you through these situations.<br />
<br />
Worse yet, you might be forced to code declaratively in XML because it's nearly impossible to do something easily and dynamically in Java.  Take Spring and Hibernate as examples of this.<br />
<br />
Out-of-the-box, Java is just a monster of a language.  You are forced to employ various plugins, IDEs, frameworks, etc. to really get any significant and immediate benefit.  And that can take a while to do as well.  <br />
<br />
Notice the words used there: &quot;a while.&quot;  That implies time and implies not moving fast, which in turn implies lack of agility.  <br />
<br />
More of my friends are turning towards languages  like Ruby and being empowered from getting more work done through frameworks like Ruby on Rails.  I think people who continue to use Java are quite arrogant in believing too much in Sun's marketing.  Java only is good in the hands of those that use it.  But for me it's too difficult to get any real benefit that I can see.<br />
<br />
The truth is, at the end of the day, you just want to be productive.  The language is truly irrelevant as long as you and your peers utilizing it understand in detail how to get the best out of it.  I for one see Java as being verbose, cumbersome, and unnecessarily detailed.  The flaws that kept a lot of C/C++ programmers away I think never were truly addressed.  C/C++ programmers have some advantage over Java people since they have more power and speed naturally.  <br />
<br />
Overall, if you need to execute something quickly, consider NOT using Java to do the job, unless your people are extremely adept at it.  Mine aren't, nor am I so I think I will continue to stay away from it where possible.<br />]]></description>
<pubDate>Tue, 07 Aug 2007 09:40:50 -0600</pubDate>
<guid>http://www.keithwatanabe.net/blogs/2007/8/7/9fd8a694e22bb98e7c67f3707bcf2279.html</guid>
</item>
<item>
<title>Programming (Language) as/is a Philosophy</title>
<link>http://www.keithwatanabe.net/blogs/2007/8/8/dd813dee5dbb08b567377b63eb18ab72.html</link>
<description><![CDATA[I was reading something on Perl packages from the O'reilly Perl Programming Book, and one paragraph really stood out:<br />
<br />
Whenever you're tempted to do any of these things, you need to sit back and think about what will do the most good for you and your neighbor over the long haul.  If you're going to pour your creative energies into a lump of code, why not make the world a better place while you're at it?<br />
<br />
This can really apply to any language.  The fact that this statement occurred in the Perl book made me realize the connection of programming, programming languages and their attribute as a philosophical mode of thinking.<br />
<br />
Think about the flamewars between Java and scripting languages such as Perl.  The core arguments that Perl people have against Java is the verbosity while Java programmers call Perl programmers obscure and lacking thoroughness.  Shouldn't the real result be about results you bring to a business?<br />
<br />
All of these statements above are loaded philosophical questions.  The best programmers, in my view, are those that have an issue or stake involved in such questions.  Should each little optimization be so critical for a business?  Why not just lie to the company and say optimization is impossible that issue?<br />
<br />
Again, it's all philosophical.  But the intention behind that philosophy is equally critical.  The person who refuses to optimize places importance on immediate results at the sacrifice of performance so that his end of the bargain is complete.  The person who prefers verbosity emphasizes thoroughness and process.  The person who favors obscurity prefers succinctness.<br />
<br />
I think those who practice programming philosophy rather than simply programming are those who are looking or have their own set of best practices.  This is one area which isn't well defined.  Certainly, there are tons of books, online articles and whatnot prescribing sets of best practices, but like any philosophy, there are numerous variations that really fit with a person's core value system.]]></description>
<pubDate>Wed, 08 Aug 2007 18:11:57 -0600</pubDate>
<guid>http://www.keithwatanabe.net/blogs/2007/8/8/dd813dee5dbb08b567377b63eb18ab72.html</guid>
</item>
<item>
<title>Very Productive At Work</title>
<link>http://www.keithwatanabe.net/blogs/2008/2/14/69f343033cd927b333aba268df2adb28.html</link>
<description><![CDATA[Man, you should've seen the amount of code I spat out today.  Tons of AJAX/JQuery stuff.  Most of it is CRUD with AJAX, but I'm about to build a kind of webtop application that utilizes a great deal of interactive elements with javascript, CSS, and AJAX for handling some administrative tasks.  I'm quite happy with the code I've got at work.  For instance, my average JQuery function call is around 4 lines while the organization of the code is working out quite well.  Stylistically, I've got things done in such a way that my code is EXTREMELY clean cut.  Not sure if it's the most optimal, but my application doesn't have extreme performance requirements.<br />
<br />
Another aspect I got to work with recently is the Reflection API in PHP.  I do some quirky things where I have my authorization piece defined as a combination of the controller name and the action name (where the action part is handled via convention in the Zend Framework).  From a search prompt, you can enter the name of an application and it will examine for the controller directories of the application.  Then using Reflection, I am able to query the controller for public methods.  From there, I reconstruct the authorization permission name and am able to display it.  It's quite cool actually because I don't have to manually run all these insert SQL commands to put the permissions into the database.<br />
<br />
Also, in the future, I'm hoping to write some web services for Bugzilla, PhpMyAdmin and MediaWiki to create permissions and user accounts from my system.  User management is a royal pain in the butt when you have disparate applications containing their own proprietary form of entitlements.  I hope to unify these aspects through my administration application and make granting access easier to these applications.<br />
<br />
Then my boss and I did a little interesting experiment where we compared the performance of different slurp methods with Perl.  We tried using one of the slurp modules as well as this little Perl idiom:<br />
<br />
open (&lt;$fh&gt;, &quot;somefile.txt&quot;) || die $!;<br />
my $txt = do { local $; &lt;$fh&gt;; };<br />
close &lt;$fh&gt;;<br />
<br />
Found out that this piece of code runs REALLY fast.  The way he was doing it was building an array using map.  However, my theory is that when you're reading a file in line-by-line, it's more memory/IO intensive, compared to storing the whole content into a scalar value.  I think in the former case, because you're building a data structure, it's also slower.  We tried each scenario with a file around 143 MB.  The code above ran at 2 seconds compared to the other routines, which all ran slower.<br />
<br />
I swear, it's a totally different world than being at the Anti-Productive company (i.e. HLIKK).  I get so much done at work these days.  Heck, I have to force myself to leave because my work can be so interesting at times.  Considering I've been here only a little over 4 months, I've accomplished a lot and learned a tremendous amount.  It makes me wonder how much more I can produce in a year's time?]]></description>
<pubDate>Thu, 14 Feb 2008 09:17:17 -0700</pubDate>
<guid>http://www.keithwatanabe.net/blogs/2008/2/14/69f343033cd927b333aba268df2adb28.html</guid>
</item>
<item>
<title>Re-sharpening My Perl Skills</title>
<link>http://www.keithwatanabe.net/blogs/2008/4/23/13f7bab8a7369e6b5e5490db552a0a06.html</link>
<description><![CDATA[In my programmatic quest to shrink all lines of code into one line, I have managed to tune my <strong>Perl</strong> scripts recently at work into 1-3 line wonders.  I've been influenced a bit (perhaps in a geeky negative way) by some people over at ValueClick in the past in creating obfuscated, but killer <strong>Perl</strong> code.  The great thing is that I'm learning how to really utilize some of the more lesser known features that you probably won't see much in anything but the most hardcore type of modules out there.<br />
<br />
For instance, I started using the following paradigm:<br />
<br />
sub func {<br />
+{ map { $_-&gt;{something} =&gt; $_-&gt;{value} } @{$_[0]-&gt;someMethod($_[1], $_[2])} };<br />
}<br />
<br />
this is a cool little piece of code that i finally got to use the <strong>+{</strong>.  I found that little bit of code in the <strong>O'Reilly SOAP</strong> book, the author of <strong>SOAP::Lite.pm</strong> had a few statements like that.  I scratched my head for a while trying to figure out what it did.  Later, I found out that it's a type hint to the interpreter to return back a <strong>hash reference</strong>.<br />
<br />
I used it here because if I just did something like:<br />
<br />
{ map { ....} };<br />
<br />
I'd receive an <strong>array</strong>, which isn't what I wanted.  The <strong>+{</strong> sign will convert this into the appropriate <strong>hash reference</strong>.  I showed my boss to see if he knew what the heck it did, but it's a pretty obscure thing in <strong>Perl</strong> that I don't see often times used.  But I'm finding it immensely useful with statements like that.<br />
<br />
Of course, your next comment might be, well why the heck would you need a statement like that in the first place?  I'm working quite a bit with various types of data.  Sometimes, I have lists of data in the <strong>array</strong> format.  But I occasionally want to convert it over to a <strong>hash</strong> format.  Map partly helps here, but if I want to stay true to my virtue of one liners and avoid returning another array, then the <strong>+{</strong> becomes quite useful in conjunction with <strong>map</strong>.<br />
<br />
I really enjoy programming in <strong>Perl</strong> the most because it's like a puzzle where you're constantly trying to optimize what you're doing.  I've seen people use tons of variables or less obscure syntax, but I think that it's really not that great of a thing in the end.  I mean, in theory, you're replicating memory by creating more variables and the function call potentially grows, whereas a one liner, for a true veteran of <strong>Perl</strong>, can easily be deciphered without having to painfully scroll through unnecessary pieces of code.  I mean, if you want verbose, code <strong>Java</strong> or <strong>COBOL</strong>.  Then tell me how readable your code is and how long it took you to get a simple idea out the door.]]></description>
<pubDate>Wed, 23 Apr 2008 10:35:47 -0600</pubDate>
<guid>http://www.keithwatanabe.net/blogs/2008/4/23/13f7bab8a7369e6b5e5490db552a0a06.html</guid>
</item>
<item>
<title>Neat Perl Tricks</title>
<link>http://www.keithwatanabe.net/blogs/2008/6/30/0e94daf300bfbb59ec41bffad4459384.html</link>
<description><![CDATA[<h2>Using qw for an array ref:</h2>
<span class="Code"> [qw(item1 item2 item3 item4)];</span><br />
<br />
<br />
<h2> Extracting parts of a split list</h2>
<span class="Code">my ($item1, $item2, $item3) = (split(/s+/, $str))[2,4,5];</span><br />
<br />
<h2> Converting An Array To Key-Value Pairs For A Hash</h2>
<span class="Code"> my @list = qw(key1 val1 key2 val2 key3 val3 key4 val4);<br />
my %h = %{+{@list}};<br />
</span><br />
<h2> Calling a function inside of a quoted element</h2>
Very useful when you don't want to end a quote or heredoc.<br />
<br />
<span class="Code">my $var = &quot;hello @{[getName()]}n&quot;;</span><br />
<br />
<h2> Checking if the correct number of parameters are passed into a subroutine</h2>
<span class="Code">sub func {<br />
  die unless @_ == 4;<br />
}<br />
</span><br />
<h2> Using A Lookup Table To Quickly Validate If Arguments Exist</h2>
<br />
Good for checking input.<br />
<br />
<span class="Code">sub validate {<br />
  my %args = (arg1 =&gt; 1, arg2 =&gt; 1, arg3 =&gt; 1, arg4 =&gt; 1);<br />
  return exists $args{$_};<br />
}<br />
</span><br />
<h2> Converting a subroutine's arrayref argument to an array</h2>
<span class="Code">some_func(&quot;arg1&quot;, &quot;arg2&quot;, ['item1', ['item2'], ['item3'], ['item4']);<br />
<br />
sub some_func {<br />
  my $arg1 = shift;<br />
  my $arg2 = shift;<br />
  my @items = @{shift()};<br />
  print &quot;$_n&quot; for @items;<br />
}<br />
</span><br />
<h2> Dynamic Subroutines With Hashrefs</h2>
Nice technique when you want to create callbacks and require that the function calls are a little dynamic (for instance, when you don't know what function you might need to call).<br />
<br />
<span class="Code">my $h = { progname =&gt; 'some_func' };<br />
eval &quot;$h-&gt;{progname}('David')&quot;;<br />
<br />
sub some_func {<br />
  print &quot;Hello $_[0]n&quot;;<br />
}<br />
</span><br />
<h2>Getting Local Time in Epoch Seconds</h2>
<span class="Code">use Time::Local;<br />
my $sec = timelocal( (localtime)[0..5] );</span><br />
<h2> Efficient File Slurping</h2>
<span class="Code">open (FILE, $dir) || die $!;<br />
my $file = do { local $/; &lt;FILE&gt; };<br />
close (FILE);</span><br />
<br />
<h2> Getting All Files in A Directory</h2>
<span class="Code"> opendir( DIR, $dir ) || die $!;<br />
my @segdirs = grep { !/^./ } readdir( DIR );<br />
closedir( DIR );</span><br />
<br />
<h2> Better Inheritance in Perl</h2>
<span class="Code"> use base(Path::MyClass);</span><br />
<br />
<h2> Creating A Basic Constructor</h2>
<span class="Code"> sub new {<br />
  my ($class, %args) = @_;<br />
  my $self = {};<br />
  bless $self, ref $class || $class;<br />
}</span><br />
<h2>Creating A Singleton Instance</h2>
Using the constructor from above:<br />
<br />
<span class="Code">sub instance {<br />
  my $class = shift;<br />
  strict 'refs';<br />
  my $instance = ${&quot;$class::_instance&quot;};<br />
  defined $$instance ? $$instance : ( $$instance = $class-&gt;new( @_ ) );<br />
}<br />
</span>]]></description>
<pubDate>Mon, 30 Jun 2008 03:10:22 -0600</pubDate>
<guid>http://www.keithwatanabe.net/blogs/2008/6/30/0e94daf300bfbb59ec41bffad4459384.html</guid>
</item>
</channel>
</rss>
