FLiFnotes

August 22, 2011

Purely Incremental Development

Filed under: Coding,Projects — Tags: , , , — Deborah Hawkins @ 8:17 am

Usually in incremental development there’s a plan which is subject to change as new features are added on incrementally and users have a chance to respond. For Flif Risc, I’m extending the idea to purely incremental development–a similar idea but without the overall plan. In purely incremental development, everything is subject to change. This may not be a great idea within a company where business justification is always necessary, but for a personal project it’s offers the flexibility needed to keep interest up.

Test-driven development goes hand-in-hand with any type of incremental development. Writing tests to define what you want to achieve in each iteration and then writing the code to pass them is exactly what’s needed to make regular process. As an added benefit, having the tests from previous iterations makes it easy to find out if a new feature’s implementation breaks existing functionality.

For unit testing in PHP, the natural choice in PHPUnit. At first, I had some difficulty getting PHPUnit set up from the installation instructions, but adding a sudo to the beginning of each instruction solved all my problems.

At the very basic level, I want my application to be able to take in a string which is the hex representation of a MIPS machine code instruction and output the instruction in assembly code. I’d like to accomplish this in a class structure, and knowing that the machine code for add $t1, $t2, $t0 is 0×01484820, the first test verifies that this is the result my code gives.

public function testGetAssemblyCodeAdd() {
    $input = '01484820';
    $expected = 'add $t1, $t2, $t0';
    $temp = new MipsInstruction($input);
    $this->assertEquals($expected, $temp->getAssemblyCode());
}

The easiest way to code this to make it work is to hardcode the output:

class MipsInstruction {
    public function __construct($machineCode) {
        // does nothing
    }

    public function getAssemblyCode() {
        return 'add $t1, $t2, $t0';
    }
}

Running phpunit on the one test now results in OK (1 test, 1 assertion), whoo! A commit is in order for this. Unfortunately, the code doesn’t do anything other than pass this one test, so the next step is to add a couple more tests:

public function testGetAssemblyCodeSub() {
    $input = '01484822';
    $expected = 'sub $t1, $t2, $t0';
    $temp = new MipsInstruction($input);
    $this->assertEquals($expected, $temp->getAssemblyCode());
}

public function testGetAssemblyCodeOr() {
    $input = '01484825';
    $expected = 'or $t1, $t2, $t0';
    $temp = new MipsInstruction($input);
    $this->assertEquals($expected, $temp->getAssemblyCode());
}

resulting in:

FAILURES!
Tests: 3, Assertions: 3, Failures: 2

Once again, I’m making these pass the easy way first and can improve the code later once I know it works.

class MipsInstruction {
    private $inst;

    public function __construct($machineCode) {
        $this->inst = substr($machineCode, -1);
    }

    public function getAssemblyCode() {
        switch ($this->inst) {
            case '0':
                return 'add $t1, $t2, $t0';
            case '2':
                return 'sub $t1, $t2, $t0';
            case '5':
                return 'or $t1, $t2, $t0';
        }
    }
}

Now that all tests pass, it’s time to commit and I’m ready to start refactoring.

August 21, 2011

The Origins of Flif Risc

Filed under: Projects — Tags: , , — Deborah Hawkins @ 7:19 pm

It’s easy to just lounge in front of the tv when you don’t have any projects to work on. It’s easy to sleep all weekend and to let blog ideas fade away. Getting started is the hardest part, though, and maybe if I can do that, it’ll make me that much more productive.

Step one: Come up with an idea

This was a project I was interested in doing while studying for Computer Architecture. It’s a simple web application that takes a MIPS instruction in machine code and then displays it in assembly code with details on the conversion. Honestly, the idea originated a semester earlier while learning the LC-3 toy language, and expanding the project to handle multiple languages is a possible future enhancement.

Step Two: Come up with a plan

The main reason I never really got started on this project before is because I always started with the architecture. I drew out diagrams of class hierarchies and debated the pros and cons of every possible design decision but never got to the coding part. To avoid this problem, this time I’m going with a pure incremental development approach and only a general overview of the desired end product.

As far as a technology stack, I’m using PHP mainly as a language refresher along with Git for my repository.

Step 3: Set up a repository

Subversion is my tried-and-true, so this is an opportunity to try another popular version control system that’s new to me. Fortunately, git has super easy set-up and hosting on github is free for open-source projects.

As everything is flif to me, you can find this project under the name Flif Risc. For now, it’s just an almost empty README, but it’s a start for things to come.

August 14, 2011

Creating a Child Theme in WordPress

Filed under: RandoMe — Tags: , — Deborah Hawkins @ 10:33 pm

For at least a couple of years, I’ve been meaning to create a personalized theme for this WordPress blog and never got around to it until this weekend. Fortunately, it was even easier than I thought since realizing that child themes are now supported. This means I can just piggy-back off of an existing theme and just override a few CSS rules or templates as needed.

I started by working off of the WordPress Default theme before realizing that I really didn’t want a fixed-width theme and switched to WordPress Classic. Classic may not be my favorite theme, but it was easy enough to modify to get the layout I wanted.

Obviously, I’m not a designer. I did start by looking at some reasonable color schemes, but in the end I stuck with the colors that are already in my favicon. Those colors actually looked much, much worse before creating the funky background which integrated the scheme a little bit. Eventually, eventually, I’ll create something a bit more professional.

Going the easy route of modifying only the CSS, there are a few other things lacking still, like an RSS link with icon as well as a copyright notice at the bottom. Additionally, the titles of the sidebar widgets would be much easier to style if they had their own class. I may end up modifying the templates to make these changes, but for the time being it works.

Powered by WordPress