<?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>Phil Wallach &#187; Programming</title>
	<atom:link href="http://philwallach.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://philwallach.com</link>
	<description>I follow where my mind leads ...</description>
	<lastBuildDate>Wed, 17 Jun 2009 03:39:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP profiling: comparisons</title>
		<link>http://philwallach.com/2009/06/17/php-profiling-comparisons/</link>
		<comments>http://philwallach.com/2009/06/17/php-profiling-comparisons/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 03:11:39 +0000</pubDate>
		<dc:creator>phil</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[sydphp]]></category>

		<guid isPermaLink="false">http://philwallach.com/?p=97</guid>
		<description><![CDATA[An application I created used a lot of MySQL ENUMS.  They are kind of useful, in that the value of an ENUM column does not need a lookup.  The downside is that it lead to a lot of string comparisons in the code, and this became a prime suspect when performance degraded. However a colleague [...]]]></description>
			<content:encoded><![CDATA[<p>An application I created used a lot of MySQL ENUMS.  They are kind of useful, in that the value of an ENUM column does not need a lookup.  The downside is that it lead to a lot of string comparisons in the code, and this became a prime suspect when performance degraded.</p>
<p>However a colleague of mine suggested that it may be due to the cost of pass-by-value as opposed to pass-by reference.</p>
<p>So I wanted to sort it out and this simple test is the result.  After all, the first rule of profiling is &#8220;measure, measure, measure&#8221; (OK, the first three rules).  The following code compares string comparisons as pass-by-value, pass-by-reference and inline, as well as an integer (constant) comparison.</p>
<p>The profiling code:<br />
<pre><code>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function compare_value($str)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($str == &#039;MekTek&#039;)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function compare_ref(&amp;$str)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($str == &#039;MekTek&#039;)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$string = &quot;MekTek&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$integer = 0;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$now = microtime(true);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for ($i = 0; $i &lt; 10000000; $i++)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compare_value($string);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo(&quot;value: &quot; . (microtime(true) - $now) . &quot;\n&quot;);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$now = microtime(true);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for ($i = 0; $i &lt; 10000000; $i++)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compare_ref($string);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo(&quot;ref: &quot; . (microtime(true) - $now) . &quot;\n&quot;);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$now = microtime(true);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for ($i = 0; $i &lt; 10000000; $i++)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($str == &#039;MekTek&#039;)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo(&quot;str: &quot; . (microtime(true) - $now) . &quot;\n&quot;);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$now = microtime(true);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for ($i = 0; $i &lt; 10000000; $i++)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($integer == 0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo(&quot;int: &quot; . (microtime(true) - $now) . &quot;\n&quot;);
</code></pre></p>
<p>The result:<br />
<pre><code>&nbsp;&nbsp;&nbsp;&nbsp;value: 5.2698040008545
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ref: 5.4901170730591
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str: 5.3154430389404
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int: 1.0382018089294</code></pre></p>
<p>Isn&#8217;t that fascinating.  I love it when profiling returns obvious results.  The time taken to compare a string depends on the length of the string, regardless of other factors.</p>
<p>The message is clear.  Do not compare strings in performance-critical code.  Use constants instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://philwallach.com/2009/06/17/php-profiling-comparisons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embracing braces: please don&#8217;t</title>
		<link>http://philwallach.com/2006/10/25/embracing-braces-please-dont/</link>
		<comments>http://philwallach.com/2006/10/25/embracing-braces-please-dont/#comments</comments>
		<pubDate>Wed, 25 Oct 2006 13:02:45 +0000</pubDate>
		<dc:creator>phil</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.philwallach.com/?p=68</guid>
		<description><![CDATA[In  Making Wrong Code Look Wrong Joel writes: Even more subtle: if (i != 0)     foo(i); In this case the code is 100% correct; it conforms to most coding conventions and there’s nothing wrong with it, but the fact that the single-statement body of the ifstatement is not enclosed in braces may be bugging you, [...]]]></description>
			<content:encoded><![CDATA[<p>In  <a href="http://www.joelonsoftware.com/articles/Wrong.html">Making Wrong Code Look Wrong</a> Joel writes:</p>
<blockquote><p>Even more subtle:</p>
<blockquote dir="ltr" style="margin-right: 0px"><p><tt><strong>if (i != 0)<br />
    foo(i);</strong></tt></p></blockquote>
<p>In this case the code is 100% correct; it conforms to most coding conventions and there’s nothing wrong with it, but the fact that the single-statement body of the <tt>if</tt>statement is not enclosed in braces may be bugging you, because you might be thinking in the back of your head, gosh, somebody might insert another line of code there</p>
<blockquote dir="ltr" style="margin-right: 0px"><p><tt><strong>if (i != 0)<br />
<span style="background-color: yellow">    bar(i);</span><br />
    foo(i);</strong></tt></p></blockquote>
<p>… and forget to add the braces, and thus accidentally make <tt><strong>foo(i)</strong></tt>unconditional! So when you see blocks of code that aren’t in braces, you might sense just a tiny, wee, soupçon of uncleanliness which makes you uneasy.</p></blockquote>
<p>Now I have heard this argument before:  that even single statements after <em>if</em> (and <em>while</em> and <em>for</em>) statements should be in braces to prevent some klutz coming along and really breaking something.  Now I don&#8217;t buy this at all.  Why?</p>
<ol>
<li>Any programmer who would add the above statement without realising the implications should not be touching <strong>any</strong> of your code for <strong>any</strong> reason.  If they are truly that terrible then the above problem is the <strong>least of your worries</strong>.  What is going to happen when that programmer tries to code something non-trivial?  Backup your codebase and keep the media handy.  You are going to need it.  (Oh sorry, I meant branch your codebase using the SCM tool you use, right?)</li>
<li>I  think these &#8220;mandatory&#8221; braces makes the code look awful: crowded, verbose, and &#8230; well .. wrong.  Just why is that single statement in braces?  Oh that&#8217;s right &#8211; they <strong>all</strong> are.  It is bad enough that the ambiguity of if-if-else requires extra braces.  I like my code minimalist &#8211; I like to see everything.  A lot of refactoring is all about making the behavious of an <em>if</em> statement a single line [1]; don&#8217;t waste that effort.</li>
<li>Martin Fowler formats &#8220;guard clauses&#8221; with the <strong>entire </strong><em>if </em>statement on one line (&#8220;guard clauses&#8221; have no <em>else</em> leg).  I like this format, and he describes why this makes the programmer&#8217;s intention clearer.  Braces?  Blech! [2]</li>
<li>This technique is really a piece of flim-flammery to create a syntactic tarpit.  I believe there are more important drivers for how code if formatted and organised.  Screen space is valuable.</li>
</ol>
<p>I get that this is going to be &#8220;horses for courses&#8221;.  I suppose you like this idea or you don&#8217;t.  I hate it.</p>
<p>I think doing things that aren&#8217;t right to compensate for (to put it bluntly) incompetence is not the right way to go.  You can never compensate for incompetence.  It just finds new means of expression.</p>
<p>I am going to put this up there with the One True Brace Style argument, about which I have equally strong and pointless opinions.</p>
<p>[1] <strong>Refactoring</strong>, <em>Martin Fowler.</em></p>
<p>[2] <strong>Refactoring</strong>, <em>Marting Fowler</em>.  pp 250-254.</p>
]]></content:encoded>
			<wfw:commentRss>http://philwallach.com/2006/10/25/embracing-braces-please-dont/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VentureBlog: Chris Anderson Strikes Again: The Economy of Abundance</title>
		<link>http://philwallach.com/2006/10/25/ventureblog-chris-anderson-strikes-again-the-economy-of-abundance/</link>
		<comments>http://philwallach.com/2006/10/25/ventureblog-chris-anderson-strikes-again-the-economy-of-abundance/#comments</comments>
		<pubDate>Wed, 25 Oct 2006 11:34:34 +0000</pubDate>
		<dc:creator>phil</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.philwallach.com/?p=67</guid>
		<description><![CDATA[What does it mean when the cost of supply (bandwidth, storage, processing speed) is effectively zero?  Does this change how businesses work? It is easy to say yes, but I have an objection.  The caveat is that software is not free.  The problem is not even that software is expensive.  The problem is that good [...]]]></description>
			<content:encoded><![CDATA[<p>What does it mean when the cost of supply (bandwidth, storage, processing speed) is effectively zero?  Does this change how businesses work?</p>
<p>It is easy to say yes, but I have an objection.  The caveat is that software is <strong>not</strong> free.  The problem is not even that software is expensive.  The problem is that good software is <strong>rare</strong>.  Good tools, good frameworks, good environments.  <strong>Rare</strong>.</p>
<p>My personal experience with V-Sec (now defunct) says that writing, maintaining and changing any system is a non-trivial task.  I suspect a lot of the talk about &#8220;agility&#8221; is by people with multi-million dollar VC budgets funding the best-of-the-best hungry for stock options.  Things will really change when the &#8220;software&#8221; part of the equation reaches zero friction.  Then &#8230; watch out!</p>
<p><a href="http://p6.hostingprod.com/@www.ventureblog.com/articles/indiv/2006/001260.html">VentureBlog: Chris Anderson Strikes Again: The Economy of Abundance</a></p>
]]></content:encoded>
			<wfw:commentRss>http://philwallach.com/2006/10/25/ventureblog-chris-anderson-strikes-again-the-economy-of-abundance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Streamlining CSS &#8211; Part II</title>
		<link>http://philwallach.com/2006/10/09/streamlining-css-part-ii/</link>
		<comments>http://philwallach.com/2006/10/09/streamlining-css-part-ii/#comments</comments>
		<pubDate>Mon, 09 Oct 2006 05:01:16 +0000</pubDate>
		<dc:creator>phil</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.philwallach.com/?p=66</guid>
		<description><![CDATA[Eric Meyer&#8216;s comments on Streamlining CSS sparked some further thoughts (always a good thing). Eric was (unsurprisingly) talking about changing the standard (and therefore browser behaviour), which I had (also unsurprisingly) considered to be way beyond the scope of what I could consider.  My approach was therefore to focus on the build system, which was not [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://meyerweb.com/">Eric Meyer</a>&#8216;s comments on <a href="http://www.philwallach.com/?p=62">Streamlining CSS</a> sparked some further thoughts (always a good thing).</p>
<p>Eric was (unsurprisingly) talking about changing the standard (and therefore browser behaviour), which I had (also unsurprisingly) considered to be way beyond the scope of what I could consider.  My approach was therefore to focus on the build system, which was not only the part of the equation I knew best, but also avoided any standards/browser issues.</p>
<p>But what if I removed that limitation?  If I wanted to add a processing capability to CSS, what would I change and why?  Broadly I see three alternatives.</p>
<p><strong>Build stage</strong></p>
<p>Processing is performed at the build stage and the resulting CSS is loaded onto the webserver as a static page.  This is the approach I took previously.  There is no change to the standard and no change to browser or webserver behaviour.</p>
<p>If this was specified as a standard, it would not so much be a standard defining a message format (which is what CSS really is), but a new language.  This would be in addition to the existing standard.</p>
<p>It may also change the nature of developing CSS; it may no longer be useable by creative people, who may need a build systems, and then we go down the path of programmers, infrastructure, and so on.  A worse idea. (While the idea that there are folks out there creating systems without the guiding light of build systems and, even worse, SCM makes my heart flutter, I can accept that this is a boon to creative people and a necessary evil if they are to stay creative).</p>
<p>This approach would be fine for a specific project or shop that &#8220;rolled their own&#8221;, or as a product that pre-processed CSS.  Such an approach would be transparent to both the webserver and the browser.</p>
<p><strong>Server-side</strong></p>
<p>Variables are resolved at the webserver and the resulting CSS is passed to the browser.  The CSS standard is unchanged and browsers do not change, but there is a new standard for the &#8220;raw&#8221; CSS and webservers must change to process &#8220;raw&#8221; CSS and produce &#8220;standard&#8221; CSS.</p>
<p>For a start this introduces a new standard for the &#8220;raw&#8221; CSS, adding to the exisiting standard for CSS.<br />
While webservers have long handed of all sorts of processing (e.g. ColdFusion, PHP, etc), the idea of mandating some form of inbuilt processing just seems wrong to me.  It changes the model too much.</p>
<p>Again this approach would be fine for a specific project or shop that &#8220;rolled their own&#8221;, or as a webserver plugin product.  Such an approach could only run from specific servers, but would be transparent to the browser.</p>
<p><strong>Client-side</strong></p>
<p>The webserver passes the new style CSS files to the browser where processing is performed.  The CSS standard and browser behaviour both change.</p>
<p>While the idea of changing browsers the web over to a new way of doing CSS makes my head spin, this is easily the best solution.  It maintains the focus, direction, architecture and relationships of CSS.  So while *how* CSS works has changed, the *way* CSS works hasn&#8217;t.  It is also the only solution that keeps *one* CSS standard.</p>
<p>This is clearly the preferred standards-based solution. </p>
<p><strong>Summary</strong></p>
<p>In some ways I have come the long way round and ended up where I began.  The naive solution to this problem would be the same as mine, I suspect &#8211; change the existing standard and add the features you want.  But it is always wise to consider the alternatives.</p>
]]></content:encoded>
			<wfw:commentRss>http://philwallach.com/2006/10/09/streamlining-css-part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Streamlining CSS</title>
		<link>http://philwallach.com/2006/10/06/streamlining-css/</link>
		<comments>http://philwallach.com/2006/10/06/streamlining-css/#comments</comments>
		<pubDate>Thu, 05 Oct 2006 15:13:51 +0000</pubDate>
		<dc:creator>phil</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.philwallach.com/?p=62</guid>
		<description><![CDATA[Why is CSS so hard?  It is verbose, repetitive and cumbersome.  At the heart of the matter, CSS has not been designed as a language.  As such, CSS has no ways to express things elegantly.  It is all hard coded from beginning to end. I had been thinking about this for a while, and was [...]]]></description>
			<content:encoded><![CDATA[<p>Why is CSS so hard?  It is verbose, repetitive and cumbersome.  At the heart of the matter, CSS has not been designed as a language.  As such, CSS has no ways to express things elegantly.  It is all hard coded from beginning to end.</p>
<p>I had been thinking about this for a while, and was considering coming up with some sort of CSS generation language.  Then, as these things happen, I read <a title="Permanent Link: CSS Repeats Itself" href="http://cafe.elharo.com/web/css-repeats-itself/" rel="bookmark"><font color="#000000">CSS Repeats Itself</font></a> and everything became clear.</p>
<p><strong>The problem</strong></p>
<p>The problems with CSS I would classify as:</p>
<ul>
<li><strong>No variables</strong>.  There is no way to set and re-use variables in CSS.  This means that to make a width or height or margin (or anything) consistent, you just have to set the same value everywhere.  To make it worse, if you want to change the value, you have to change it everywhere.  If values collide, your global replace is going to break something.  If values are in different stylesheets &#8230; well &#8230; good luck!</li>
<li><strong>No expressions</strong>.  There is no way to say &#8220;this equals twice this plus that&#8221; in CSS.  You have to figure it out by hand and hard code the value. If one of your values change, you better remember what to re-calculate (after changing all the instances by hand, that is).</li>
<li><strong>No includes</strong>. There is no way to include a CSS file within another CSS file.  This must be done by importing multiple stylesheets in the final (X)HTML document. This hides dependencies between CSS files and prevents reuse.</li>
<li><strong>No inheritance</strong>.  There is a sort of broken implicit inheritance in CSS, but it is totally opaque (to me, anyway).  I would rather express inheritance explicitly, rather than by the imposition of obscure ordering and specificity rules.</li>
</ul>
<p>You can sort of see why this happened.  Without variables, expressions make less sense, as do include files.  I think (true) inheritance was considered out-of-scope :p</p>
<p><strong>Towards a solution</strong></p>
<p>In <strong>CSS Repeats Itself</strong> the challenge was to solve this with XSLT.  Well, I don&#8217;t know XSLT, so that is not an option.  Also the implication was that this would be an on-the-fly thing, though I am not sure if that was specific to a specific server or a suggestion for a &#8220;grand new Internet architecture&#8221;.</p>
<p>I was more interested in a solution for a developer like myself, so my solution was always going to be in the world of build systems (where I believe all such things belong).  Looking at the example it struck me that most of what we want to do we already have the tools for (surprise, surprise).  So I took about ten minutes of my time, and reworked a project using:</p>
<ul>
<li>cpp</li>
<li>make</li>
</ul>
<p>Not quite the sexiest set of tools now-a-days.  But they get the job done, and they work in my environment!  (Always a plus).  I would hate to think of a development environment that didn&#8217;t have this sort of capability, but I am sure they exist *sigh*.</p>
<p><strong>My solution</strong></p>
<p>This is a quick example I cooked up, based on the example in <strong>CSS Repeats Itself</strong>.  It is more to show what could be done, than what you should do.</p>
<p><em>Makefile</em></p>
<blockquote><p> file.css : file.pcss<br />
         cpp -x c -P -C $? -o $@</p></blockquote>
<p>I have created the &#8220;pcss&#8221; file extension, meaning &#8220;pre-processable CSS&#8221;.  So <em>file.pcss </em>is our source file, from which we build our CSS file, <em>file.css</em>, as part of our system build.  For a well setup project, this should not introduce any wrinkles.  The only issue I can see, which is hopefully minor, is that projects without *any* build phase (e.g. PHP projects) may not have a nice place to slot this in.</p>
<p>The command breaks down as follows:</p>
<ul>
<li>cpp is the C pre-processor.  It is designed to work on &#8220;C&#8221;, but we can bend it to our will.</li>
<li>-x c treats all files as &#8220;C&#8221; files, which is just as well because it has no idea what a .pcss file is.</li>
<li>-P turns off &#8216;#line&#8217; commands which would ruin our file.</li>
<li>-C keeps any comments that might be in our code, though we might want to turn this off.</li>
</ul>
<p><em>file.pcss</em></p>
<blockquote><p>#define LC 200px<br />
#define RC 150px<br />
#define WIDTH 550px</p>
<p>#include &#8220;3col.pcss&#8221;</p></blockquote>
<p><em>3col.pcss</em></p>
<blockquote><p>body {<br />
    min-width: WIDTH;<br />
}<br />
#container {<br />
    padding-left: LC;<br />
    padding-right: RC;<br />
}<br />
#container .column {<br />
    position: relative;<br />
    float: left;<br />
}<br />
#center {<br />
    width: 100%;<br />
}<br />
#left {<br />
    width: LC;<br />
    right: LC;<br />
    margin-left: -100%;<br />
}<br />
#right {<br />
    width: RC;<br />
    margin-right: -RC;<br />
}<br />
#footer {<br />
    clear: both;<br />
}</p></blockquote>
<p>The make command creates <em>file.css</em>:</p>
<blockquote><p>body {<br />
    min-width: 550px ;<br />
}<br />
#container {<br />
    padding-left: 200px ;<br />
    padding-right: 150px ;<br />
}<br />
#container .column {<br />
    position: relative;<br />
    float: left;<br />
}<br />
#center {<br />
    width: 100%;<br />
}<br />
#left {<br />
    width: 200px ;<br />
    right: 200px ;<br />
    margin-left: -100%;<br />
}<br />
#right {<br />
    width: 150px ;<br />
    margin-right: &#8211; 150px ;<br />
}<br />
#footer {<br />
    clear: both;<br />
}</p></blockquote>
<p>I have made the three column layout an include file, as it may be re-used for many projects.  The parameterisation of the layout means not only does it remain consistent when it is changed, but every project can use different values while using the &#8220;same code&#8221;.  An obvious advantage to any programmer, but a bit lost in the CSS world.</p>
<p><strong>Summary</strong></p>
<p>The solution above is simple and should be easily achieved in most development environments (so I assert without proof).  This solution:</p>
<ul>
<li>Solves the <strong>variables</strong> problem by using macros to define constants.</li>
<li>Solves the <strong>include file</strong> problem through the preprocessors &#8220;include&#8221; function.</li>
<li>Partially solves the <strong>expression</strong> problem.  We still cannot use expressions, but we can use macros to put the each hard coded value in one sensible location (i.e. with their related variables).</li>
<li>Does not solve the <strong>inheritance </strong>problem.  We can make some things better, but the solution may be as complex as the problem, and we still have to contend with CSS&#8217;s internal model.</li>
</ul>
<p><strong>Caveats</strong></p>
<p>When I generated this example, I noticed (belatedly) that these is a problem with it.  In <em>file.css</em> one of the expansions evaluates to &#8220;<strong>- 150px ;</strong>&#8220;.  This is because the C preprocessor inserts space around macro expansions (for reasons which are too mind bending to go into here).  This is a problem because I am not sure (i.e. I don&#8217;t know) if this is going to be alright or not.  &#8220;C&#8221; is pretty robust about such things; I doubt whether CSS is so robust.  This means that even using this solution, you have to be careful to avoid such constructs.  You will need to do something (admittedly sub-optimal) like:</p>
<blockquote><p>#define RC 150px<br />
#define NEGRC -150px</p></blockquote>
<p>I have not tested this extensively, and suspect there may be other cases that make CPP barf!  Also in my research after writing the bulk of this article (see below) I found much concern about id tags (e.g. #blah) being mistaken for cpp directives.  This is possible, if the id formed a reconizable directive.  AFAIK unrecognised directives are passed through unchanged, which is what we want.</p>
<p><strong>Postscript </strong></p>
<p>While following up the inserted whitespace problem, I came across <a href="http://www.cs.tut.fi/~jkorpela/html/cpre.html">Using a C preprocessor as an HTML authoring tool</a>, which is the same thing for HTML (all the way down to the same CPP arguments).</p>
<p>Then I thought; well, this is all pretty obvious, someone else might have done something similar &#8230; and they have.</p>
<p><a href="http://www.developerdotstar.com/community/node/505">Precompiling CSS with Extensions &#8211; A Crazy Idea?</a></p>
<p><a href="http://blog.roberthahn.ca/articles/2006/06/24/css-preprocessor">CSS Preprocessor</a></p>
<p><a href="http://blog.roberthahn.ca/articles/2006/06/24/css-preprocessor-%E2%80%93-take-2">CSS Preprocessor – Take 2</a></p>
<p><a href="http://meyerweb.com/eric/thoughts/2005/08/31/the-constants-gardener/">The Constants Gardener</a></p>
<p><a href="http://www.shauninman.com/plete/2005/08/css-variables">CSS-SSV</a></p>
]]></content:encoded>
			<wfw:commentRss>http://philwallach.com/2006/10/06/streamlining-css/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Compression == AI ?</title>
		<link>http://philwallach.com/2006/09/30/compression-ai-i-dumb-idea/</link>
		<comments>http://philwallach.com/2006/09/30/compression-ai-i-dumb-idea/#comments</comments>
		<pubDate>Fri, 29 Sep 2006 16:16:09 +0000</pubDate>
		<dc:creator>phil</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.philwallach.com/?p=55</guid>
		<description><![CDATA[The idea of an AI prize was quite intriguing and I came to this site hoping to find something interesting.  However this is one of those cases where either these guys are crazy or I am missing something. This is the competition: The contest is about compressing the human world knowledge as well as possible. [...]]]></description>
			<content:encoded><![CDATA[<p>The idea of an AI prize was quite intriguing and I came to this site hoping to find something interesting.  However this is one of those cases where either these guys are crazy or I am missing something.</p>
<p>This is the competition:</p>
<blockquote><p>The contest is about compressing the human world knowledge as well as possible.</p>
<p>If your compressor compresses the 100MB file <tt>enwik8</tt> x% better than the current record, you&#8217;ll receive x% of the prize.</p></blockquote>
<p>This strikes me as a <strong>good thing</strong>.  But where they lose me is when they start to talk about AI. </p>
<blockquote><p>If you can compress the first 100MB of Wikipedia better than your predecessors, you(r compressor) likely has to be smart(er).</p></blockquote>
<blockquote><p><font color="#000000">&#8230; being able to compress well is closely related to acting intelligently &#8230;</font></p></blockquote>
<p>Say again?  Let&#8217;s think about this, for a moment (that&#8217;s all it takes):</p>
<ul>
<li>I do <strong>not</strong> get how compression relates to intelligence.  They go on about matching patterns, and prediction, but I do think the &#8220;pattern detection&#8221; in LZW (for example) is really pattern detection in the AI sense at all.  Nothing is done with these patterns but transcription and mappings. </li>
<li>They have also confused <strong>where the intelligence is</strong>.  A compression algorithm is the <strong>result</strong> of intelligence, it is not an (artificial) intelligence operating in its own domain.  The intelligence they are measuring (if any) is that of the creator, not of the compressor.</li>
<li>Their metrics are plain wrong.  The prize is awarded for the compression of a known piece of text.  This seems to me to be a flawed approach.  Even if people were to attack the problem with integrity, the winning solution would almost certainly be &#8220;fitted&#8221; to the data.</li>
</ul>
<p><a href="http://prize.hutter1.net/hfaq.htm#compai">Human Knowledge Compression Contest: Frequently Asked Questions &#038; Answers</a></p>
]]></content:encoded>
			<wfw:commentRss>http://philwallach.com/2006/09/30/compression-ai-i-dumb-idea/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embedded.com &#8211; Avoiding the most common software development goofs</title>
		<link>http://philwallach.com/2006/09/19/embeddedcom-avoiding-the-most-common-software-development-goofs/</link>
		<comments>http://philwallach.com/2006/09/19/embeddedcom-avoiding-the-most-common-software-development-goofs/#comments</comments>
		<pubDate>Mon, 18 Sep 2006 23:37:36 +0000</pubDate>
		<dc:creator>phil</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.philwallach.com/?p=35</guid>
		<description><![CDATA[Why do developers make mistakes? 1. Ignorance 2. Stress 3. Boredom 4. Human frailties Categories of error &#8220;We can either categorize based on root cause in the code (e.g., null pointer dereference, failure to unlock after acquiring a lock, buffer overrun, etc.) or based on a higher level reason for the mistake (e.g., improper error [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Why do developers make mistakes?</strong></p>
<p>1. Ignorance</p>
<p>2. Stress</p>
<p>3. Boredom</p>
<p>4. Human frailties</p>
<p><strong>Categories of error</strong></p>
<blockquote><p><em>&#8220;We can either categorize based on root cause in the code (e.g., null pointer dereference, failure to unlock after acquiring a lock, buffer overrun, etc.) or based on a higher level reason for the mistake (e.g., improper error handling, typo, copy and paste, etc.) &#8230; we choose the latter &#8230;&#8221;</em></p></blockquote>
<p>1. Ignorance</p>
<p>2. Copy and paste</p>
<p>3. Error handling</p>
<p>4. Off by ones</p>
<p>5. Typos</p>
<p>The article then goes on to make a case for static code analysis tools.</p>
<p><a href="http://www.embedded.com/showArticle.jhtml?articleID=192800005">Embedded.com &#8211; Avoiding the most common software development goofs</a></p>
]]></content:encoded>
			<wfw:commentRss>http://philwallach.com/2006/09/19/embeddedcom-avoiding-the-most-common-software-development-goofs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
