Some New Ideas

I’ve been wondering lately about the future of Organon and what I want to do with it. I’ve got two ideas which seem somewhat creative (I haven’t seen any other blogs using the same techniques), so it will probably be a choice between those. The only issue is that both techniques would be harder to maintain and would most likely take up more time than I have set aside for blogging. And I’d have to spend some time over spring break redesigning for the new format, time that would be better used getting the rest of the Brettia network up to speed (brettia.com has a really crappy stylesheet, brettepps.com displays a PHP error, and new.brettia.com has been inactive for two months).

Anyway, these are my ideas, and please don’t use them on your own site (if you have one) because I’ll hunt you down and murder you gruesomely. The first is to blog in a “voices in my head” format, which would be much like normal but with occaisional commentary from other entities, such as body, mind, spirit, etc. It could be interesting, since I find myself thinking like that most of the time anyway.

The second option, and my favorite of the two, is a newspaper-like format where I can post in different sections (Sports, Money, Life, etc.) fake articles about me. This was inspired by the entry from a week or so ago where I reported my current school situation as if it were the economy. So I dunno. I might just stay with the way I’m doing it already, but I could use something new. And who knows, maybe this is the next level for blogging: a jump from a single point of view to a kind of surround-blogging. Hmm.

While on the subject of blogging, I discovered a nice PHP blogging application called WordPress recently that is fully W3C standards-compliant (or so it says) and is generally stable. Now, I’m building my own homegrown blogging system (which, I admit, has not been going well recently), and I decided to take a look at some of the WP code just to see how a few things (such as multiple sub-categories) were done. I was appalled, to say the least, when I found disorganized code build around a library of global functions, most of which were poorly commented and hard to understand. There was only perhaps 500 lines of object-oriented code in the whole thing.

Okay, time for a quick PHP tutorial, since I know a lot of people don’t understand what I’m talking about. Here’s an example PHP script:

Above is the classic “Hello World” script. All this does is show the phrase “Hello World!” on the browser screen. Not complicated. Now, for something a bit more complex:

function hello_world($number) {

echo('Hello World');

echo($number);

}

?>

This is an example of a very simple function. You can define functions in PHP so that you can reuse code without having to copy and paste it over and over again. This also allows you to change the code in one place rather than in multiple scripts. The above function takes one argument, which is a variable called number. Then the function echoes the phrase “Hello World” and the value of the variable called number. For example:

This would output “Hello World42″ to the browser. You could put in other numbers to get similar results, even decimals or strings of text that aren’t even numbers at all. (The name of the variable doesn’t control it’s value.) Now for code that is object-oriented, a standard that is gaining strength among PHP developers.

class hello {

    var $message;

    var $number;

    function hello($message,$number) {

        $this->message = $message;

        $this->number = $number;

    }

    function print_all() {

        echo($this->message . $this->number);

    }

}

$hello = &new hello('Your head is large.',42);

$hello->print_all();

?>

Now, don’t worry if you don’t understand the above code; I’ll go through it step-by-step. First we define an object, or class, called ‘hello.’ A class can be a container for several functions or it can do even more advanced things. After defining the class we define two variables, $message and $number, which are owned by the class. Then we define a function called ‘hello,’ which is known as a constructor because it shares the same name as the class and is meant to perform any steps needed to initialize the class. The hello function takes two arguments, $message and $number, the values of which are transferred to the object’s $message and $number variables.

With the constructor taken care of, we define another function, print_all(), which takes no arguments and will display the values of $message and $number in the browser window. Now that the class is finished, we call it by assigning it to the variable $hello. We also provide the message, ‘Your head is large.’ and the number 42 as arguments. Finally, we call the print_all() function to output the values of the two variables to the browser.

Does it make a bit more sense now? Again, don’t worry about the code, just the concept. The first two examples are called procedural code because each instruction follows in order and no part of the code really interacts with other parts. Also, should the code need to be changed, the first example would not work well if it were used in the code repeatedly. The last example is object-oriented code, meaning that it is organized into an object. An object-oriented approach makes the code easier to read (once you’re used to it) and it makes it easier for other programmers to use your objects in their code, because they can use those objects without actually looking at the code inside them, providing that they have good documentation or comments to help them.

That tutorial probably didn’t help much, did it? That’s all right, you can try PHP Freaks for some decent tutorials on PHP, if you’re interested in understanding the language better. Also, SitePoint (one of my dailies) has some wonderful books on PHP and on HTML, so you might check them out. Mr. Trapani recently got me a two-volume set of books called the PHP Anthology by Harry Fuecks (wouldn’t it suck to have that name?), one of SitePoints main writers. It’s been very helpful and enlightening, but I’d recommend “Build Your Own Database-Driven Website Using PHP and MySQL” by Kevin Yank (yet again, not exactly a desired name). I downloaded the first four chapters free, and it was all I needed to really get started with PHP and such.

Someday I’ll write up a tutorial describing how to install PHP, Apache, and MySQL on a personal computer for testing, since I know it would be helpful to those just starting out.

Eh, there’s so much more I should write, but I’ve lost the will suddenly. I’ll write again over spring break, I promise.

Obfustication.

Comments are closed.