Your browser is no longer supported.

Please upgrade to a modern browser.

Top Menu

5% Discount on Legal Highs, Salvia Divinorum and Everything Else From The Coffeesh0p

I'm Off My Mash On Ecstasy Pipes

By John Clarke

It’s that time again. I’m coding Coffeesh0p from the ground up for the third time since I started in 2006, only this time, it will look exactly the same. Sounds point­less, right? Well, pro­gram­ming is very much like skin­ning a cat — there’s more than one way to do it, and cur­rently the pro­gram­ming behind Coffeesh0p resembles an epi­leptic retard with Huntington’s Chorea trying to skin a cat with a dull pocket knife under a strobe light. Almost.

The reason I’m recod­ing it this time, and also the reason behind why I recoded it last time is that I’ve gotten a lot better at pro­gram­ming since the pre­vi­ous incarn­a­tion. This time, I’ve been trying to wrap my head around taking an Object Ori­ent­ated approach. That means using code to rep­res­ent things as an object, such as a product, a news post, a comment, or a basket, which is a great way of looking at things. Before, I might have written some code to pull product inform­a­tion straight out of the data­base and display it, which works OK, but if the data­base behind the site changes for some reason, then I’d have to go through every page and update the code to work with the new data­base. Object ori­ent­ated code makes any­thing like this much easier, because all the code to talk to the data­base is kept in one or two files, which can be mod­i­fied or swapped for some­thing else really easily. Since each object is kept in a single file, they can also be reused for any other site that requires some­thing similar. For example, Coffeesh0p and Salvia​-Trip​.net both use the same object to talk to the data­base — I just bor­rowed the code from one site and uploaded it to the other.

As Coffeesh0p expands, the exist­ing code has become much harder to main­tain and add new bits to, which is also much easier using objects, as the code is far easier to read and under­stand. Imagine if I wanted to add a comment to some­thing. Without objects, it might look some­thing like this hor­rible mess:

$sql = "INSERT INTO `comments`(`item_id`,`name`,`email`,`body`,`rating`) ";
$sql .= "VALUES (1, 'Synchronium', 'pretend@email.addr', 'Here\'s my comment!', 5);';
mysql_query( $sql, $database_link );

But with objects, you don’t even have to know any PHP to work out what the fol­low­ing does:

$comment = new Comment();
$comment->item_id = 1;
$comment->name = 'Synchronium';
$comment->email = 'pretend@email.addr';
$comment->body = 'Here\'s my comment!';
$comment->rating = 5;
$comment->save();

As you can imagine, coding like this hardly gives me a head­ache at all!

Learn­ing to code was prob­ably one of the best things I ever did. Ser­i­ously. I’d recom­mend it to anyone, and there are loads of books out there for begin­ners.

So, yeah, that’s what I’ve been up to. Nothing inter­est­ing or hil­ari­ous, but import­ant non­ethe­less.

As a treat for indul­ging my geek­i­ness, I bring you the Brass Eye episode on drugs. Brass Eye got a passing mention in my misses’s last post, Can I Get High Legally?, and it occurred to me that a lot of readers from outside the UK prob­ably wouldn’t know what we were talking about. Well, for those that don’t know, it’s one of the fun­ni­est TV pro­grams of all time, written by a per­sonal hero of mine and comedy genius Chris Morris.

Click the red play button once, close any adverts that might pop up then click the green play button to watch it. The first 40 seconds or so are blank, so you might want to skip it forward.

.

One Response to I'm Off My Mash On Ecstasy Pipes

  1. James Rozee says:

    $comment = new Comment();
    $comment->item_id = 1;
    $comment->name = ‘Syn­chronium’;
    $comment->email = ‘pretend@email.addr’;
    $comment->body = ‘Here\‘s my comment!’;
    $comment->rating = 5;
    $comment->save();

    I’d rather do it this way, per­son­ally:

    $core->comments->addComment( $name, $email, $body, $rating );

    I rather have everything work through my core.

    Really id actu­ally do

    $core->users->comments->addComment( … ); etc

    Anyway, hope it went well (that is if you’ve fin­ished).

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: