<?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>Webuml - Developer Notes &#187; tips</title>
	<atom:link href="http://www.webuml.com/blog/category/tips/feed" rel="self" type="application/rss+xml" />
	<link>http://www.webuml.com/blog</link>
	<description>Developer Notes</description>
	<lastBuildDate>Tue, 26 Jan 2010 10:00:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Versioning. For lazy people.</title>
		<link>http://www.webuml.com/blog/versioning-for-lazy-people/79</link>
		<comments>http://www.webuml.com/blog/versioning-for-lazy-people/79#comments</comments>
		<pubDate>Tue, 26 Jan 2010 09:58:45 +0000</pubDate>
		<dc:creator>khelo</dc:creator>
				<category><![CDATA[tips]]></category>
		<category><![CDATA[personal]]></category>
		<category><![CDATA[versioning]]></category>

		<guid isPermaLink="false">http://www.webuml.com/blog/?p=79</guid>
		<description><![CDATA[I am a pretty lazy guy and therefore I want to do all things with as little trouble as possible. Usually , I don&#8217;t plan a certain methodology for my projects, instead , I use an organic approach.  If things are needed, they will be added to my &#8216;methodology&#8217;.
One of the most important issues [...]]]></description>
			<content:encoded><![CDATA[<p>I am a pretty lazy guy and therefore I want to do all things with as little trouble as possible. Usually , I don&#8217;t plan a certain methodology for my projects, instead , I use an organic approach.  If things are needed, they will be added to my &#8216;methodology&#8217;.</p>
<p>One of the most important issues for me is <strong>versioning</strong> . It doesn&#8217;t matter whether you are using svn , git , or whatever, it&#8217;s only important to be able to version via tags ( I use tags) or other mechanisms .</p>
<p>When you work from time to time on a particular project, you will certainly loose track of what you do and you will probably forget most of your code.   For me it&#8217;s important to know the differences between versions, even if I don&#8217;t plan them.</p>
<p>The standard <strong>versioning </strong>system is composed of 3 digits : like <strong>x.y.z</strong> . Most of the people think these numbers are random , or incremental , but they are not. For example if product A has the version 1.1.0 and the next version is 1.1.1 , i will know that some bugs have been fixed.  A <strong>changelog</strong> will  further detail this . If the next version will be 1.2.0 I know that some new features will be added to the product. If the new version will be 2.0 I know product A will go trough major changes and most of the base code will be rewritten and improved (also means backwards compatibility is broken).  And finally , if product A is versioned 0.y.z , I will know that the product is not considered ready yet.</p>
<h2>How do I use this in my projects?</h2>
<p>If I work on small things , bug related stuff, I will increase the minor ( z) . So from 0.1.0 I will go to 0.1.2 .</p>
<p>If I add new features, I will increase the middle digit (y). So from 0.1.0 I will go to 0.2.0 .</p>
<p>If I finish a first stable and complete version, I will go from 0.1.0 to 1.0.0 .</p>
<h2>At deploy</h2>
<p>Let&#8217;s say my current version is 0.1.2 and  the new version is 0.2.0 . My site being www.example.com , I find it convenient to create the following subdomains : <strong>sandbox</strong> and <strong>history</strong>.</p>
<p>First , I will place the new version ,  0.2.0 in the sandbox environment. All the testing will be done there. If everything looks ok,  example.com  contents  will move to history, and sandbox will move to the live site, example. com</p>
<p>So at this point, the environments will be as follow:</p>
<pre><strong>example.com - 0.2.0
sandbox.example.com - 0.2.0
history.example.com  -  0.1.2</strong></pre>
<p>If anything goes wrong , I will easily revert example.com to 0.1.2 , using the history environment.</p>
<p>Having versioning in place , allows you to see all the changes that took place in time , and also provide snapshot of your application from the past.  If you provide meaningful description to your commits, you will be able to generate a nice automated text that will build your changelog.</p>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webuml.com/blog/versioning-for-lazy-people/79/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using a decorator for caching purposes</title>
		<link>http://www.webuml.com/blog/using-a-decorator-for-caching-purposes/62</link>
		<comments>http://www.webuml.com/blog/using-a-decorator-for-caching-purposes/62#comments</comments>
		<pubDate>Wed, 18 Nov 2009 12:53:36 +0000</pubDate>
		<dc:creator>khelo</dc:creator>
				<category><![CDATA[tips]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[decorator]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.webuml.com/blog/?p=62</guid>
		<description><![CDATA[In my previous post I  gave some examples on  how caching can evolve.   However , what annoys  me in the  second and third approach is that I have some extra code and  dependencies  which are not really related to my class.  The examples bellow detail how you can use a decorator to cache another class.

class [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://www.webuml.com/blog/?p=49">previous</a> post I  gave some examples on  how caching can evolve.   However , what annoys  me in the  second and third approach is that I have some extra code and  dependencies  which are not really related to my class.  The examples bellow detail how you can use a decorator to cache another class.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Foo
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getExpensiveData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getNotSoExpensiveData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getUnbelievableExpensiveData<span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//no hardware in the world can scale this</span>
        <span style="color: #990000;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'string'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Foo_Decorator_Exception <span style="color: #000000; font-weight: bold;">extends</span> Exception<span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Foo_Decorator
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$source</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span>Foo <span style="color: #000088;">$foo</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">source</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$foo</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$tag</span>    <span style="color: #339933;">=</span> <span style="color: #000088;">$method</span><span style="color: #339933;">.</span><span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'getUnbelievableExpensiveData'</span><span style="color: #339933;">:</span>
            <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'getExpensiveData'</span><span style="color: #339933;">:</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>Cache<span style="color: #339933;">::</span><span style="color: #004000;">isCached</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tag</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    Cache<span style="color: #339933;">::</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$tag</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
                <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> Cache<span style="color: #339933;">::</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tag</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">default</span> <span style="color: #339933;">:</span>
                <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">source</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            throw <span style="color: #000000; font-weight: bold;">new</span> Foo_Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No delegate object set&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$delegate</span>        <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">source</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$method_variable</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$delegate</span><span style="color: #339933;">,</span> <span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$callableName</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">is_callable</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$method_variable</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$callableName</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">call_user_func_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$method_variable</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            throw <span style="color: #000000; font-weight: bold;">new</span> Foo_Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Function missing in both decorate and delegate object&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.webuml.com/blog/using-a-decorator-for-caching-purposes/62/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Three simple php caching tehniques</title>
		<link>http://www.webuml.com/blog/three-simple-php-caching-techniques/49</link>
		<comments>http://www.webuml.com/blog/three-simple-php-caching-techniques/49#comments</comments>
		<pubDate>Tue, 10 Nov 2009 15:20:37 +0000</pubDate>
		<dc:creator>khelo</dc:creator>
				<category><![CDATA[tips]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[simple]]></category>

		<guid isPermaLink="false">http://www.webuml.com/blog/?p=49</guid>
		<description><![CDATA[No talking . Just examples
class Foo
{
    private static $_bar = null;

    private function getBar()
    {
        if ( null == self::$_bar) {
            //very expensive operation
     [...]]]></description>
			<content:encoded><![CDATA[<p>No talking . Just examples</p>
<pre>class Foo
{</pre>
<pre>    private static $_bar = null;

    private function getBar()
    {
        if ( null == self::$_bar) {
            //very expensive operation
            self::$bar = $this-&gt;expensiveOperation();
        }

        return self::$bar;
    }

    private function expensiveOperation()
    {
        return 1+1;//wow
    }
}</pre>
<p>Extending the example</p>
<pre>class Foo
{</pre>
<pre>    private function getBar()
    {
        if ( !this-&gt;isCached()) {
            //very expensive operation
            $this-&gt;saveCache($this-&gt;expensiveOperation);
        }

        return $this-&gt;getCache();
    }

    protected function saveCache($value)
    {
        file_put_contents($this-&gt;getCachePath(),$value);
    }

    protected function getCache()
    {
        return file_get_contents($this-&gt;getCachePath());
    }

    protected function isCached()
    {
        return is_file($this-&gt;getCachePath());
    }

    private function getCachePath()
    {
        return '/path/to/somefile.txt';
    }
<pre>    private function expensiveOperation()
    {
        return 1+1;//wow
    }
}</pre>
<p>Final example</p>
<pre>class Cache
{
    public static function isCached($tag)
    {
        return is_file(self::isFile(self::getCacheFile($tag)));
    }

    public static function save($value , $tag)
    {

        $file = self::getCacheFile($tag);
        file_put_contents($file , $value);
    }

    public static function load( $tag)
    {
        $file = self::getCacheFile($tag);
        return file_get_contents($file);
    }

    private static function getCachePath($tag)
    {
        return "/path/to/somefile_$tag.txt";
    }
}

class Foo
{
    public static function getBar()
    {
       if ( !Cache::isCached('my_tag')) {
            //very expensive operation
            Cache::save($this-&gt;expensiveOperation(),'my_tag');
        }
        return $this-&gt;load('my_tag');
    }

    private function expensiveOperation()
    {
        return 1+1;//wow
    }
}

All three examples are variations of the same technique.
Of course , the  <strong>file_get_contents</strong> thing is used for the example's sake only</pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.webuml.com/blog/three-simple-php-caching-techniques/49/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
