First Thoughts

First Thoughts

As I mentioned on the homepage, this is my first experience really building a real website. Of course I've encountered HTML before and so am not completely new to this world, but my knowledge of CSS, PHP, and JavaScript was basically limited to knowing that they exist. So far what I've built has required a lot of HTML, some CSS, and a little bit of PHP (more on that in a minute).

The first thing I've realized, is that I am reinventing the wheel in an epic fashion. So much so that I need a bigger metaphor. This is like reinventing the microchip. Or planning to build an airplane and starting with learning to make a fire by rubbing sticks together. In the past I've had a blog using Wordpress. Complicated formatting was as easy as using Microsoft Word and posts were automatically indexed, and tagged, and had comment sections, and so on. Thinking about this blog, I'm realizing that I'll need to implement all that. And it will take quite a bit of learning. Now, down the road I might use existing tools to add features, as I only want to do something myself if I feel like there is an education benefit to it. Reinventing the wheel is pretty boring if you don't have a reason to know how to invent a wheel. One of the primary questions I'm pondering at the moment is how to store my blog posts. I want them to exist as separate pages so that I can have comments and track stats for individual posts and so on, but I also want the viewer to be able to see them all on one page. I'll let you know what I come up with.

A more immediate problem is what gave me my first tiny taste of PHP. I've been told it's a horrifying language to be avoided at all costs, although I haven't used enough to see if that is true quite yet. My problem was a simple one - code reuse. As a desktop app programmer, code reuse is like the golden rule. If you write the same code twice, you're doing something wrong. However, on this site I found myself maintaining footers and headers and navigation bars on every page. And even with 5 pages, updating those things was tedious.

Searching around the web for solutions, I came across this page which contains a method called PHP-Configured HTML. The basic idea is that ALL shared content is generated by a php script which takes parameters like the page title (and many more that I'm sure I'll add in the future as things get complicated) and then each individual page only needs two php require statements. At this point, it feels like a simple and elegant solution. Here is what my "About Me" page looks like.

<?php
$TITLE_PARAMETER='About Me';
require_once("header_script.php");
?>

<div class="contents">

  <div class="page-header">
    <h1 class="page-title">About Me</h1>
  </div>

  <h2>Content</h2>
  <p>Content?!? I love content!</p>

</div>

<?php require_once("footer_script.php") ?>			
				

Simple, clean, and elegant. It makes me feel warm and fuzzy inside.