<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Simone 'Wiz' Tellini - Software Development</title>
    <link>http://tellini.info/blog/</link>
    <description>To strive, to seek, to find, and not to yield.</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.3 - http://www.s9y.org/</generator>
    <pubDate>Tue, 05 Aug 2008 06:01:52 GMT</pubDate>

    <image>
        <url>http://tellini.info/blog/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: Simone 'Wiz' Tellini - Software Development - To strive, to seek, to find, and not to yield.</title>
        <link>http://tellini.info/blog/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Quote of the Day</title>
    <link>http://tellini.info/blog/archives/71-Quote-of-the-Day.html</link>
            <category>Quotes</category>
            <category>Software Development</category>
    
    <comments>http://tellini.info/blog/archives/71-Quote-of-the-Day.html#comments</comments>
    <wfw:comment>http://tellini.info/blog/wfwcomment.php?cid=71</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://tellini.info/blog/rss.php?version=2.0&amp;type=comments&amp;cid=71</wfw:commentRss>
    

    <author>nospam@example.com (Simone)</author>
    <content:encoded>
    &lt;blockquote&gt;[...] a good programmer cultivates the virtue of laziness. (But not just any laziness: you must be aggressively, proactively lazy!)&lt;/blockquote&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;-- Chris Pine&lt;/em&gt;, dealing with the &lt;a href=&quot;http://blogs.msdn.com/steverowe/archive/2008/05/15/design-principle-don-t-repeat-yourself.aspx&quot;&gt;DRY rule&lt;/a&gt; 
    </content:encoded>

    <pubDate>Mon, 04 Aug 2008 22:53:09 -0700</pubDate>
    <guid isPermaLink="false">http://tellini.info/blog/archives/71-guid.html</guid>
    <category>laziness</category>
<category>quotes</category>
<category>software development</category>

</item>
<item>
    <title>Quote of the Day</title>
    <link>http://tellini.info/blog/archives/68-Quote-of-the-Day.html</link>
            <category>Quotes</category>
            <category>Software Development</category>
    
    <comments>http://tellini.info/blog/archives/68-Quote-of-the-Day.html#comments</comments>
    <wfw:comment>http://tellini.info/blog/wfwcomment.php?cid=68</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://tellini.info/blog/rss.php?version=2.0&amp;type=comments&amp;cid=68</wfw:commentRss>
    

    <author>nospam@example.com (Simone)</author>
    <content:encoded>
    &lt;blockquote&gt;Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.&lt;/blockquote&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;-- Richard Cook, read on &lt;a href=&quot;http://www.freesoftwaremagazine.com/columns/dont_compare_gnu_linux_windows_or_macos_they_are_not_same_game&quot;&gt;FSM&lt;/a&gt;&lt;/em&gt; 
    </content:encoded>

    <pubDate>Sat, 12 Jul 2008 12:15:14 -0700</pubDate>
    <guid isPermaLink="false">http://tellini.info/blog/archives/68-guid.html</guid>
    <category>idiots</category>
<category>quotes</category>
<category>software development</category>
<category>universe</category>

</item>
<item>
    <title>Quote of the Day</title>
    <link>http://tellini.info/blog/archives/67-Quote-of-the-Day.html</link>
            <category>Quotes</category>
            <category>Software Development</category>
    
    <comments>http://tellini.info/blog/archives/67-Quote-of-the-Day.html#comments</comments>
    <wfw:comment>http://tellini.info/blog/wfwcomment.php?cid=67</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://tellini.info/blog/rss.php?version=2.0&amp;type=comments&amp;cid=67</wfw:commentRss>
    

    <author>nospam@example.com (Simone)</author>
    <content:encoded>
    &lt;blockquote&gt;[...] as we all know, premature optimization is the root of all evil.&lt;/blockquote&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;-- from a &lt;a href=&quot;http://lists.apple.com/mailman/listinfo/cocoa-dev/&quot;&gt;cocoa-dev&lt;/a&gt; email&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
amen! 
    </content:encoded>

    <pubDate>Sun, 06 Jul 2008 21:21:04 -0700</pubDate>
    <guid isPermaLink="false">http://tellini.info/blog/archives/67-guid.html</guid>
    <category>optimization</category>
<category>quotes</category>
<category>software development</category>

</item>
<item>
    <title>Single instance per session application with argument passing</title>
    <link>http://tellini.info/blog/archives/61-Single-instance-per-session-application-with-argument-passing.html</link>
            <category>Software Development</category>
    
    <comments>http://tellini.info/blog/archives/61-Single-instance-per-session-application-with-argument-passing.html#comments</comments>
    <wfw:comment>http://tellini.info/blog/wfwcomment.php?cid=61</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://tellini.info/blog/rss.php?version=2.0&amp;type=comments&amp;cid=61</wfw:commentRss>
    

    <author>nospam@example.com (Simone)</author>
    <content:encoded>
    Suppose you want to create an application which you want to limit to a single running instance, like some image viewers do for example. Also, you need different users on a Terminal Server not to conflict with each other. Oh, and you&#039;re coding in C#.&lt;br /&gt;
