The Boston Diaries

The ongoing saga of a programmer who doesn't live in Boston, nor does he even like Boston, but yet named his weblog/journal “The Boston Diaries.”

Go figure.

Thursday, June 16, 2005

“Oh, I see the problem—you're trying to add a pterodactyl to a gluon and you just can't do that … ”

I spent most of my time at The Office today working on the web-based security cam for our data center. The actual camera is working fine and the images are accumulating on a server—the stuff I was working on today involves browsing the ever accumulating pictures.

The first major decision I had to make (and this is a project I've been working on for the past couple of weeks) is whether to generate static pages (as the images are mailed in) or do a completely dynamic site. There are arguments for both ways; the pages won't change all that much—during the day only the main index page for the current day, then at midnight the index page for the current month, then once a month the current page for the year and while I personally like this idea (a form of early binding if you will) there are a few downsides: one) it's even more files to store and two) if there's ever a design change, all the pages will have to be regenerated.

A dynamic site, however, only requires a few additional files for the program, and changes to the site take effect immediately, but the page(s) have to be built (and built and built) for each request, which involves quite a bit of disk I/O (to get image filenames namely).

I ended up going the dynamic route—Smirk wants to store the images for as long as possible so the less overhead (in this case, static web pages) the better. Also, it's not like we have to support heavy network traffic—only one, maybe two people at a time may be viewing these, and only if there's a problem with missing tools.

Also, since Smirk is a fan of PHP (Why? I don't know … ) so I figured this would be a good chance to get a feel for programming in that … language.

I do not like it, Sam I am. I do not like PHP and ham.

The whole global variable thing I'm ambivilent about. PHP is unusual (for the languages I've used) in that you have to declare which variables are global every time you use them, like:

$g_base = "/some/random/path";

function display_file($template)
  global $g_base;

  for ($this->m_i = 0 ; $this->m_i < count($this->m_files) ; $this->m_i++)

