Archive for November, 2006

It is not uncommon to run across arguments which insist that if a particular society does not exist now, it is unlikely to exist in the future. I often find this situation with free markets. The argument goes something like this.

If free markets are such a good idea, why aren’t there any free market societies?
(more…)
Milton Friedman died this morning after a bout with pneumonia. As a sufferer of a rare respiratory disease and as a libertarian I feel a real loss on more than one level. There are already many tributes to him around the web. If you are unfamiliar with his work and with his passions I urge you to look him up. Mr. Friedman, you will be missed.

A common question on the beginner programming mailing lists goes something like this:

have been trying to open a web page into internet explorer using the getprint command and then opening the file for internet explorer. The getprint command only downloads the code to the command window. I have used the following code and have used the getprint line before and after the internet explorer line ,

To the expert this might look similar to “How to apply a phillips head screw with a tire iron?” The obvious answer is “You don’t. You use a screwdriver.”

If you find yourself about to ask a question in this form, you are limiting yourself. Try to look for a solution that does not involve the tire iron. If inspiration doesn’t inspire you, ask the beginner programming group How to do A and leave off the limiting factor B.

In general, subroutines should receive data, process that data, and then output something. There are some exceptions. In void context, we have no output. In the case of information retrieval from a fixed source there may not be any input. An error logging routine might have input and output but no processing.

Good subroutines only affect and are affected by their own environment. If events exterior to the subroutine affect it, you have probably done something wrong. Here's an example of a poorly written subroutine. foo() is using $bar. $bar has not been passed to it. Remember that a well written subroutine has data passed to it. Good subroutines only affect and are affected by their own environment. Deleting the $bar variable outside this subroutine affects the subroutine.

PERL:
  1. sub foo {
  2.     return $bar;
  3. }

(more...)

CGI.pm is a module included in the standard perl distribution. It is the most commonly used module for writing perl scripts that interact with the web.

I run across these mistakes a lot when reviewing beginner perl code. The first mistake has to do with the dual nature of perl modules. A perl module can be accessed either as a function-oriented module or as a object-oriented module or by both methods.

CGI.pm allows both. Under the hood, that makes for some messy looking code. In practice, we find a lot of bloated code. Normally, we would use either the function oriented or the OO version, not both.Here are a few of the most common errors I see.

(more...)

The author of this module chose to use some file scoped variables in a module. This effectively created some global variables used outside the sub. This is not the recommended way to write a subroutine, but I needed an example and this one was handy. :)

PERL:
  1. my $htmltree;
  2. my $node;
  3. my @prevnodes;
  4. my $htmloutput;
  5.  
  6. sub start {
  7.     my $tagname = shift;
  8.     my $attr = shift;
  9.     my $newnode = {};
  10.  
  11.     $newnode->{tag} = $tagname;
  12.     foreach my $key(keys %{$attr}) {
  13.         $newnode->{$key} = $attr->{$key};
  14.     }
  15.     $newnode->{content} = [];
  16.     push @prevnodes, $node;
  17.     push @{$node}, $newnode;
  18.     $node = $newnode->{content};
  19. }

(more...)

Opening files in perl is a fairly easy task. Here are the basic file opens. Do not use them in production code.

PERL:
  1. my $file = 'foo.txt';
  2.  
  3. # open for read
  4. open FH, ">$file";
  5.  
  6. # open for write
  7. open FH, ">$file";
  8.  
  9. # open for append
  10. open FH, ">>$file";

(more...)

I frequent the John Stossel message boards at ABCNews. I often find little morsels of economics misunderstanding like this.

LUCKY are those people who have full time employment whose employer pays all or part of their health insurance. Those people are becoming far fewer now that many companies are discontinuing health insurance benefits because they are more interested in larger profits than helping their employees stay healthy, so these same employees can continue to generate large profits for their company.
(more...)

Look at the bottom of your toaster or the back of your television set and you will probably see that it is UL listed. Underwriter's Laboratories has had the same mission for more than a century. Look in your garage and you are likely to find a shovel whose blade has a curve in it. That curve was first added by an innovative young company before Thomas Jefferson penned the Declaration of Independence.

More than 200 years later the Ames company still makes shovels. UL certification spans continents. The Catholic church has changed culturally over the millennia of its existence, but its core message remains pretty much the same. The Red Cross still saves lives. In this day of disposable everything, we sometimes forget that many private organizations have outlasted governments and can influence more than just one country.

(more...)