&lt;br /&gt;
A possible solution to the problem is the one described in &lt;a href=&quot;http://www.flawlesscode.com/post/2008/02/Enforcing-single-instance-with-argument-passing.aspx&quot;&gt;this Flawless Code post&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
What I didn&#039;t like is, it requires the 3.5 version of the framework, while I preferred to be able to run on machines with only 2.0 installed. So I&#039;ve replaced the NamedPipeClientStream/NamedPipeServerStream with a P/Invoke-based implementation based on &lt;a href=&quot;http://blog.paranoidferret.com/index.php/2007/07/25/interprocess-communication-using-named-pipes-in-csharp/&quot;&gt;this example&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Also, I create a different pipe per user session, since I haven&#039;t found a way to create a &quot;local&quot; pipe. An article at &lt;a href=&quot;http://www.drdobbs.com/windows/184416711&quot;&gt;Dr Dobb&#039;s&lt;/a&gt; suggests that  it&#039;s possible, while &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa365150(VS.85).aspx&quot;&gt;MSDN&lt;/a&gt; doesn&#039;t mention this possibility...&lt;br /&gt;
&lt;br /&gt;
I&#039;ve zipped up my &lt;a href=&quot;http://files.tellini.info/SingleInstanceApp.zip&quot;&gt;test solution&lt;/a&gt; in case someone else has the same needs. 
    </content:encoded>

    <pubDate>Wed, 04 Jun 2008 12:44:00 -0700</pubDate>
    <guid isPermaLink="false">http://tellini.info/blog/archives/61-guid.html</guid>
    <category>.net</category>
<category>c#</category>
<category>ipc</category>
<category>software development</category>

</item>
<item>
    <title>How much would it cost to rewrite it?</title>
    <link>http://tellini.info/blog/archives/60-How-much-would-it-cost-to-rewrite-it.html</link>
            <category>Software</category>
            <category>Software Development</category>
    
    <comments>http://tellini.info/blog/archives/60-How-much-would-it-cost-to-rewrite-it.html#comments</comments>
    <wfw:comment>http://tellini.info/blog/wfwcomment.php?cid=60</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://tellini.info/blog/rss.php?version=2.0&amp;type=comments&amp;cid=60</wfw:commentRss>
    

    <author>nospam@example.com (Simone)</author>
    <content:encoded>
    I&#039;ve just added &lt;a href=&quot;http://logminer.tellini.info/&quot;&gt;LogMiner&lt;/a&gt; to &lt;a href=&quot;http://www.ohloh.net/projects/logminer&quot;&gt;Ohloh&lt;/a&gt;, a site that offers an interesting feature: it can analyse a project source code and estimate how much it would cost to hire a development team to recreate the project from scratch.&lt;br /&gt;
&lt;br /&gt;
I think that it&#039;s a simple way to estimate the effort you put over the time in open source projects.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s the resulting figure for LogMiner:&lt;br /&gt;
&lt;div align=&quot;center&quot; style=&quot;border-style: none&quot;&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://www.ohloh.net/projects/14626/widgets/project_partner_badge&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt; 
    </content:encoded>

    <pubDate>Mon, 02 Jun 2008 17:13:44 -0700</pubDate>
    <guid isPermaLink="false">http://tellini.info/blog/archives/60-guid.html</guid>
    <category>logminer</category>
<category>software</category>
<category>software development</category>

</item>
<item>
    <title>If at first you don't succeed... try, try again...</title>
    <link>http://tellini.info/blog/archives/58-If-at-first-you-dont-succeed...-try,-try-again....html</link>
            <category>Coding fun</category>
    
    <comments>http://tellini.info/blog/archives/58-If-at-first-you-dont-succeed...-try,-try-again....html#comments</comments>
    <wfw:comment>http://tellini.info/blog/wfwcomment.php?cid=58</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://tellini.info/blog/rss.php?version=2.0&amp;type=comments&amp;cid=58</wfw:commentRss>
    

    <author>nospam@example.com (Simone)</author>
    <content:encoded>
    Here&#039;s another &lt;em&gt;interesting&lt;/em&gt; piece of code I&#039;ve just digged up in a C# application I&#039;m reviewing.&lt;br /&gt;
&lt;br /&gt;
If you can come up with a bright idea about what those try/catch blocks are supposed to do, you&#039;ve got more imagination than me... &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;csharp&quot; style=&quot;text-align: left&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;class&lt;/span&gt; Foo&lt;br /&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0600FF;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;int&lt;/span&gt; bar;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #008080; font-style: italic;&quot;&gt;// ...snip...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0600FF;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;int&lt;/span&gt; GetNewBar&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #FF0000;&quot;&gt;int&lt;/span&gt; ret = &lt;span style=&quot;color: #FF0000;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0600FF;&quot;&gt;lock&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0600FF;&quot;&gt;try&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; bar++;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; ret = bar;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0600FF;&quot;&gt;catch&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0600FF;&quot;&gt;try&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; bar++;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; ret = bar;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0600FF;&quot;&gt;catch&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0600FF;&quot;&gt;return&lt;/span&gt; ret;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #008080; font-style: italic;&quot;&gt;// ...snip...&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;/div&gt; 
    </content:encoded>

    <pubDate>Mon, 19 May 2008 16:57:02 -0700</pubDate>
    <guid isPermaLink="false">http://tellini.info/blog/archives/58-guid.html</guid>
    <category>coding fun</category>
<category>fun</category>
<category>software development</category>