(why yes, I am using objects in PHP, and yes, the looping variable is part of the current object so I can support templates, but that's not important right now)

Unlike most languages I've experienced, if you do:

$g_base = "/some/random/path";

function display_file($template)
  for ($this->m_i = 0 ; $this->m_i < count($this->m_files) ; $this->m_i++)

the language looks first to see if $g_base is defined within the function, and if not, looks to see if it's been defined outside of the function and if so, uses that. PHP, on the other hand, will just assume you want a new local variable named $g_base and not even bother looking elsewhere, hense the need to declare $g_base as being global within display_file().

Not something I'm used to.

But I can see why it's done that way and can't really argue with it, but I keep forgetting about that, expecting PHP to handle lexical scoping.

I also find the gratuitous use of dollar signs annoying, but at least PHP uses it in a consistent manner:

var $scalar;
var $array = Array();
var $hash  = Array();

$scalar            = 0;
$array[0]          = 1;
$array[1]          = 2;
$hash ['brownies'] = "are good";
$hash ['hashish']  = "is illegal";

unlike Perl, where the declarations of scalars, arrays and hashes use different symbols:

my $scalar;
my @array;
my %hash;

so I would expect Perl to work like:

$scalar   = 0;
@array[0] = 1;
@array[1] = 2;

# NOTE---Perl uses {} instead of [] for hashes!

%hash{'brownies'} = "are good";
%hash{'hashish'}  = "is illegal";

but nooooooooooooooooooo! It's back to the dollar signs:

$scalar           = 0;
$array[0]         = 1;
$array[1]         = 2;
$hash{'brownies'} = "are good";
$hash{'hashish'}  = "is illegal";

But I come to bury PHP, not Perl.

The biggest sticking point I have with PHP (and I have the same issue with Perl as well) is the lack of type checking—a variable could be a number, or a string, or an array, or an associative array (aka hash table) or a pterodactyl. This means you can do stuff like:

$fourscore = "80"; //note-this is A STRING
$seven     = 7;    //note-this is A NUMBER
$yearsago  = $fourscore + $seven; //Do you get 87 as
                                  //A STRING or as
                                  //A NUMBER?  It's BOTH!
                                  //It's Hiesenburg programming!

But something like:

$bills   = Array();	      //note-this is AN ARRAY
$account = 400;		      //note-this is A NUMBER
$money   = $account - $bills; //What now?

will most likely blow up.

At run time.

And while it's clear what's wrong with the code above, it's not quite so clear in the following:

$bills   = get_the_bills();
$account = 400;
$money   = $account - $bills;

Hope get_the_bills() returns something that can be subtracted from a number. Or was it sum_the_bills() that returns the number? (certainly ignore_the_bills() is not the right thing, although that is tempting, and I'm digressing).

I suppose I'm too used to strongly typed langauges where the compiler nickel and dimes you to death about types so I don't have to keep all those details in my head (the computer is more capable of keeping track of details like so I don't have to).

So I'm having to constantly remind myself that $g_baseobj->m_subobj is a “month object” (not a “day object”) in this portion of the code, and that find_entry() returns a number (the index into an array), not the entry itself (although perhaps I could rename that function find_index() instead … ).

Object support in PHP isn't that bad—certainly nicer than Perl, but again, the serious lack of type checking makes it difficult to track down problems, and the error messages it gives could be more informative (“Okay, it's nice that I didn't call parent::init() with the correct number of parameters, but which call to parent::init() was incorrect—who or where was the call made from you XXXXXXX piece of XXXX?”).

It's always nice to know that “PRINT debugging” will always be alive and well.

“We gots an offer you can probably refuse … ”

Well, that was fast.

Not one day since I wrote about roulette and Google's page ranking algorithm, and I get:

From: "Norman" <>
Subject: Links exchange with
Date: Fri, 17 Jun 2005 02:55:56 +0400 (MSD)

Hello Webmaster,

We have been looking for partners to exchange links with our sites. Our sites have good traffic, and make quick market penetration, so, I hope our positions in lead search engines will be rising very fast.

If you decide to link to our websites,please use the following linking details:

and send us the exact location, and your site information:
Title, Description, and URL
We'll add your resource to our sites shortly.

URL: [yeah—like I'm going to link to these sites! –Sean]
Link Title: Baccarat
Description: All about Online Baccarat For YOU!

Link Title: Black Jack
Description: Blackjack is one of the most popular table games in the casino.

Link Title: Gambling
Description: 1 Gambling US—Welcome to your complete online source for gambling information and links!

Link Title: Internet Casino.
Description: The best online directory of casinos!

Link Title: Poker Game
Description: You will find information on how to play the game of poker, information about the types of poker, and what you can expect in an online poker casino.

Link Title: Craps
Description: 1 CRAPS US—Online Craps for YOU!

Link Title: Poker Online
Description: 1 Poker Online—the best online directory of where you can find many links to poker games!

Link Title: Poker
Description: 1 Poker US—The Best Online Poker.

Link Title: Roulette
Description: 1 Roulette US—Roulette Online.

Link Title: Slots
Description: 1 Slot US is the best online source for online slot machines, poker slots, fruit slots and money slots like you have never seen before!

Best regards,
Norman Robbins

I'd be wary of actually visiting any of these sites—redirects to hell and back and there's no telling how many popups or malware might be lurking there.

But Norman sure was quick …

Obligatory Picture

[It's the most wonderful time of the year!]

Obligatory Contact Info

Obligatory Feeds

Obligatory Links

Obligatory Miscellaneous

You have my permission to link freely to any entry here. Go ahead, I won't bite. I promise.

The dates are the permanent links to that day's entries (or entry, if there is only one entry). The titles are the permanent links to that entry only. The format for the links are simple: Start with the base link for this site:, then add the date you are interested in, say 2000/08/01, so that would make the final URL:

You can also specify the entire month by leaving off the day portion. You can even select an arbitrary portion of time.

You may also note subtle shading of the links and that's intentional: the “closer” the link is (relative to the page) the “brighter” it appears. It's an experiment in using color shading to denote the distance a link is from here. If you don't notice it, don't worry; it's not all that important.

It is assumed that every brand name, slogan, corporate name, symbol, design element, et cetera mentioned in these pages is a protected and/or trademarked entity, the sole property of its owner(s), and acknowledgement of this status is implied.

Copyright © 1999-2021 by Sean Conner. All Rights Reserved.