Refactoring

Building Clean URLs Into a Site

I wrote about building a site with clean URLs, but that's useless to you. No, you've got a creaking hulking monster of a site that coughs up URLs like "render.php?action=list_mailbox&id=42189", was built "to meet an accelerated schedule", and eats summer interns whole.

This article tells you how to put clean and human-usable URLs on top of the site without even editing your underlying scripts. All these examples mention PHP but it doesn't matter what you coded the site in, you just have to be running Apache and have a little familiarity with regular expressions.

So we have two goals. First, requests for the new URL are internally rewritten to call the existing scripts without users ever knowing they exist. Second, requests for the old URLs get a 301 redirect to the new URLs so that search engines and good bookmarks immediately switch to the new URLs.

Let's work through an example .htaccess file. We take apart the new URLs and map them internally to the old URLs:

Versioning - The Next Big Thing

In the web development world, anyways. So, in the grand scheme of things, maybe not a huge deal to anyone else. Versioning is going to be one of the biggest problems and opportunities there is in web development, and it's going to take us at least five years to get it right.

Actually, let me admit up front that five years is a shot in the dark, and optimistic to boot. If people keep hanging out with bondage and discipline languages like Java and C# that are still catching up to language and framework developments from the 90's it'll take us more like ten years. (Attention Lisp Weenies: Yes, I know you solved every problem forty years ago for certain values of "solved" and "problem" while the rest of us were getting work done.) Not only is versioning a difficult technical problem, it will be difficult to educate programmers in what it is, how it works, and why you'll wish you used about a year after you decided it was too much work.

New Contributor - Peter Harkins

Let's all give a warm welcome to our newest contributor, the incredibly brilliant and good-looking Peter Harkins.

That's right, clap for me -- er, him, clap for him. I'm not writing this about myself. I mean he's not. Crap.

Hi, folks. I'm a new contributor to CodeSnipers. I'll be writing mostly about design and coding, though I may wander into MicroISV territory if any of my side projects should start doing particularly well.

To tell you a little about myself, I'm a 25-year old web developer in Chicago, IL, USA, Earth. I've been programming for about fourteen years, professionally for the last 5.5. My constant obsession is writing code that's just a little bit better, a little bit smarter, a little bit higher-level. Even though the steps I've taken and will be writing about are small, they're a great way to improve code and design every time you touch it.

HTML Helpers - Ruby Wannabes in PHP

I've gone back and forth on the idea of using ALL html generation functions to hammering it all out in a template like Smarty. Templates are nice, It sure is nice to use functions. I was looking at RoR and saw these HTML helper functions. I thought, hey I can write them in php. (Yeah to all you php hating ruby folks, this may be an effort in futility, but thinking how to implement some of these things in PHP helps me understand the concept, like my MVC articles)

Implementing just a few… Here's what I came up with:

Business Logic != Database Logic

Databases are good for one thing: storing data. But so are spreadsheets, PDF files, and the like. What separates out a good database from other data storage facilities is the ability to retrieve and store records in the database efficiently.

There are a lot of table models that seem to be more worthy of a spreadsheet than a database. For example, consider this scaled down employees table (my apologies for the dots, but it makes the formatting work):

+----+------+------------+
| id | name | department |
+----+------+------------+
| 1. | Bob. | Sales..... |
| 2. | Mark | Shipping.. |
+----+------+------------+