</item>
<item>
    <title>Don't code like this at home, kids</title>
    <link>http://tellini.info/blog/archives/57-Dont-code-like-this-at-home,-kids.html</link>
            <category>Coding fun</category>
    
    <comments>http://tellini.info/blog/archives/57-Dont-code-like-this-at-home,-kids.html#comments</comments>
    <wfw:comment>http://tellini.info/blog/wfwcomment.php?cid=57</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://tellini.info/blog/rss.php?version=2.0&amp;type=comments&amp;cid=57</wfw:commentRss>
    

    <author>nospam@example.com (Simone)</author>
    <content:encoded>
    Sometimes when you&#039;re reviewing someone else&#039;s code, you find interesting pieces of &quot;&lt;em&gt;art&lt;/em&gt;&quot;. Like the following loop construct in a C# application:&lt;br /&gt;
&lt;div class=&quot;csharp&quot; style=&quot;text-align: left&quot;&gt;&lt;br /&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #FF0000;&quot;&gt;int&lt;/span&gt; i = anArray.&lt;span style=&quot;color: #0000FF;&quot;&gt;Length&lt;/span&gt; - &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #0600FF;&quot;&gt;while&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0600FF;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;i &amp;lt; &lt;span style=&quot;color: #FF0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0600FF;&quot;&gt;break&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0600FF;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;...&amp;#160; &amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000FF;&quot;&gt;i&lt;/span&gt;--;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Doh.&lt;br /&gt;
&lt;br /&gt;
You might be tempted to rewrite it as:&lt;br /&gt;
&lt;div class=&quot;csharp&quot; style=&quot;text-align: left&quot;&gt;&lt;br /&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #0600FF;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;int&lt;/span&gt; i = anArray.&lt;span style=&quot;color: #0000FF;&quot;&gt;Length&lt;/span&gt; - &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;; i &amp;gt;= &lt;span style=&quot;color: #FF0000;&quot;&gt;0&lt;/span&gt;; i-- &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;...&amp;#160; &amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;/div&gt;&lt;br /&gt;
but it would be too simple, too boring, wouldn&#039;t it? 
    </content:encoded>

    <pubDate>Wed, 14 May 2008 10:25:13 -0700</pubDate>
    <guid isPermaLink="false">http://tellini.info/blog/archives/57-guid.html</guid>
    <category>coding fun</category>
<category>fun</category>
<category>software development</category>

</item>
<item>
    <title>Quote of the Day</title>
    <link>http://tellini.info/blog/archives/54-Quote-of-the-Day.html</link>
            <category>Fun</category>
            <category>Quotes</category>
            <category>Software Development</category>
    
    <comments>http://tellini.info/blog/archives/54-Quote-of-the-Day.html#comments</comments>
    <wfw:comment>http://tellini.info/blog/wfwcomment.php?cid=54</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://tellini.info/blog/rss.php?version=2.0&amp;type=comments&amp;cid=54</wfw:commentRss>
    

    <author>nospam@example.com (Simone)</author>
    <content:encoded>
    &lt;blockquote&gt;I always assumed the designers of the Objective-C language and Cocoa frameworks trust me to know what I&#039;m doing while I find very elegant ways to shoot myself in the foot.&lt;/blockquote&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;-- from a mail sent to &lt;a href=&quot;http://lists.apple.com/mailman/listinfo/cocoa-dev/&quot;&gt;Cocoa-dev&lt;/a&gt;&lt;/em&gt; 
    </content:encoded>

    <pubDate>Fri, 18 Apr 2008 12:07:59 -0700</pubDate>
    <guid isPermaLink="false">http://tellini.info/blog/archives/54-guid.html</guid>
    <category>cocoa</category>
<category>fun</category>
<category>objective-c</category>
<category>quotes</category>
<category>software development</category>

</item>
<item>
    <title>PHP templates</title>
    <link>http://tellini.info/blog/archives/47-PHP-templates.html</link>
            <category>Software Development</category>
    
    <comments>http://tellini.info/blog/archives/47-PHP-templates.html#comments</comments>
    <wfw:comment>http://tellini.info/blog/wfwcomment.php?cid=47</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://tellini.info/blog/rss.php?version=2.0&amp;type=comments&amp;cid=47</wfw:commentRss>
    

    <author>nospam@example.com (Simone)</author>
    <content:encoded>
    When you design a complex application, it&#039;s always useful to separate the presentation layer from the business logic. Usually, when dealing with web apps, this involves handing templates which are &quot;filled&quot; with data by your controller.&lt;br /&gt;
