<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FLiFnotes &#187; php</title>
	<atom:link href="http://www.flifnotes.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flifnotes.com</link>
	<description></description>
	<lastBuildDate>Mon, 22 Aug 2011 13:17:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Purely Incremental Development</title>
		<link>http://www.flifnotes.com/57-purely-incremental-development/</link>
		<comments>http://www.flifnotes.com/57-purely-incremental-development/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 13:17:14 +0000</pubDate>
		<dc:creator>Deborah Hawkins</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[flif-risc]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.flifnotes.com/?p=57</guid>
		<description><![CDATA[Usually in incremental development there&#8217;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&#8217;m extending the idea to purely incremental development&#8211;a similar idea but without the overall plan. In purely incremental development, everything is subject to change. This may [...]]]></description>
			<content:encoded><![CDATA[<p>Usually in incremental development there&#8217;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&#8217;m extending the idea to <strong>purely incremental development</strong>&#8211;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&#8217;s offers the flexibility needed to keep interest up.</p>
<p>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&#8217;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&#8217;s implementation breaks existing functionality.</p>
<p>For unit testing in PHP, the natural choice in PHPUnit. At first, I had some difficulty getting PHPUnit set up from the <a href="http://www.phpunit.de/manual/current/en/installation.html" title="install PHPUnit">installation instructions</a>, but adding a <code>sudo</code> to the beginning of each instruction solved all my problems.</p>
<p>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&#8217;d like to accomplish this in a class structure, and knowing that the machine code for <code>add $t1, $t2, $t0</code> is 0&#215;01484820, the first test verifies that this is the result my code gives.</p>
<pre><code>public function testGetAssemblyCodeAdd() {
    $input = '01484820';
    $expected = 'add $t1, $t2, $t0';
    $temp = new MipsInstruction($input);
    $this->assertEquals($expected, $temp->getAssemblyCode());
}</code></pre>
<p>The easiest way to code this to make it work is to hardcode the output:</p>
<pre><code>class MipsInstruction {
    public function __construct($machineCode) {
        // does nothing
    }

    public function getAssemblyCode() {
        return 'add $t1, $t2, $t0';
    }
}</code></pre>
<p>Running phpunit on the one test now results in <code>OK (1 test, 1 assertion)</code>, whoo! A commit is in order for this. Unfortunately, the code doesn&#8217;t do anything other than pass this one test, so the next step is to add a couple more tests:</p>
<pre><code>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());
}</code></pre>
<p>resulting in:</p>
<pre><code>FAILURES!
Tests: 3, Assertions: 3, Failures: 2</code></pre>
<p>Once again, I&#8217;m making these pass the easy way first and can improve the code later once I know it works.</p>
<pre><code>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';
        }
    }
}</code></pre>
<p>Now that all tests pass, it&#8217;s time to commit and I&#8217;m ready to start refactoring.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flifnotes.com/57-purely-incremental-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Origins of Flif Risc</title>
		<link>http://www.flifnotes.com/56-the-origins-of-flif-risc/</link>
		<comments>http://www.flifnotes.com/56-the-origins-of-flif-risc/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 00:19:39 +0000</pubDate>
		<dc:creator>Deborah Hawkins</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[flif-risc]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.flifnotes.com/?p=56</guid>
		<description><![CDATA[It&#8217;s easy to just lounge in front of the tv when you don&#8217;t have any projects to work on. It&#8217;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&#8217;ll make me that much more productive. Step one: [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s easy to just lounge in front of the tv when you don&#8217;t have any projects to work on. It&#8217;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&#8217;ll make me that much more productive.</p>
<h4>Step one: Come up with an idea</h4>
<p>This was a project I was interested in doing while studying for <a href="http://www.flifnotes.com/39-semester-in-review-spring-10/" title="Semester in Review – Spring ’10">Computer Architecture</a>. It&#8217;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.</p>
<h4>Step Two: Come up with a plan</h4>
<p>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&#8217;m going with a pure incremental development approach and only a general overview of the desired end product.</p>
<p>As far as a technology stack, I&#8217;m using PHP mainly as a language refresher along with Git for my repository.</p>
<h4>Step 3: Set up a repository</h4>
<p>Subversion is my tried-and-true, so this is an opportunity to try another popular version control system that&#8217;s new to me. Fortunately, git has <a href="http://help.github.com/">super easy set-up</a> and hosting on github is free for open-source projects. </p>
<p>As everything is flif to me, you can find this project under the name <a href="https://github.com/flif/Flif-Risc" title="Flif Risc - git repository">Flif Risc</a>. For now, it&#8217;s just an almost empty README, but it&#8217;s a start for things to come.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flifnotes.com/56-the-origins-of-flif-risc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>goto in PHP</title>
		<link>http://www.flifnotes.com/23-goto-in-php/</link>
		<comments>http://www.flifnotes.com/23-goto-in-php/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 04:05:07 +0000</pubDate>
		<dc:creator>Deborah Hawkins</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[goto]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php 5.3]]></category>

		<guid isPermaLink="false">http://www.flifnotes.com/?p=23</guid>
		<description><![CDATA[I had a class in middle school where we did a little bit of programming. I don&#8217;t remember much about it, and the programs we wrote probably weren&#8217;t more than 25 lines. The one thing I do remember is that we used gotos. No object-oriented programming, not even functional programming. The reason I mention this [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://xkcd.com/292/"><img alt="xkcd" src="http://imgs.xkcd.com/comics/goto.png" title="goto" width="455" height="150" /></a></p>
<p>I had a class in middle school where we did a little bit of programming. I don&#8217;t remember much about it, and the programs we wrote probably weren&#8217;t more than 25 lines. The one thing I do remember is that we used <code>goto</code>s. No object-oriented programming, not even functional programming.</p>
<p>The reason I mention this now is that I was talking one of my colleagues today, arguing PHP&#8217;s case, as he supported Python, and I mentioned that as of PHP 5.3, <a href="http://us.php.net/manual/en/control-structures.goto.php">PHP now has a goto operator</a>. He was really hoping that was a joke, and now probably takes the language significantly less seriously.</p>
<p>There are plenty of criticisms of <code>goto</code>, not the least important of which is Edsger Dijkstra&#8217;s <i> <a href="http://en.wikipedia.org/wiki/Go_To_Statement_Considered_Harmful">Go To Statement Considered Harmful</a></i>. The crux of most arguments, though, seems to be that goto statements are not inherently semantic and as such aren&#8217;t appropriate for modern structured languages.</p>
<p>I&#8217;m not using PHP 5.3 yet, so I can&#8217;t say that I&#8217;ve used <code>goto</code> already, but I don&#8217;t see why having a <code>goto</code> operator can make a language intrinsicly bad. There&#8217;s some code that looks gacky however you try to write it, and in some cases a simple <code>goto</code> may actually make it easier to read and understand, even if it also has its share of bad uses.</p>
<p>Looking over some <a href="http://www.procata.com/blog/archives/2004/07/29/goto-in-php/">comments on goto use</a>, one of the concerns I find most interesting is that of the <a href="http://www.procata.com/blog/archives/2004/07/29/goto-in-php/#comment-118">kitchen sink mentality</a>. Personally, I enjoy PHP because I can have one language and use it for procedural, functional, or object-oriented code&#8211;whatever I feel is most appropriate at the time. But, yes, this can also lead to poor coding standards and huge misunderstandings between, say two developers who are both writing code in PHP but with two completely different programming paradigms.</p>
<p>How well a language like this works for you depends on how you use it, and I think I can use it effectively, but if others prefer to work with just one subset at a time&#8211;that&#8217;s totally fine too. Anyhow, I plan to take a look this summer at this awe-inspiring Python that everyone around me keeps evangelizing (except for Jared, who loves Rails), so who knows? Maybe I&#8217;ll be enlightened then.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flifnotes.com/23-goto-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving to WordPress / bbPress</title>
		<link>http://www.flifnotes.com/17-moving-to-wordpress-bbpress/</link>
		<comments>http://www.flifnotes.com/17-moving-to-wordpress-bbpress/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 02:42:47 +0000</pubDate>
		<dc:creator>Deborah Hawkins</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[bbpress]]></category>
		<category><![CDATA[chavez360]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[smf]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.flifnotes.com/?p=17</guid>
		<description><![CDATA[After many months of planning and procrastination, I finally used Spring Break to move my site from plain php for content and SMF for the forum to WordPress with bbPress. As much effort as it took, I have to say that either it was much easier than other conversions and integrations I&#8217;ve experimented with or [...]]]></description>
			<content:encoded><![CDATA[<p>After many months of planning and procrastination, I finally used Spring Break to move my site from plain php for content and SMF for the forum to WordPress with bbPress. As much effort as it took, I have to say that either it was much easier than other conversions and integrations I&#8217;ve experimented with or the experience from those previous experiments has really paid off. </p>
<p>For the most part, I followed affacat&#8217;s instructions on his <a href="http://bbpress.org/forums/topic/successful-convert-smf-gt-phpbb2-gt-bbpress">successful convert from SMF to bbPress</a>, trying it out first on my own machine of course before ready to go live:</p>
<ol>
<li>Install bbPress 0.9.0.4 and WordPress 2.7.1. I chose to put bbPress in a subdirectory of WordPress. Set up the database integration as part of the bbPress installation and delete any posts created on install.</li>
<li>Install the latest phpBB with <a href="http://sourceforge.net/project/showfiles.php?group_id=141446">the necessary converter</a> to move my existing members and posts to bbPress.</li>
<li>Install Jaim&#8217;s <a href="http://bbpress.org/forums/topic/a-phpbb-to-bbpress-database-converter">phpBB to bbPress converter</a>. I had to change bb_users to wp_users, and delete the first user and forum from the SQL because there are already a first user and forum in bbPress. I&#8217;m not sure what the topic_resolved key was from, so I removed that option. Then I copied and pasted the code from bbPress into this tool to generate my topic and username slugs. (There may have been other changes also that I didn&#8217;t keep track of.)</li>
<li>Finally, I imported the SQL into my database.</li>
<li>Install and activate SuperAnn&#8217;s WordPress plugin for <a href="http://superann.com/2009/02/26/wordpress-26-27-bbpress-09-cookie-integration-plugin/">WordPress / bbPress cookie integration</a>.</li>
<li>Activate other plugins.</li>
<li>Post the first blog entry and new forum thread to announce the updates.</li>
</ol>
<p>Man, it feels good to finally have the base I need to build up my site.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flifnotes.com/17-moving-to-wordpress-bbpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

