<?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>Artful Code &#187; php</title>
	<atom:link href="http://www.artfulcode.net/tags/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.artfulcode.net</link>
	<description>Resources and tips for dynamic, interactive languages.</description>
	<lastBuildDate>Fri, 09 Sep 2011 02:15:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP is a framework</title>
		<link>http://www.artfulcode.net/articles/php-is-a-framework/</link>
		<comments>http://www.artfulcode.net/articles/php-is-a-framework/#comments</comments>
		<pubDate>Fri, 15 May 2009 18:12:26 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Soap box]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://www.artfulcode.net/?p=624</guid>
		<description><![CDATA[Rails, Django, Spring &#8211; application frameworks like these are now ubiquitous in the development of web-based applications. This is part of a trend in many general purpose languages of building toward the web. For these, the application framework is not just a buzzword; it is the abstraction used to build the language up to the [...]]]></description>
			<content:encoded><![CDATA[<p>Rails, Django, Spring &#8211; application frameworks like these are now ubiquitous in the development of web-based applications. This is part of a trend in many general purpose languages of building toward the web. For these, the application framework is not just a buzzword; it is the abstraction used to build the language up to the browser.<span id="more-624"></span></p>
<p>PHP was designed with the reverse in mind. In its first release, it could have been considered to be a DSL for web-based applications. It was written to specifically address the needs to writing web applications, and is now building toward a more general purpose language. In all likelihood, this is the wrong way around. It certainly does not fall into the bottom-up design Shangri-La of which Paul Graham is such a proponent.</p>
<p>In reality, though, web-based applications are driving the industry. PHP is still very relevant in that domain. From very early on, PHP was centered on functionality that is considered basic to any web-based framework. Functionality without which each library is simply a thin wrapper over CGI. Features like easy access to GET and POST variables, session handling, header control, and database access have been built into PHP from, if not the beginning, then close enough that dinosaurs like myself don&#8217;t remember it ever being otherwise.</p>
<p>PHP has its own share of frameworks, too, which allow the programmer to painstakingly map SQL schema to XML or vice versa. They carefully abstract the logic out of the view and force the programmer to jump through hoops to write a simple application (although, for complex applications, this often makes the programmer&#8217;s life *much* easier.)</p>
<p>PHP does not need any of this. In fact, the most pragmatic framework I have used to date for PHP is the <a href="http://clickontyler.com/simple-php-framework/">Simple PHP Framework</a>, which is just a set of useful classes to automate some of the more tedious areas of web development. What it does not do is get in the programmer&#8217;s way. It is <a href="http://en.wikipedia.org/wiki/Occam's_razor">Occam&#8217;s razor</a> at work in the world of web development. From the SPF website, quoting a non-existent link:</p>
<blockquote><p>&#8220;All the web frameworks in the world won’t turn a shitty programmer into a good one.&#8221;</p></blockquote>
<p>What PHP is not is elegant. It does not have beauty of prose, nor those features that make languages like ML and Lisp so exciting, such as closures, functions-as-objects, or lazy evaluation. Instead, PHP is, above all, a practical language. Instead, it has less sexy features, such as built-in support for XML, XSLT, and Xpath, support most databases, and the built-in ability to serialize to and from JSON and cookie strings.</p>
<p>It is easy to overlook how simple PHP makes many tasks that are complex in other frameworks. For example, Django&#8217;s form library is large and complex. I&#8217;ve no doubt that most other frameworks have equally Byzantine systems for developing reusable forms. In PHP, one might just write:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">function input($type, $name, $display, $value)
{
    &lt; ?
        &lt;label&gt;&lt; ?= $display ?&gt;
        &lt;input type=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$type</span> ?<span style="color: #339933;">/&gt;</span><span style="color: #0000ff;">&quot; value=&quot;</span><span style="color: #339933;">&lt;</span> ?<span style="color: #339933;">=</span> <span style="color: #000088;">$value</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
    ?&gt;
}</pre></div></div>

<p>The function could be refined to separate the template and the code by putting the HTML into a separate include:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> input<span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dispaly</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">include</span> <span style="color: #0000ff;">'templates/input.inc.php'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Simple, right? Which is not to say that PHP&#8217;s faults are not legion. That said, I think that PHP sometimes does a better job of building toward general purpose programming than many other languages do of building toward web development.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Submit article</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fphp-is-a-framework%2F&amp;title=PHP+is+a+framework" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fphp-is-a-framework%2F&amp;title=PHP+is+a+framework" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=PHP+is+a+framework&amp;url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fphp-is-a-framework%2F&amp;title=PHP+is+a+framework" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fphp-is-a-framework%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fphp-is-a-framework%2F&amp;title=PHP+is+a+framework" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fphp-is-a-framework%2F&amp;title=PHP+is+a+framework" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fphp-is-a-framework%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+PHP+is+a+framework+@+http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fphp-is-a-framework%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.artfulcode.net/articles/php-is-a-framework/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Utilizing PHP&#8217;s strengths</title>
		<link>http://www.artfulcode.net/articles/utilizing-phps-strengths/</link>
		<comments>http://www.artfulcode.net/articles/utilizing-phps-strengths/#comments</comments>
		<pubDate>Mon, 21 May 2007 23:29:00 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Soap box]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.artfulcode.net/articles/utilizing-phps-strengths/</guid>
		<description><![CDATA[PHP is a procedural language. This is not a criticism. PHP revolutionized CGI by being half-scripting language, half templating system. It is, in fact, about the most powerful templating system around. The fact that object oriented syntax was even able to be bolted on is a testament to that. However, PHP does not shine in [...]]]></description>
			<content:encoded><![CDATA[<p>PHP is a procedural language.  This is not a criticism.  PHP revolutionized CGI by being half-scripting language, half templating system.  It is, in fact, about the most powerful templating system around.  The fact that object oriented syntax was even able to be bolted on is a testament to that.<span id="more-63"></span></p>
<p>However, PHP does not shine in object oriented programming.  Frameworks like Cake suffer because of this.  On the other hand, there are also excellent frameworks, like <a href="http://www.codeigniter.com">Code Igniter</a>, which embrace this (by using PHP objects as scoping mechanisms for function libraries).</p>
<p>There is a tendency as a programmer to dismiss any language that is not object oriented.  This is a particular trait of Pythonistas (like me), Rubyists, and those who use Java (which I put into the same category as those who use Cobol).  This is unfortunate because procedural code can be much more efficient for many applications.</p>
<p>The beauty of PHP is that it allows the creation of a simple application without the overhead of large libraries, long planning meetings, and a fight with the DBA over MyIsam versus InnoDB.</p>
<p>OO advocates will point out that this is also the problem with PHP.  If you wish to expand the program in the future, it takes a lot more work than if the program had been written using OO syntax from the ground up.</p>
<p>This is true, and PHP can be written using object oriented syntax as well.  However, classes in PHP are pretty second-rate, and do not do much to help solve the problems of over-complication in large PHP applications.  Joomla is a perfect example of this; if you look at its internals (or, god forbid, its documentation &#8211; yech!) it is readily apparent how unfit PHP is for extremely complex operations using classes.</p>
<p>PHP does shine in one area, though: arrays.  In PHP, the array is a phenominal construction.  It can be used to create tables, dictionaries (associative arrays or hashes to the non-religious), lists &#8211; just about anything.  There is a fairly comprehensive set of functions for dealing with arrays as well (at least, comprehensive when not comparing it to Lisp), and a superb iterator for them as well (foreach).</p>
<p>PHP does not need classes except as a mechanism to group functions grouped together.  Its powerful arrays bely its heritage as a procedural language, and more than make up for its substandard classes.  PHP arrays are much more helpful than classes if you consider PHP in the context of a templating system, rather than an OO language.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Submit article</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Futilizing-phps-strengths%2F&amp;title=Utilizing+PHP%26%238217%3Bs+strengths" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Futilizing-phps-strengths%2F&amp;title=Utilizing+PHP%26%238217%3Bs+strengths" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Utilizing+PHP%26%238217%3Bs+strengths&amp;url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Futilizing-phps-strengths%2F&amp;title=Utilizing+PHP%26%238217%3Bs+strengths" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Futilizing-phps-strengths%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Futilizing-phps-strengths%2F&amp;title=Utilizing+PHP%26%238217%3Bs+strengths" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Futilizing-phps-strengths%2F&amp;title=Utilizing+PHP%26%238217%3Bs+strengths" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Futilizing-phps-strengths%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Utilizing+PHP%26%238217%3Bs+strengths+@+http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Futilizing-phps-strengths%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.artfulcode.net/articles/utilizing-phps-strengths/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Contextual programming</title>
		<link>http://www.artfulcode.net/articles/contextual-programming/</link>
		<comments>http://www.artfulcode.net/articles/contextual-programming/#comments</comments>
		<pubDate>Tue, 15 May 2007 21:25:00 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[newlisp]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.artfulcode.net/articles/contextual-programming/</guid>
		<description><![CDATA[PHP is a procedural language. This is not a criticism. PHP revolutionized CGI by being half-scripting language, half templating system. It is, in fact, about the most powerful templating system around. The fact that object oriented syntax was even able to be bolted on is a testament to that. However, PHP does not shine in [...]]]></description>
			<content:encoded><![CDATA[<p>PHP is a procedural language.  This is not a criticism.  PHP revolutionized CGI by being half-scripting language, half templating system.  It is, in fact, about the most powerful templating system around.  The fact that object oriented syntax was even able to be bolted on is a testament to that.<span id="more-64"></span></p>
<p>However, PHP does not shine in object oriented programming.  Frameworks like Cake suffer because of this.  On the other hand, there are also excellent frameworks, like <a href="http://www.codeigniter.com">Code Igniter</a>, which embrace this (by using PHP objects as scoping mechanisms for function libraries).</p>
<p>There is a tendency as a programmer to dismiss any language that is not object oriented.  This is a particular trait of Pythonistas (like me), Rubyists, and those who use Java (which I put into the same category as those who use Cobol).  This is unfortunate because procedural code can be much more efficient for many applications.</p>
<p>The beauty of PHP is that it allows the creation of a simple application without the overhead of large libraries, long planning meetings, and a fight with the DBA over MyIsam versus InnoDB.</p>
<p>OO advocates will point out that this is also the problem with PHP.  If you wish to expand the program in the future, it takes a lot more work than if the program had been written using OO syntax from the ground up.</p>
<p>This is true, and PHP can be written using object oriented syntax as well.  However, classes in PHP are pretty second-rate, and do not do much to help solve the problems of over-complication in large PHP applications.  Joomla is a perfect example of this; if you look at its internals (or, god forbid, its documentation &#8211; yech!) it is readily apparent how unfit PHP is for extremely complex operations using classes.</p>
<p>When working on a large project, it is usually advisable to break your code up into smaller portions.  In many languages, these are called shared libraries: smaller chunks of code that can be reused as needed throughout this and other programs.</p>
<p>In many languages, such as PHP, evaluating the contents of another file necessarily means that its code is run in the current namespace.  This means that if you were to run the following code in PHP:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$foo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;bar&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;some_file.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Contents of some_file.php:
</span><span style="color: #000088;">$foo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;baz&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Can you guess what $foo now evaluates to?  $foo has been overwritten.  To get around this, we can abuse a class to create a singleton-like object:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$foo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;bar&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">class</span> Something <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$foo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;baz&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$context</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Something<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We now have two contexts, main, where $foo = &#8220;bar,&#8221; and $context, where $context-&gt;foo = &#8220;baz.&#8221;</p>
<p>In Python, we avoid this altogether:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">foo = <span style="color: #483d8b;">&quot;bar&quot;</span>
<span style="color: #ff7700;font-weight:bold;">import</span> some_module
&nbsp;
<span style="color: #808080; font-style: italic;"># Contents of some_module.py</span>
foo = <span style="color: #483d8b;">&quot;baz&quot;</span></pre></div></div>

<p>In the Python example, foo is still &#8220;bar.&#8221;  However, we now have a new symbol, some_module.foo, which evaluates to &#8220;baz.&#8221;</p>
<p>newLisp has a similar concept, but slightly lower level, and somewhat more limited (in that all namespaces are children of the MAIN namespace, and cannot be nested, as in Python).  It also gives you greater control.</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'foo <span style="color: #ff0000;">&quot;bar&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>context 'SOME-CONTEXT<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set</span> 'foo <span style="color: #ff0000;">&quot;baz&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>context 'MAIN<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>In newLisp, &#8216;foo still evaluates to &#8220;bar&#8221;, and &#8216;SOME-CONTEXT:foo evaluates to &#8220;baz.&#8221;  Really, of the three, only PHP comes out the poorer here.</p>
<p>If I were comparing the languages, I would say that Python really wins out with contexts.  Having nested modules eliminates the need to misuse classes and likewise prevents symbols overwriting each other.</p>
<p>newLisp&#8217;s implementation is extremely useful as well, but somewhat hindered by its lack of nesting.</p>
<p>PHP is the one that really takes a hit here.  It&#8217;s complete lack of programmer-controlled namespaces forces misuse of other parts of the language and encourages bad coding &#8211; for which I am just as guilty as anyone.</p>
<p>PHP does shine in one area, though: arrays.  In PHP, the array is a phenominal construction.  It can be used to create tables, dictionaries (associative arrays or hashes to the non-religious), lists &#8211; just about anything.  There is a fairly comprehensive set of functions for dealing with arrays as well (at least, comprehensive when not comparing it to Lisp), and a superb iterator for them as well (foreach).</p>
<p>PHP does not need classes except as a mechanism to group functions grouped together.  Its powerful arrays bely its heritage as a procedural language, and more than make up for its substandard classes.  PHP arrays are much more helpful than classes if you consider PHP in the context of a templating system, rather than an OO language.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Submit article</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fcontextual-programming%2F&amp;title=Contextual+programming" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fcontextual-programming%2F&amp;title=Contextual+programming" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Contextual+programming&amp;url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fcontextual-programming%2F&amp;title=Contextual+programming" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fcontextual-programming%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fcontextual-programming%2F&amp;title=Contextual+programming" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fcontextual-programming%2F&amp;title=Contextual+programming" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fcontextual-programming%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Contextual+programming+@+http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fcontextual-programming%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.artfulcode.net/articles/contextual-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