&lt;br /&gt;
The common rationale is that the template should contain as little logic as possible and that it should be easily editable by non-programmers.&lt;br /&gt;
&lt;br /&gt;
There are &lt;a href=&quot;http://www.whenpenguinsattack.com/2006/07/19/php-template-engine-roundup/&quot;&gt;several PHP packages&lt;/a&gt; (Smarty, PHPTal, etc...) that aim at providing a flexible and neat template framework. They usually try to force you not to put code in the template by providing a limited set of directives that can be used, such as placeholders, foreach-style control blocks, conditional blocks... but in the end, every framework I&#039;ve seen also includes a directive that allows you to put arbitrary PHP code inside the template.&lt;br /&gt;
&lt;br /&gt;
Thus I&#039;ve always wondered: what&#039;s the point? Why don&#039;t you just use PHP as a templating engine instead of inventing a new language? &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
So, let me introduce my super-duper template class!&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;php&quot; style=&quot;text-align: left&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/*&lt;br /&gt;&amp;#160;* Copyright ©2007-2008 by Simone Tellini&lt;br /&gt;&amp;#160;* http://tellini.info/&lt;br /&gt;&amp;#160;*/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; Template&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; private &lt;a href=&quot;http://www.php.net/static&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;static&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$commonVars&lt;/span&gt; = &lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; private &lt;span style=&quot;color: #0000ff;&quot;&gt;$tpl&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; private &lt;span style=&quot;color: #0000ff;&quot;&gt;$vars&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; __construct&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$template&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;tpl&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$template&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;vars&lt;/span&gt; = self::&lt;span style=&quot;color: #0000ff;&quot;&gt;$commonVars&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// you might set some variables before instantiating your templates when&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// you want to have some data available in all the templates you need to&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// build a complex page&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; public &lt;a href=&quot;http://www.php.net/static&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;static&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; setCommon&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$key&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$value&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; self::&lt;span style=&quot;color: #0000ff;&quot;&gt;$commonVars&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$key&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$value&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; set&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$key&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$value&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;vars&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$key&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$value&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; execute&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$T&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;vars&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;a href=&quot;http://www.php.net/ob_start&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;ob_start&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;include&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;tpl&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$html&lt;/span&gt; = &lt;a href=&quot;http://www.php.net/ob_get_contents&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;ob_get_contents&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;a href=&quot;http://www.php.net/ob_end_clean&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;ob_end_clean&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$html&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Ta-da!&lt;br /&gt;
&lt;br /&gt;
A sample template may look like:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;php&quot; style=&quot;text-align: left&quot;&gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;Hello, &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?&lt;/span&gt;= &lt;span style=&quot;color: #0000ff;&quot;&gt;$T&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;user&#039;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;!&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&amp;#160;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
The &lt;strong&gt;$T&lt;/strong&gt; array is the only variable visible to the template (except for $this, which points to the Template instance and the super-variables $_GET, $_POST, etc...), since it&#039;s the only variable defined in the scope where the template has been include()&#039;d&lt;br /&gt;
&lt;br /&gt;
The controller might look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;php&quot; style=&quot;text-align: left&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;require_once&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;classes/template.php&#039;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$tpl&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; Template&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;templates/helloWorld.php&#039;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$tpl&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;user&#039;&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;World&#039;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &lt;a href=&quot;http://www.php.net/print&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;print&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$tpl&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;execute&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
I&#039;ve been using a class like that for a couple of years now, without any regret. It&#039;s been used in sites whose content and graphics are now constantly edited by their owners: even though they aren&#039;t programmers, they never had any problem whatsoever in editing or creating their own templates. I truly like it beacuse:&lt;br /&gt;
&lt;ul&gt;&lt;br /&gt;
  &lt;li&gt; it&#039;s simple &lt;/li&gt;&lt;br /&gt;
  &lt;li&gt; it surely isn&#039;t bloated &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt; &lt;/li&gt;&lt;br /&gt;
  &lt;li&gt; it&#039;s faster than many (most?) of the other templating engines &lt;/li&gt;&lt;br /&gt;
  &lt;li&gt; it&#039;s as flexible as you need &lt;/li&gt;&lt;br /&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
Of course, the fact that you&#039;re using PHP to create your templates shouldn&#039;t tempt you to start placing business logic inside them! 
    </content:encoded>

    <pubDate>Thu, 24 Jan 2008 22:21:31 -0800</pubDate>
    <guid isPermaLink="false">http://tellini.info/blog/archives/47-guid.html</guid>
    <category>php</category>
<category>software development</category>

