Feb 14

Flying over the Rockies

As I write this, I’m in a 737 flying over the Rocky mountains on my way home from a long week in Denver, Colorado. When you think about all the infrastructure that is in place to facilitate a flight from one US city to another it boggles the mind. Not just software and hardware; but people, places, processes, and protocols. With all those puzzle pieces a person and their belongings can be safely (and magically) transported. (I’m hoping :)

All those balls in the air makes me think of the conglomeration of technologies that make up the web services I’ve built and how they are working together to synergistically create an experience and a working model of something much bigger than it’s parts.

Nowadays when a person looks at a website they rarely see a collection of pages but most websites have become their own platform and environment for the user. The advent of Ajax and frameworks like jQuery, have made a consistent look and feel with consistent user controls a must have for any (aspiring) mainstream site.

To extend my (overextended) flying analogy, certain plane manufacturers and boarding methods for example have become the default choice for all airlines. This is generally a good thing. We want our planes to be Boeing and our airports to have rolling sidewalks. (Those are awesome by the way; “Look at me! I’m walking and I’m not moving my legs!”).

However along the way it seems we’ve laid aside some important considerations on the merits of a completely unobtrusive (read “it doesn’t get in my way”), user interface.

Remember standard hyperlinks? Why do away with a method that has worked for years just because you can slap an id an on element and a write up a jQuery function? We need to at least with temerity consider not breaking a time tested model.

Remember documentation that was simple text pages hyperlinked together? An amazing tool still today which many have abandoned.

If you’ve created an exclusive club that requires an up to the minute javascript interpreter, at least bother to preserve the use of the old fashioned back button.

It so easy to ignore all the technologies that, when built upon, gave us our new shiny toys. However it takes much more effort to see the important parts of those base UI features that would be catastrophic (in a “your new app sucks” kind of way) to leave behind.

Feb 4

Blogging from Android


I just installed the new wordpress app for Android phones. Now I can blog from anywhere! Of course writing things on a tiny phone screen is kind of funny. But I guess it’s nice for starting a draft when an idea strikes you, wherever you may be.

I think I’ll try this out for while. Hey, if it gets me to write a little more, that’s a good thing.

Thanks to those of you following my blog these last few years, I’ve enjoyed explaining the intricacies of web programming. I sometimes use these posts to work out problems by attempting to explain them in writing. Its helpful to have a void to dump your ideas into where you can examine them and still have the pressures of public scrutiny.

Feb 2

Are you a Luddite?

Amish Boy
From the wikipedia article, Luddite:

The Luddites were a social movement of British textile artisans in the early nineteenth century who protested—often by destroying mechanised looms—against the changes produced by the Industrial Revolution, which they felt were leaving them without work and changing their entire way of life.

As a proponent of software efficiency measures at home and in the workplace, I occasionally detect a subtle, yet tangible, animosity toward new ideas in the technological realm. Fortunately, few today would turn to “machine breaking”. Yet there does seem to be the more passive aggressive form of industrial sabotage, the refusal to grow or learn. I don’t think people generally hold an overall dystopian view of technology in a broad sense for our society. Just that on a personal level the resistance to even small changes is a great barrier. Like a wire, cut and wrapped in plastic insulation, the power cannot reach the place it is needed.

So where do you stand in your relationship with technology? Are you a tech lover,a technophobe, or somewhere in between?

If this is you:

“I’m afraid of techology, get me out of here.”

Admit it. Your aggression towards technological advancement is really based in fear. Fear you might be left behind. Fear of the unknown. Fear of failure. The only way to conquer your fears is to face them. For me, changing the oil in my truck is a similar challenge. It takes me way longer than it should. My knuckles get all bruised up and I hate all the grunting and messing with wrenches and nasty fluids.

However the truth is we all are comfortable doing what we are good at. And the more you do the better you become at it. It’s called “practice”. The piano virtuoso MUST practice diligently to become a master.

Dealing with technology comes with it’s own kind of grease that rubs off and gets in your hair and clothes, but you’ll come to tolerate it for the satisfaction of a job well done.

If this is you:

“I still love technology… Always and Forever

