Always Get Better

Never stop looking for ways to improve

November 30th, 2008

An interesting article at the Silicon Alley Insider today – recession winners are designers and SEO experts.  Advertising is tricky for businesses because dollars spent can’t always be tracked to dollars earned.  When it comes to designing a web site I like to go with the analogy of a salesperson.  A web site is like an employee who works 24/7, can serve unlimited numbers of customers, and remembers everything they are told about every product.  Every dollar spent on a corporate web site is returned to the company passively over time – and as the site ages and grows in traffic, its value continues to increase.

Those are interesting elements to keep in mind when making purchasing decisions.  As we head into hard times it is more important than ever for businesses to connect to their customers in real and organic ways – social networking is the tool for the job.

For the best bang-for-the-buck, look for companies to increase efforts at creating and maintaining blogs either through the acquisition of in-house writers or by outsourcing to professional bloggers.  Blogs are search-engine darlings, but their real power lies in the fact that people are not just visiting blogs – they are reading them and participating in discussion.

Any company that has not yet begun to consider the benefit of the blogging medium to increase their brand awareness is going to find themselves left behind like the dinosaurs of the industrial revolution.

November 26th, 2008

In Drupal it is possible to remove the login option from the site template by using the Blocks tool in the administration.  If you do this, you won’t be able to log in from the regular page template.

Logging in is still possible and easy.  Just add the querystring: ?q=user to call up a login prompt.

November 25th, 2008

A common issue faced by theme developers is that of the site slogan not appearing even when the variable $site_slogan is present.

The site slogan is disabled by default.  To turn it on in Drupal 6.6 go to the Theme selection list and choose Configuration.  The site slogan is one of the checkboxes available on the left-hand side.

The same thing might have to be done in the theme-specific settings to take effect.

November 24th, 2008

When configuring Drupal 6.6 on a Windows XP/Apache/MySQL box, I ran into an issue whereby I would enter the database information on the Database Configuration screen, press the advance button, but be constantly redirected back to the Database Configuration screen.

The Drupal community indicates this is a problem with permissions – Drupal needs to be able to write to your site’s settings.php file.  All permissions appeared to be correct in my setup but I was still unable to continue.

The solution was to edit the settings.php file, putting in my database information manually.  Just look for this line:

$db_url = ‘mysql://username:password@localhost/databasename’;

And change the username, password and databasename parts.

Then return to the Database Configuration screen, enter the information again and continue.  The correct database information will be read from the settings file and the configuration will continue to the next step.

Happy hunting!

November 23rd, 2008

I recently transferred AlwaysGetBetter.com from GoDaddy to MediaTemple. Although their administrative interface was somewhat, I found GoDaddy’s hosting service decent enough to meet my needs so the move has nothing to do with dissatisfaction in their service.

MediaTemple was recommended to me by a close programmer friend who has been using their service for some time and had nothing but glowing reviews for them.  So far the hosting seems alright – the setup was almost instantaneous and the administrative tools very easy to work with.  Their pricing is a little on the high side but certainly not unreasonable.

August 16th, 2008

Since this blog has been running for the past 8 months, I thought I might take a step back and consider the journey so far.  How did my original expectations stack up against reality?

The first thing that struck me was how quickly people found my work and how readily they picked it apart.  I thought I knew quite a lot about my field, but this experience has shown me that there are many very knowledgeable people out there, and with a breadth of experience I could not have imagined.  Consequentially, I feel I’ve become much sharper in my writing – I am less likely to jump to unsupported conclusions and I can hold my own much better.

The second revelation I had was that in order to have decent content prepared and ready to publish regularly, I have to write a lot.  With a full-time job, new child, and college studies on my hands, I haven’t had the opportunity to invest as much effort into this blog as it deserves.  Sometimes days (at one time, weeks) go by without a post.  That is a situation I plan to rectify in the lead-up to the one-year anniversary.

Third: revenue.  In the back of my mind I know that it is possible to monetize blogs, and I plan to do so with Always Getting Better – one day.  While originally I believed my goal was to rush to riches, I am aware of the reality of the time involved and my own commitment being barriers to that kind of success.  What I found was the pleasure of writing these articles, and of interacting with some of the very intelligent people I’ve met so far, has made the experience of maintaining this blog worth the effort.