</item>
<item>
    <title>Attributes, reflection and PHP</title>
    <link>http://tellini.info/blog/archives/46-Attributes,-reflection-and-PHP.html</link>
            <category>Software Development</category>
            <category>Tips'n'Tricks</category>
    
    <comments>http://tellini.info/blog/archives/46-Attributes,-reflection-and-PHP.html#comments</comments>
    <wfw:comment>http://tellini.info/blog/wfwcomment.php?cid=46</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://tellini.info/blog/rss.php?version=2.0&amp;type=comments&amp;cid=46</wfw:commentRss>
    

    <author>nospam@example.com (Simone)</author>
    <content:encoded>
    After a long exposure to .NET, when I get back to PHP I sometimes find myself missing some cool functionality (and a good IDE too... none of those I&#039;ve tried so far can compete with the comfort of VisualStudio + ReSharper).&lt;br /&gt;
&lt;br /&gt;
Among these missing features, &lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/xtwkdas5.aspx&quot; title=&quot;Attributes Overview&quot;&gt;attributes&lt;/a&gt; are what I needed in order to solve a certain problem in an elegant way.&lt;br /&gt;
&lt;br /&gt;
Looking at what the &lt;a href=&quot;http://www.php.net/oop5.reflection&quot;&gt;reflection API&lt;/a&gt; was offering, I came up with a simple way to decorate my properties/methods/classes with attributes: through the documentation comments!&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see an example:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;php&quot; style=&quot;text-align: left&quot;&gt;&lt;br /&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; A&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160;&amp;#160; * @attr&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160;&amp;#160; * @attr2&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160;&amp;#160; */&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; protected &lt;span style=&quot;color: #0000ff;&quot;&gt;$foo&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; protected &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; GetPropAttrs&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$property&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$class&lt;/span&gt;&amp;#160; &amp;#160;= &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; ReflectionClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;a href=&quot;http://www.php.net/get_class&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;get_class&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$prop&lt;/span&gt;&amp;#160; &amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$class&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getProperty&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$property&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$doc&lt;/span&gt;&amp;#160; &amp;#160; &amp;#160;= &lt;span style=&quot;color: #0000ff;&quot;&gt;$prop&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getDocComment&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attrs&lt;/span&gt;&amp;#160; &amp;#160;= &lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$matches&lt;/span&gt; = &lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;a href=&quot;http://www.php.net/preg_match_all&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;preg_match_all&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;/@([a-zA-Z_][a-zA-Z_0-9]*)&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\s&lt;/span&gt;/m&#039;&lt;/span&gt;,&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$doc&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$matches&lt;/span&gt;, PREG_SET_ORDER &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$matches&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$m&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attrs&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$m&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attrs&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; test&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attrs&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;GetPropAttrs&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;foo&#039;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;a href=&quot;http://www.php.net/print_r&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;print_r&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attrs&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; B&lt;br /&gt;extends A&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160;&amp;#160; * @attr3&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160;&amp;#160; */&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; protected &lt;span style=&quot;color: #0000ff;&quot;&gt;$foo&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$obj&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; A&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://www.php.net/print&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;print&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;Test A:&amp;lt;br&amp;gt;&#039;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$obj&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$obj&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; B&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://www.php.net/print&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;print&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;&amp;lt;p&amp;gt;Test B:&amp;lt;br&amp;gt;&#039;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$obj&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;&amp;#160;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Running the above script you&#039;ll see the following output, confirming that everything works as desired:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
Test A:&lt;br /&gt;
Array&lt;br /&gt;
(&lt;br /&gt;
    [0] =&gt; attr&lt;br /&gt;
    [1] =&gt; attr2&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
Test B:&lt;br /&gt;
Array ( [0] =&gt; attr3 ) &lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
If you&#039;re using the /** */ comments for real documentation, you might want to use another escape character rather than @, to avoid problems.&lt;br /&gt;
&lt;br /&gt;
Happy coding &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt; 
    </content:encoded>

    <pubDate>Sun, 13 Jan 2008 12:16:00 -0800</pubDate>
    <guid isPermaLink="false">http://tellini.info/blog/archives/46-guid.html</guid>
    <category>php</category>
<category>reflection</category>
<category>software development</category>
<category>tips'n'tricks</category>

</item>
<item>
    <title>Is MySQL bad for (open source) software quality?</title>
    <link>http://tellini.info/blog/archives/44-Is-MySQL-bad-for-open-source-software-quality.html</link>
            <category>Software Development</category>
    
    <comments>http://tellini.info/blog/archives/44-Is-MySQL-bad-for-open-source-software-quality.html#comments</comments>
    <wfw:comment>http://tellini.info/blog/wfwcomment.php?cid=44</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://tellini.info/blog/rss.php?version=2.0&amp;type=comments&amp;cid=44</wfw:commentRss>
    

    <author>nospam@example.com (Simone)</author>
    <content:encoded>
    I think so.&lt;br /&gt;
&lt;br /&gt;
Why? Because it&#039;s basically a toy DBMS with too many non-standard behaviours.&lt;br /&gt;
&lt;br /&gt;
A lot of open source projects choose &lt;a href=&quot;http://www.mysql.com&quot;&gt;MySQL&lt;/a&gt; mainly because it&#039;s widely available among hosting providers, while better RDBMS like &lt;a href=&quot;http://www.postgresql.org/&quot; title=&quot;PostgreSQL&quot;&gt;PostgreSQL&lt;/a&gt;&lt;sup&gt;1&lt;/sup&gt; are hard to find. The real problem is, a lot of open source developer know very little about SQL and databases: they make things up as they proceed in their project, almost often caring only that &quot;it works&quot; for them&lt;sup&gt;2&lt;/sup&gt;. The result is that they learn wrong habits and write poor DB-related code, a trait common to many projects, sadly.&lt;br /&gt;
&lt;br /&gt;
For instance, the inspiration for this rant comes from &lt;a href=&quot;http://bugs.flyspray.org/task/1338&quot;&gt;this bug report&lt;/a&gt; for &lt;a href=&quot;http://www.flyspray.org/&quot;&gt;Flyspray&lt;/a&gt;, a bug reporting system written in &lt;a href=&quot;http://www.php.net&quot;&gt;PHP&lt;/a&gt;. The report is about a pretty lame error in the SQL query used to fetch the task list, as detailed in the &lt;a href=&quot;http://bugs.flyspray.org/task/1338#comment3854&quot;&gt;9th comment&lt;/a&gt;. PostgreSQL is not &quot;incredibly annoying regarding GROUP BY&quot; as the Flyspray maintainer believes: PostgreSQL simply does the right thing to do in that case, just like every other serious&lt;sup&gt;3&lt;/sup&gt; RDBMS on the market. I was recently hired to port Flyspray to Oracle: needless to say that I had to fix this problem as well as several other queries.&lt;br /&gt;
&lt;br /&gt;
Other examples of DB abuse include &lt;a href=&quot;http://www.mantisbt.org&quot;&gt;Mantis&lt;/a&gt;, another PHP bugtracker. If you had a chance to use it, probably you&#039;ve seen the statistics at the bottom of the page, something like:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
43 total queries executed.&lt;br /&gt;
30 unique queries executed.&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
I beg your pardon? 43 queries to display a 10 rows table? and why 13 of them have been performed twice? &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
So, please... kids don&#039;t use MySQL at home. &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
I&#039;m not saying that you should never use MySQL (there would be plenty of reasons to avoid it anyway &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;) or that projects based on it suck (I like mantis, for one). It&#039;s simply a bad choice for a beginner wishing to learn how to do things properly, IMHO.&lt;br /&gt;
&lt;br /&gt;
&lt;small&gt;&lt;br /&gt;
&lt;sup&gt;1&lt;/sup&gt; my favorite open source RDBMS. If it seems like I&#039;m doing some advocacy, well... maybe I am &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
&lt;sup&gt;2&lt;/sup&gt; I&#039;ve got nothing against this attitude when it comes to free software: if you want things to get done as &lt;em&gt;you&lt;/em&gt; wish, you should be prepared to do them yourself or pay for them, instead of &lt;em&gt;expecting&lt;/em&gt; other people to do the dirty work for free &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
&lt;sup&gt;3&lt;/sup&gt; yes, that excludes MySQL &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/tongue.png&quot; alt=&quot;:-P&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
&lt;/small&gt; 
    </content:encoded>

    <pubDate>Fri, 04 Jan 2008 15:54:00 -0800</pubDate>
    <guid isPermaLink="false">http://tellini.info/blog/archives/44-guid.html</guid>
    <category>database</category>
<category>mysql</category>
<category>oracle</category>
<category>postgresql</category>
<category>rant</category>
<category>software development</category>

</item>
<item>
    <title>The meaning of const in C</title>
    <link>http://tellini.info/blog/archives/40-The-meaning-of-const-in-C.html</link>
            <category>Software Development</category>
    
    <comments>http://tellini.info/blog/archives/40-The-meaning-of-const-in-C.html#comments</comments>
    <wfw:comment>http://tellini.info/blog/wfwcomment.php?cid=40</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://tellini.info/blog/rss.php?version=2.0&amp;type=comments&amp;cid=40</wfw:commentRss>
    

    <author>nospam@example.com (Simone)</author>
    <content:encoded>
    John Engelhart posted to &lt;a href=&quot;http://lists.apple.com/mailman/listinfo/cocoa-dev&quot; &gt;Cocoa-dev&lt;/a&gt; a &lt;a href=&quot;http://lists.apple.com/archives/cocoa-dev/2007/Dec/msg00373.html&quot;  title=&quot;about the const keyword&quot;&gt;detailed explanation&lt;/a&gt; of what exactly &lt;strong&gt;const&lt;/strong&gt; means in C programs.&lt;br /&gt;
&lt;br /&gt;
Keep in mind that he&#039;s talking about &lt;em&gt;C&lt;/em&gt;, not C++ (where &lt;strong&gt;const&lt;/strong&gt; has a stronger meaning and even a slightly different semantic when used to declare constant values).&lt;br /&gt;
&lt;br /&gt;
Still, it&#039;s worth reading. 
    </content:encoded>

    <pubDate>Sat, 08 Dec 2007 14:06:27 -0800</pubDate>
    <guid isPermaLink="false">http://tellini.info/blog/archives/40-guid.html</guid>
    <category>c</category>
<category>software development</category>

</item>
<item>
    <title>A little rant about .NET's ReportViewer</title>
    <link>http://tellini.info/blog/archives/37-A-little-rant-about-.NETs-ReportViewer.html</link>
            <category>Software Development</category>
    
    <comments>http://tellini.info/blog/archives/37-A-little-rant-about-.NETs-ReportViewer.html#comments</comments>
    <wfw:comment>http://tellini.info/blog/wfwcomment.php?cid=37</wfw:comment>

    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://tellini.info/blog/rss.php?version=2.0&amp;type=comments&amp;cid=37</wfw:commentRss>
    

    <author>nospam@example.com (Simone)</author>
    <content:encoded>
    The .NET Framework 2.0 contains a component called ReportViewer which can be used to generate reports in different formats (HTML, PDF, etc...).&lt;br /&gt;
&lt;br /&gt;
After having used it for a couple of reports in a web application, I came to believe that the only good thing about it is that it&#039;s free (when used in Local mode).&lt;br /&gt;
&lt;br /&gt;
Why? Because of its bug ridden designer!&lt;br /&gt;
&lt;br /&gt;
First of all, it contains a nice &quot;Data Sources&quot; panel that should list all the functions (from your code) that can be used to feed the report. Wonderful. Too bad that unless you keep the Default.aspx page open it doesn&#039;t display anything.&lt;br /&gt;
&lt;br /&gt;
Also, you should place the .rdlc file in your App_Code folder to get the &quot;Data Sources&quot; list to work. Too bad that when you publish your web site, the content of that directory will be ignored.&lt;br /&gt;
&lt;br /&gt;
There are other bugs here and there, but come on... how can these two have not been noticed by Microsoft? 
    </content:encoded>

    <pubDate>Wed, 03 Oct 2007 11:19:31 -0700</pubDate>
    <guid isPermaLink="false">http://tellini.info/blog/archives/37-guid.html</guid>
    <category>.net</category>
<category>ReportViewer</category>
<category>VisualStudio</category>
<category>software development</category>

</item>
<item>
    <title>(White) Space, the final frontier</title>
    <link>http://tellini.info/blog/archives/24-White-Space,-the-final-frontier.html</link>
            <category>Software Development</category>
    
    <comments>http://tellini.info/blog/archives/24-White-Space,-the-final-frontier.html#comments</comments>
    <wfw:comment>http://tellini.info/blog/wfwcomment.php?cid=24</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://tellini.info/blog/rss.php?version=2.0&amp;type=comments&amp;cid=24</wfw:commentRss>
    

    <author>nospam@example.com (Simone)</author>
    <content:encoded>
    In this second post about my preferred coding style, I&#039;ll talk about white space.&lt;br /&gt;
&lt;br /&gt;
White space is very important to improve readability, not only when dealing with code. For instance, when you write an email you usually break it up in several paragraphs, instead of writing a single chunk of code (or if you don&#039;t, &lt;a href=&quot;http://www.theprices.com/3tipmak.htm&quot; &gt;you should&lt;/a&gt;!).&lt;br /&gt;
&lt;br /&gt;
When writing a piece of software, white space should be used to isolate code blocks logically and to enhance the visibility of the most important parts of the code (e.g. arguments, operators, operands...).&lt;br /&gt;
&lt;br /&gt;
I often see people writing code like this:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: teal&quot;&gt;foo&lt;/span&gt;() {&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style=&quot;color: blue&quot;&gt;string&lt;/span&gt; bar = &quot;a&quot;;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style=&quot;color: blue&quot;&gt;string&lt;/span&gt; row = &quot;&quot;;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style=&quot;color: blue&quot;&gt;foreach&lt;/span&gt; (ObjectType item &lt;span style=&quot;color: blue&quot;&gt;in&lt;/span&gt; collection) {&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Response.Write(&quot;zot!&quot;);&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;AnotherMethodCall();&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;abc = dtMinData;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;row = i%2==0 ? &quot;even&quot; : &quot;odd&quot;;&lt;br /&gt;
// ...&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
It&#039;s not very pleasant to the eyes (and I&#039;ve seen worse than that!). Let&#039;s pimp it up!&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
&lt;span style=&quot;color: red&quot;&gt;1.&lt;/span&gt;&amp;#160;&amp;#160;void &lt;span style=&quot;color: teal&quot;&gt;foo&lt;/span&gt;()&lt;br /&gt;
&lt;span style=&quot;color: red&quot;&gt;2.&lt;/span&gt;&amp;#160;&amp;#160;{&lt;br /&gt;
&lt;span style=&quot;color: red&quot;&gt;3.&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style=&quot;color: blue&quot;&gt;string&lt;/span&gt; bar = &quot;a&quot;;&lt;br /&gt;
&lt;span style=&quot;color: red&quot;&gt;4.&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style=&quot;color: blue&quot;&gt;string&lt;/span&gt; row = &quot;&quot;;&lt;br /&gt;
&lt;span style=&quot;color: red&quot;&gt;5.&lt;/span&gt;&amp;#160;&amp;#160;&lt;br /&gt;
&lt;span style=&quot;color: red&quot;&gt;6.&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style=&quot;color: blue&quot;&gt;foreach&lt;/span&gt;( ObjectType item &lt;span style=&quot;color: blue&quot;&gt;in&lt;/span&gt; collection ) {&lt;br /&gt;
&lt;span style=&quot;color: red&quot;&gt;7.&lt;/span&gt;&amp;#160;&amp;#160;&lt;br /&gt;
&lt;span style=&quot;color: red&quot;&gt;8.&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Response.Write( &quot;zot!&quot; );&lt;br /&gt;
&lt;span style=&quot;color: red&quot;&gt;9.&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;AnotherMethodCall();&lt;br /&gt;
&lt;span style=&quot;color: red&quot;&gt;10.&lt;/span&gt;&amp;#160;&amp;#160;&lt;br /&gt;
&lt;span style=&quot;color: red&quot;&gt;11.&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;abc = dtMinData;&lt;br /&gt;
&lt;span style=&quot;color: red&quot;&gt;12.&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;row = (( i % 2 ) == 0 ) ? &quot;even&quot; : &quot;odd&quot;;&lt;br /&gt;
&lt;span style=&quot;color: red&quot;&gt;13.&lt;/span&gt;&amp;#160;&amp;#160;&lt;br /&gt;
&lt;span style=&quot;color: red&quot;&gt;14.&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;// ...&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some notes:&lt;br /&gt;
&lt;ul&gt;&lt;br /&gt;
    &lt;li&gt; line 1-2: as I&#039;ve said in my previous post, I hate the java-style &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;  Line 2 helps to separate the method name from the first line of code, so they&#039;re both easier to see. &lt;/li&gt;&lt;br /&gt;
    &lt;li&gt; line 5 is empty, to mark the end of the variable declaration block and the beginning of a statements block. &lt;/li&gt;&lt;br /&gt;
   &lt;li&gt; line 6: notice the spaces inside the parenthesis, to increase the readability of the content of the foreach(). There is no space between foreach and the opening parenthesis, for two reasons: 1. the parenthesis is part of the instruction, not of its arguments 2. syntax highlighting makes the foreach keyword already enough visible. &lt;/li&gt;&lt;br /&gt;
  &lt;li&gt; line 10 is empty, stressing the passage from a series of method invokations to a block of assignments.&lt;/li&gt;&lt;br /&gt;
 &lt;li&gt; line 12: what?! no whitespace around operators? Also, even if the language in this case doesn&#039;t require them, I prefer to use parenthesis to explicate the structure of the expression. &lt;/li&gt;&lt;br /&gt;
&lt;/ul&gt;&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Fri, 25 May 2007 15:17:32 -0700</pubDate>
    <guid isPermaLink="false">http://tellini.info/blog/archives/24-guid.html</guid>
    
</item>
<item>
    <title>Zen and the Art of Coding</title>
    <link>http://tellini.info/blog/archives/23-Zen-and-the-Art-of-Coding.html</link>
            <category>Software Development</category>
    
    <comments>http://tellini.info/blog/archives/23-Zen-and-the-Art-of-Coding.html#comments</comments>
    <wfw:comment>http://tellini.info/blog/wfwcomment.php?cid=23</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://tellini.info/blog/rss.php?version=2.0&amp;type=comments&amp;cid=23</wfw:commentRss>
    

    <author>nospam@example.com (Simone)</author>
    <content:encoded>
    Writing software is an art: some say it&#039;s a &lt;em&gt;black&lt;/em&gt; art (usually right after Word decided to crash taking their last two hours of work to hell &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;). Someone even considers it a magic art, which reminds of an Arthur Clark quote: &quot;Any sufficiently advanced technology is indistinguishable from magic&quot;.&lt;br /&gt;
&lt;br /&gt;
Like other arts, it has its canons: rules, principles that define how a piece of software should be written. In this post, I&#039;m talking about the &lt;em&gt;style&lt;/em&gt;, not the language. Every software developer seems to have his own set of rules: I usually end up arguing with everyone about them &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
I&#039;ve decided to write this post, and hopefully other ones, to explain my coding style and the rationale behind it, especially in the vain effort to get my colleagues to agree with me &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt; or at least, to comment with their point of view.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s start from the dogma:&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;&lt;br /&gt;
    &lt;strong&gt;Code should be easy to read&lt;/strong&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
I do mean &quot;read&quot;, not necessarily &quot;understand&quot;: it&#039;s hard to understand something if you find it difficult to read.&lt;br /&gt;
&lt;br /&gt;
You should be able to pick up a piece of code written by someone else and scroll through it grasping its structure at a glance, without having to read every single word or character. You might be looking for a single spot to fix in a huge file and you don&#039;t really want to stay overtime just to find it. &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
This has always been my #1 rule and it&#039;s usually the first answer I give when someone asks me &quot;why the heck do you write declarations like that, functions this way and expressions that way?&quot; &lt;img src=&quot;http://tellini.info/blog/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see now how my coding style it&#039;s just an application of the dogma.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Namespaces, classes and methods&lt;/h3&gt;&lt;br /&gt;
&lt;br /&gt;
I write all these structures using the same style:&lt;br /&gt;
&lt;ul&gt;&lt;br /&gt;
&lt;li&gt; the first line declares the block &lt;/li&gt;&lt;br /&gt;
&lt;li&gt; the opening brace is placed in its own line. The content of the block begins in the following line, without any blank line in between &lt;/li&gt;&lt;br /&gt;
&lt;li&gt; the closing brace is placed in its own line, without leaving blank lines after the last line of the block &lt;/li&gt;&lt;br /&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
class Example&lt;br /&gt;
{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;public void Method()&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;int n;&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;// ...&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;br /&gt;
}&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
I don&#039;t like the Java-style, which is preferred by someone at the office. Why? Because it forces the eye to do more work to recognize the important part of the text: the name of the namespace/class/method.&lt;br /&gt;
&lt;br /&gt;
For instance, look at the following two examples and try to identify the methods as quickly as possible, while scrolling the page up or down:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;public void which() {&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;ThisMightBeAnother declaration;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;ThisIsAnother.Kind ofObject;&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;// ...&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;public void isTheMost() {&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;DontGetDistracted lookOnly;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;atTheMethod names!&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;// ...&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;public void easyToRead() {&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;DontGetDistracted lookOnly;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;atTheMethod names!&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;// ...&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;public void between() &lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;ThisMightBeAnother declaration;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;ThisIsAnother.Kind ofObject;&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;// ...&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;public void thisAndThe() &lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;DontGetDistracted lookOnly;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;atTheMethod names!&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;// ...&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;public void previousExample()&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;DontGetDistracted lookOnly;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;atTheMethod names!&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;// ...&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;...to be continued...&lt;/div&gt; 
    </content:encoded>

    <pubDate>Sat, 19 May 2007 21:06:59 -0700</pubDate>
    <guid isPermaLink="false">http://tellini.info/blog/archives/23-guid.html</guid>
    
</item>

</channel>
</rss>