I’m in this category and I struggle to keep my technophilia from becoming transhumanism. But the reality is we can become too obsessed with technology. If we ignore our families, our ideals, or our life altogether.

Jan 20

Conjunction Junction What’s your Function

Today I’ve decided to go over functions, (also known as “methods” or “subroutines”) the building blocks of modular code; and show why it’s a good idea to use them in your programming.

When I first started writing web applications I didn’t really understand what a function was and how it worked, so I just avoided them. I would instead write something procedurally and if I needed to do the same thing over again I would repeat that line (or lines) of code again.

Doing this breaks one of the important ethos of programming called DRY (“Don’t Repeat Yourself”). In a program of any sufficient complexity, repetition of code is NOT your friend.

Let me demonstrate how using a function can save you from repeating lines of code over and over.

Here is a section of PHP code that calculates a human readable string of days, hours, minutes, and seconds from two times to give a files age. I want to get the plurals of day(s), hour(s), etc., correct. So I am testing the number to see if there is more than one and adding an “s” to the end if there is.

<?php
//...
$seconds = strtotime($curdate) - strtotime($olddate);
/*** number of days ***/
$days=(int)($seconds/86400);
/*** number of hours ***/
$hours = (int)(($seconds-($days*86400))/3600);
/*** number of mins ***/
$mins = (int)(($seconds-$days*86400-$hours*3600)/60);
/*** number of seconds ***/
$secs = (int)($seconds - ($days*86400)-($hours*3600)-($mins*60));
/*** return the string ***/
if($days != 0) {
	if($days > 1) {
		$plural = "s ";
	} else {
		$plural = " ";
	}
	$file_age = $days . " day" . $plural;
}
if($hours != 0) {
	if($hours > 1) {
		$plural = "s ";
	} else {
		$plural = " ";
	}
	$file_age .= $hours . " hr" . $plural;
}
if($mins != 0) {
	if($mins > 1) {
		$plural = "s ";
	} else {
		$plural = " ";
	}
	$file_age .= $mins . " min" . $plural;
}
if($secs != 0) {
	if($secs > 1) {
		$plural = "s ";
	} else {
		$plural = " ";
	}
	$file_age .= $secs . " sec" . $plural;
}
echo $file_age;
//...
?>

Using a function to simplify the getting of the plural distills the 20+ lines of code into one function making it in essence 5 lines of code.

<?php
//...
function getPlural($num) {
        /*** if more than one ***/
        if($num > 1) {
                $plural = "s ";
        } else {
                $plural = " ";
        }
        return $plural;
}

function calculateFileAge($curdate, $olddate) {
	/*** get difference in times in seconds ***/
	$seconds = strtotime($curdate) - strtotime($olddate);
	/*** number of days ***/
	$days=(int)($seconds/86400);
	/*** number of hours ***/
	$hours = (int)(($seconds-($days*86400))/3600);
	/*** number of mins ***/
	$mins = (int)(($seconds-$days*86400-$hours*3600)/60);
	/*** number of seconds ***/
	$secs = (int)($seconds - ($days*86400)-($hours*3600)-($mins*60));
	/*** return the string ***/
	if($days != 0) {
		$file_age = $days . " day" . getPlural($days);
	}
	if($hours != 0) {
		$file_age .= $hours . " hr" . getPlural($hours);
	}
	if($mins != 0) {
		$file_age .= $mins . " min" . getPlural($mins);
	}
	if($secs != 0) {
		$file_age .= $secs . " sec" . getPlural($secs);
	}
	return $file_age;
}
//...
?>

This function called getPlural() is a very simple function we pass the function one “argument” (one independent variable that is the input to a function). In our case that argument is the $num variable. In the function definition (where we define function getPlural()), $num is just a placeholder for whatever variable we input. In the example we input to the function a number of days, hours, minutes, and seconds.

The function does the work of examining the number and then returning a single variable that either is “s” or an empty string.

The nice thing about designing a function is that once your function does it’s job; namely taking arguments and returning a result. It is a nice black box which you don’t have to think about how it operates any more and you can use it over and over again without repeating the code that is contained therein.

Functions are a great tool for helping you to stay original and stop repeating yourself.