So to all those who do read, whether they contact me or not, I’d like to take this opportunity to say thank you for making this a fun ride so far.  I hope you find the content I add to be worth your time investment and I welcome your continued feedback!

February 15th, 2008

When we learn how to open and use a database connection with ASP.NET, as with any other programming concept in any other programming language, the simplified version used to explain what’s going on is not truly representative of the quality professional code we will one day be expected to write.
Opening and Closing Connections

Case in point: managing of sql database connection resources. How many of us learned to write something like this:


// Create a new SQL Connection object
SqlConnection conn = new SqlConnection( connectionString );

// Open the connection to the database
conn.Open();

// Create a new SQL Command
SqlCommand cmd = new SqlCommand( “DELETE FROM BabyNames;”, conn );

// Execute the command
cmd.ExecuteNonQuery();

// Close the database connection
conn.Close();

Sure it’s easy to follow, but if you deploy that on a moderately busy server you are going to make your client very unhappy.

Dispose Resources

SQLConnection and SQLCommand objects reference unmanaged resources, meaning the C# garbage collector has no framework knowledge about your object. Since these classes both implement the disposable interface it is important to call the Dispose() method in order to correctly free your application’s used memory.

So our code gets updated to look like this:


// Create a new SQL Connection object
SqlConnection conn = new SqlConnection( connectionString );

// Open the connection to the database
conn.Open();

// Create a new SQL Command
SqlCommand cmd = new SqlCommand( “DELETE FROM BabyNames;”, conn );

// Execute the command
cmd.ExecuteNonQuery();

// Dispose of the command
cmd.Dispose();

// Close the database connection
conn.Close();

// Dispose of the connection object
conn.Dispose();

Trap for Errors

What happens if there’s a problem, and your code fails to complete? If your application crashes before your objects are disposed, you are left with the same effect as if you had never disposed your objects at all!

Fortunately, C# includes the try … finally reserved words. If anything within the try { } block fails, the finally { } still executes. We can easily apply this to our program code:


// Create a new SQL Connection object
SqlConnection conn = new SqlConnection( connectionString );

try
{
// Open the connection to the database
conn.Open();

// Create a new SQL Command
SqlCommand cmd = new SqlCommand( “DELETE FROM BabyNames;”, conn );

try
{
// Execute the command
cmd.ExecuteNonQuery();
}
finally
{
// Dispose of the command
cmd.Dispose();
}

// Close the database connection
conn.Close();
}
finally
{
// Dispose of the connection object
conn.Dispose();
}

For my own part, I prefer the using keyword. We can include a using call anywhere we would ordinarily use a disposal object. When the code is compiled, it behaves the same as try … catch, but leaves our program code much more readable.

Even better, we don’t even have to bother calling Dispose() because it does it for us!


// Create a new SQL Connection object
using ( SqlConnection conn = new SqlConnection( connectionString ) )
{
// Open the connection to the database
conn.Open();

// Create a new SQL Command
using ( SqlCommand cmd = new SqlCommand( “DELETE FROM BabyNames;”, conn ) )
{
// Execute the command
cmd.ExecuteNonQuery();
}

// Close the database connection
conn.Close();
}

Slick.

Open Late, Close Early (like a bank)

There is one more thing I would add to this. Creating objects in memory takes time. Although it happens in fractions of a second too fast to be detectable by us, it’s important not to waste processing time wherever possible.

Whenever we Open() a database connection, we expect to use the database right away. If we then create an SqlCommand, we’re wasting the open connection’s time. It’s as if we pick up the phone and listen to the dial tone while we then flip through the white pages looking for the number we want to call.

Let’s change our example code so we will now Open() at the last possible opportunity, and Close() right away when we’ve made our call:


// Create a new SQL Connection object
using ( SqlConnection conn = new SqlConnection( connectionString ) )
{
// Create a new SQL Command
using ( SqlCommand cmd = new SqlCommand( “DELETE FROM BabyNames;”, conn ) )
{
// Open the connection to the database
conn.Open();

// Execute the command
cmd.ExecuteNonQuery();

// Close the connection to the database
conn.Close();
}
}

In the end, the program code we wrote is very similar to the newbie code we started with. However, we’re now protecting our system from memory leaks, and we’re protecting our database from wasted clock cycles. Our code is easy to read and stable.