<?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>Dereleased &#187; The Internet</title>
	<atom:link href="http://www.dereleased.com/category/the-internet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dereleased.com</link>
	<description>Information Saturation</description>
	<lastBuildDate>Sat, 10 Sep 2011 20:41:33 +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>Let&#8217;s talk about your password model</title>
		<link>http://www.dereleased.com/2010/02/09/lets-talk-about-your-password-model/</link>
		<comments>http://www.dereleased.com/2010/02/09/lets-talk-about-your-password-model/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 17:02:50 +0000</pubDate>
		<dc:creator>Clark</dc:creator>
				<category><![CDATA[Information Security]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[The Internet]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[blowfish]]></category>
		<category><![CDATA[crypt]]></category>
		<category><![CDATA[md5]]></category>
		<category><![CDATA[nonce]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[salt]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sha1]]></category>
		<category><![CDATA[sha256]]></category>

		<guid isPermaLink="false">http://www.dereleased.com/?p=151</guid>
		<description><![CDATA[First off, let me just say that I am by no means an expert cryptographer; there are all sorts of wonderful, terrible things about hashes and block ciphers that I just don&#8217;t understand (I&#8217;d like to believe that it&#8217;s because I&#8217;ve not been exposed to them, whoever&#8217;s fault that is, and that if given a [...]]]></description>
			<content:encoded><![CDATA[<p>First off, let me just say that I am by no means an expert cryptographer; there are all sorts of wonderful, terrible things about hashes and block ciphers that I just don&#8217;t understand (I&#8217;d like to believe that it&#8217;s because I&#8217;ve not been exposed to them, whoever&#8217;s fault that is, and that if given a chance I would get it), but that&#8217;s also why I&#8217;m writing this &#8211; to give the opinion of someone who recognizes his own weakness, and how that translates to another&#8217;s strength.  Furthermore, this explanation gives a very simplistic view of web security that only examines one aspect of a secure system.  For loads more information about securing your web application, take a look at <a href="http://cookies.lcs.mit.edu/pubs/webauth:tr.pdf">&#8220;Dos and Don&#8217;ts of Client Authentication on the Web&#8221; <small>[PDF]</small></a> written by some very smart folks at M.I.T.</p>
<p>So, let&#8217;s start with a beginner&#8217;s introduction.  In the beginning, there were users, and users wanted to be able to log in because otherwise being a user was rather pointless indeed.  Thus, the password is born, and forevermore it becomes the goal of clever crackers and security experts alike.  The first problem someone encounters with passwords is how to store them, and that depends very much on a few key factors: Audience, Exposure, and Uniqueness.  If you are running a &#8220;homegrown&#8221; application (shout out to MecTracker) for use only inside the company, containing (in general) zero sensitive data, and you intend to pick user&#8217;s passwords for them (preventing the loss of a life password, itself a bad-yet-unavoidable practice), then why not just store them in plain text?  Certainly makes it easy to retrieve a password for someone without having to reset it (useful for someone away from their work machine with saved password who needs to log in).</p>
<p>Conversely, if you&#8217;re a bank, and you&#8217;re storing any of this in plain text, you will be razed to the ground by angry tech-savvy customers and auditors alike, hopefully BEFORE you get grandma and grandpa Jones to type in the password they use for everything else, too.  Hopefully, if you&#8217;re a bank, you&#8217;re using some crazy method I&#8217;m not about to describe here.</p>
<p>Then, there&#8217;s the middle ground.  I, for example, am not a bank (who would&#8217;ve guessed?  Can someone please notify my ex-girlfriend?), so my needs are much more middle-of-the-road, which is why I&#8217;ve settled for hashing.  When I started using PHP, I generally stuck to simple MD5 hashes; it was 10 years ago, and breaking MD5 seemed reasonably difficult.  Then I was told not to use MD5 because, at 128 bits, it was too weak, and I should be using SHA-1, which was 160 bits.  Then came the recommendation for SHA-256 (guess how many bits that one is!), and then whirlpool, and so on.  If you&#8217;re using a proper password strategy then you&#8217;ve been salting all along (I&#8217;ll admit I wasn&#8217;t in the old days, but you&#8217;ve got to be a beginner sometime), but if you haven&#8217;t, allow me to give you a word on salt.</p>
<p>&#8220;Salting&#8221; a password hash is the practice of taking a piece of input data, adding in an extra piece of information (called &#8220;salt&#8221;; see where this is going?), and hashing that, instead of just hashing the raw input.  In fact, with sites <a href="http://md5.rednoize.com/">that act like a search engine for MD5 and SHA-1 hashes</a>, not salting your input is, for general purpose storage, only one-degree of separation away from just storing the data in plain text.  Furthermore, good salt will be ever-changing (in this practice, the salt is also known as a &#8216;nonce&#8217;), and can safely be stored without obfuscation, as having included it means that a table not accounting for the nonce is useless, and a table that accounts for the nonce is only good against one of the passwords in your database.  Now you&#8217;ve just made an attack much more expensive, but that may not be as useful in reality as we&#8217;d like to believe.</p>
<p>MD5 and SHA-1 hashes can be calculated very, very quickly.  In fact, it&#8217;s generally more expensive to include some data about the current time (for use in salting/as a nonce) than it is to calculate the actual hash.  Here is some experimental code to prove my point:</p>
<div class="wp_syntax">
<div class="code">
<pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">(</span><span style="color: #0000ff;">'ITERATIONS'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$tt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$th</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">(</span><span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$j</span> <span style="color: #339933;">&lt;</span> ITERATIONS<span style="color: #339933;">;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$j</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
	<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">(</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">(</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">(</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">)</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$start</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$i</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
		<span style="color: #000088;">$k</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">(</span><span style="color: #000088;">$i</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">}</span>
	<span style="color: #000088;">$tt</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">(</span><span style="color: #990000;">microtime</span><span style="color: #009900;">(</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">)</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$start</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$th</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span>
&nbsp;
<span style="color: #990000;">var_dump</span><span style="color: #009900;">(</span><span style="color: #000088;">$tt</span> <span style="color: #339933;">/</span> ITERATIONS<span style="color: #339933;">,</span> <span style="color: #000088;">$th</span> <span style="color: #339933;">/</span> ITERATIONS<span style="color: #009900;">)</span><span style="color: #339933;">;</span></pre>
</div>
</div>
<p>Simply hashing the value of the counter averaged 320,000 hashes per second on my work machine, which is not very powerful, and is certainly not running this in a very optimized way.  By changing what is being hashed to the current time to the microsecond, the number of hashes per second is reduced to an average of about 150,000 &#8211; in short, the hash is NOT the expensive part of what&#8217;s going on here.  So, let&#8217;s say that, given a more optimized environment but a more expensive dictionary list to be hashed, that the average is 200,000 hashes per second, and the dictionary is about 50,000,000 common passwords.  Simple math tells you that generating a hash list for this will take about 250 seconds, or less than 5 minutes.  If it takes under 5 minutes to generate a table, and only a few seconds from there to query it, then even a database of 150,000 users can be fully cracked in just under a fortnight.</p>
<p>So how can this be combated?  Well, strong password guidelines are a good start, but if you&#8217;re relying on users to implement password security for you, you&#8217;re probably doing it very, very wrong.  I&#8217;d like to challenge one of the assumptions you&#8217;ve probably made that I&#8217;ve had to challenge recently, and that is the value of speed; speed is <em>bad</em>.  Think about it: using a hash method that can generate a table of fifty million values in under 5 minutes sounds great from a performance perspective, but who are you really helping?  Is your user going to notice that your hash method took under 1ms to calculate, or is this performance more likely to benefit someone trying to crack your passwords?  Who would be more hurt if your passwords took closer to 12ms to generate and verify, your users or your would-be attacker?</p>
<p>If you haven&#8217;t heard of it yet, may I introduce you to <a href="http://www.bletchleypark.net/cryptology/blowfish.html">Blowfish Encryption</a>.  Blowfish is designed to scale with Moore&#8217;s Law by allowing you, the programmer, to decide how long it takes to generate a hash.  This is done by allowing you to specify a number which will be interpreted as a log-base-2 of how many iterations the hashing sequence should take; this metadata is then stored as part of the salt, prepended to the hash, and can be verified by the same function that created it since hashes are of fixed length and will be truncated or padded accordingly.  By using a log-base-2 scale, every increment of that number (n) literally doubles the time required to calculate the hash, as it will have to undertake 2<sup>n</sup> iterations to generate the password.  From what I can gather, a number like 7 or 8 is a fair industry standard at this time, and on my work machine limits the hashes-per-second to around 86.6 and 43.3, respectively.</p>
<p>Now, performance is a factor in real world applications, so let&#8217;s pick a number like 2<sup>7</sup>, which as I said allows about 87 hashes per second.  At that rate, a single dictionary table (useful for only one user, since we are salting these passwords) takes about six and a half days to generate.  For that same database of 150,000 users, it would take over 2,733 <b>years</b> to crack.  Of course, computational power will get less expensive as time goes on, and the same number of operations can and will get faster, but with the blowfish algorithm you need only increment the log to double the computational cost, keeping the cracking of your database safely outside the realm of technical feasibility.</p>
<p>So how does one use the blowfish algorithm in PHP?  The <a href="http://php.net/manual/en/function.crypt.php" style="font-family: 'Courier New',courier,monospace;">crypt()</a> function is your friend!  However, the manual is not entirely clear on the implementation details of blowfish, as it does not include one key part (which caused me to tear my hear out a little bit, since, as a Windows user, I was unable to check the man pages for crypt(3)) in any great detail, and that is the log base.  When you generate the salt, you will need to prepend it with an instruction string that tells it what kind of hash to generate, and what parameters to use.  Furthermore, the salt is not sixteen characters, but sixteen BYTES, and the characters in your hash will be read as a BASE64 encoded string, which means that using characters not allowed in a base64 string will cause the function to revert back to whatever the default is on your system, probably STD_DES or MD5.</p>
<p>All of that information might have seemed a bit hazy, so I&#8217;ll include the timing example I used before modified to suit crypt/blowfish.  Note also that I am storing the microtime result on every iteration of the for-loop, as in order to give you worst-case scenarios on the cracker&#8217;s timetable, I had to give best-case timings on the hashing, and that means as few calls to microtime as possible.</p>
<div class="wp_syntax">
<div class="code">
<pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">(</span><span style="color: #0000ff;">'ITERATIONS'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$tt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$th</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">(</span><span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$j</span> <span style="color: #339933;">&lt;</span> ITERATIONS<span style="color: #339933;">;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$j</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
	<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">(</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">(</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #009900;">(</span><span style="color: #000088;">$z</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">(</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$start</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$i</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
		<span style="color: #000088;">$k</span> <span style="color: #339933;">=</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">(</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'$2a$07$'</span> <span style="color: #339933;">.</span> <span style="color: #009900;">(</span>string<span style="color: #009900;">)</span><span style="color: #000088;">$z</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">}</span>
	<span style="color: #000088;">$tt</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">(</span><span style="color: #000088;">$z</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$start</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$th</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span>
&nbsp;
<span style="color: #990000;">var_dump</span><span style="color: #009900;">(</span><span style="color: #000088;">$tt</span> <span style="color: #339933;">/</span> ITERATIONS<span style="color: #339933;">,</span> <span style="color: #000088;">$th</span> <span style="color: #339933;">/</span> ITERATIONS<span style="color: #009900;">)</span><span style="color: #339933;">;</span></pre>
</div>
</div>
<p>Of paramount importance is the literal string prepended to the stored value.  The first four characters, <span style="font-family:'Courier New',courier,monospace;">$2a$</span>, simply instruct crypt to use the blowfish algorithm.  The next three, <span style="font-family:'Courier New',courier,monospace;">07$</span>, pass the number 7 as our log-base-2 argument, meaning the computation will run for 2<sup>7</sup> iterations.  After that, we concatenate our salt (values shorter than 22 characters will be padded in a predictable fashion, and longer than 22 will be truncated) to the argument string and send it off on its merry, 12ms way.</p>
<p>Do I think I&#8217;ve defeated all the clever crackers out there?  Certainly not.  However, I&#8217;m definitely in a better boat for having stood on the shoulders of giants and listened to people smarter than I am about security.  In fact, don&#8217;t listen to me, check out these links for more info:</p>
<p><a href="http://vwng.blogspot.com/2008/01/php-hash.html">(Victor) Xi Wang talks about salt, nonces and rainbow tables</a></p>
<p><a href="http://chargen.matasano.com/chargen/2007/9/7/enough-with-the-rainbow-tables-what-you-need-to-know-about-s.html">Matasano Security, LLC, talks about blowfish and why you shouldn&#8217;t design your own password protection scheme.</a></p>
<p><a href="http://www.bletchleypark.net/cryptology/blowfish.html">Linked earlier, explains blowfish encryption &#8211; very math/pseudocode heavy.</a></p>
<p><a href="http://php.net/manual/en/function.crypt.php">Also linked earlier, the PHP Manual Entry for Crypt()</a></p>
<p>Happy Hashing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dereleased.com/2010/02/09/lets-talk-about-your-password-model/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Arrays of Objects and __get: Friends Forever</title>
		<link>http://www.dereleased.com/2010/01/11/arrays-of-objects-and-__get-friends-forever/</link>
		<comments>http://www.dereleased.com/2010/01/11/arrays-of-objects-and-__get-friends-forever/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 22:51:13 +0000</pubDate>
		<dc:creator>Clark</dc:creator>
				<category><![CDATA[Design Considerations]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[PHP Quirks]]></category>
		<category><![CDATA[The Internet]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[ArrayObject]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[object-array]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[visibility]]></category>

		<guid isPermaLink="false">http://www.dereleased.com/?p=138</guid>
		<description><![CDATA[In PHP, an object is always passed around as a reference, which allows one to deal with objects in a very transparent manner, since the only way to deal with a by-value copy instead of the real deal is to explicitly use the clone operator. Recently, I came upon a situation in which it was [...]]]></description>
			<content:encoded><![CDATA[<p>In PHP, an object is always passed around as a reference, which allows one to deal with objects in a very transparent manner, since the only way to deal with a by-value copy instead of the real deal is to explicitly use the <strong>clone</strong> operator.  Recently, I came upon a situation in which it was very useful for me to have an array of objects inside an object; the scenario was somewhat simple, a parent object can contain an indefinite number of children, and in order to have easy access to them I created a lazy loading property to contain them all as an array, indexed by their unique IDs.  Of course, setting the stage for that is a bit more complicated than is needed for this example, so here is an extremely minimal example:</p>
<div class="wp_syntax">
<div class="code">
<pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> foo <span style="color: #009900;">{</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$bar</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">(</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span><span style="color: #009900;">[</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> stdClass<span style="color: #339933;">;</span>
	<span style="color: #009900;">}</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __get<span style="color: #009900;">(</span><span style="color: #000088;">$n</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">}</span>
<span style="color: #009900;">}</span></pre>
</div>
</div>
<p>So now we have a simple object with an array whose single element is an instance of PHP&#8217;s default object, stdClass.  In reality you&#8217;d likely have more than just one element to the array, but it&#8217;s not necessary here to prove the point.  Now, since objects are always returned by reference, accessing the first index of the array returned by __get when you try to access any member will allow you unfettered access to the contents of the object, to do with what you will (or rather, what the object will allow you to do).</p>
<p>With that in mind, let&#8217;s examine this:</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: #000000; font-weight: bold;">new</span> foo<span style="color: #339933;">;</span>
<span style="color: #000088;">$foo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span><span style="color: #009900;">[</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baz</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'I am a test'</span><span style="color: #339933;">;</span></pre>
</div>
</div>
<p>This code is pretty easy to follow, and in fact does exactly what you&#8217;d expect: the stdClass object sitting in the first element of the &#8220;bar&#8221; array has a new member, &#8220;baz&#8221;, defined and assigned.  Viewing the contents of the object will show that this is exactly what happened:</p>
<div class="wp_syntax">
<div class="code">
<pre class="php" style="font-family:monospace;">  <span style="color: #009900;">[</span><span style="color: #0000ff;">"bar"</span><span style="color: #339933;">:</span><span style="color: #0000ff;">"foo"</span><span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">private</span><span style="color: #009900;">]</span><span style="color: #339933;">=&gt;</span> <span style="color: #009900;">{</span>
  <span style="color: #990000;">array</span><span style="color: #009900;">(</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
    <span style="color: #009900;">[</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">=&gt;</span>
    object<span style="color: #009900;">(</span>stdClass<span style="color: #009900;">)</span><span style="color: #666666; font-style: italic;">#2 (1) {
</span>      <span style="color: #009900;">[</span><span style="color: #0000ff;">"baz"</span><span style="color: #009900;">]</span><span style="color: #339933;">=&gt;</span>
      string<span style="color: #009900;">(</span><span style="color: #cc66cc;">11</span><span style="color: #009900;">)</span> <span style="color: #0000ff;">"I am a test"</span>
    <span style="color: #009900;">}</span>
  <span style="color: #009900;">}</span>
<span style="color: #009900;">}</span></pre>
</div>
</div>
<p>However, there&#8217;s a problem.  Somewhere along the line, we generated a notice:</p>
<blockquote><p>Notice: Indirect modification of overloaded property foo::$bar has no effect in &#8230;</p></blockquote>
<p>While the notice certainly won&#8217;t halt the script&#8217;s execution, and the expected (and desired) action has taken place with no other apparent side effects, we are left with the conundrum of what to do with this notice (Note: While <a href="http://bugs.php.net/bug.php?id=41641">this issue has been brought to the attention of the PHP team</a>, no word of a fix has yet surfaced).  Since I am a firm believer that Notices and Warnings are potentially more dangerous than Fatal Errors, I won&#8217;t simply turn off error reporting; indeed, since the errors are still raised that doesn&#8217;t completely fix the small performance hit of generating the error, either.</p>
<p>In order to address this issue, it is important to understand what the notice is trying to tell us.  Once upon a time, __get was a return-by-reference function by default.  Of course, this doesn&#8217;t really help with wanting to prevent the modification of an object&#8217;s internal data, so __get was corrected to always return by value; in fact, even objects are &#8220;returned by value&#8221; in this case, since the value of the member variable is being returned (which just happens to also be a reference to an object), whereas the old __get would have returned a reference to the member variable itself; while the difference may seem subtle, it is monumental.  Since this change occurred, it was important to notify coders that if they attempted to modify the contents of an array element which came from an overloaded array, this action would have no effect, as the modified element would only exist in the copy returned from __get.</p>
<p>Armed with this knowledge of history, we have a few obvious options for solving this problem</p>
<ol>
<li><span style="font-weight:bold;font-family: 'Courier New',courier,mono;">public function &#038; __get($n)</span>.  This will technically prevent the warning from coming up, but if you&#8217;re going to go this route you might as well just declare all your member variables as public anyway, as this is what it will effectively cause __get to do.  It opens the door to such dangerous situations as:
<div class="wp_syntax">
<div class="code">
<pre class="php" style="font-family:monospace;"><span style="color: #000088;">$foo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span></pre>
</div>
</div>
<p>That&#8217;s right, if you return by reference explicitly in __get, then you will circumvent any rules you&#8217;ve set for assignment via __set.  Even objects are not immune to this, as a reference to the member variable (itself containing a reference) will be returned.  This option removes the efficacy of even having visibility operators for anything you intend to provide overloaded access to.</li>
<li><strong>Assign a variable to the contents of the array element</strong>.  Again, technically, this works, but it is messy, inelegant, and is nowhere near the ideal.  Here are two examples:
<div class="wp_syntax">
<div class="code">
<pre class="php" style="font-family:monospace;"><span style="color: #000088;">$bar</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$foo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$bar</span><span style="color: #009900;">[</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baz</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'This works'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">###
</span><span style="color: #000088;">$bar</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$foo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span><span style="color: #009900;">[</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$bar</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baz</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'This also works'</span><span style="color: #339933;">;</span></pre>
</div>
</div>
<p>Again, though, this is not the clean, simple approach we were looking for to begin with.
</li>
<li><strong>Just turn off notices</strong>.  Nah, we ain&#8217;t doin&#8217; that.</li>
</ol>
<p>So what&#8217;s left to consider?  After thinking about the problem for a little while, I realized that this problem wouldn&#8217;t even exist if I could just store the array as an object instead, but objects don&#8217;t allow numerical indices, so it would take a little jimmy-rigging to get it to work.  Here was the first version:</p>
<div class="wp_syntax">
<div class="code">
<pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> arrayReference <span style="color: #009900;">{</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __set<span style="color: #009900;">(</span><span style="color: #000088;">$n</span><span style="color: #339933;">,</span> <span style="color: #000088;">$v</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_<span style="color: #009900;">[</span><span style="color: #000088;">$n</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$v</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">}</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __get<span style="color: #009900;">(</span><span style="color: #000088;">$n</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">(</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">(</span><span style="color: #000088;">$n</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_<span style="color: #009900;">)</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_<span style="color: #009900;">[</span><span style="color: #000088;">$n</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">}</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_<span style="color: #009900;">[</span><span style="color: #000088;">$n</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_<span style="color: #009900;">[</span><span style="color: #000088;">$n</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">}</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __call<span style="color: #009900;">(</span><span style="color: #000088;">$n</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">(</span><span style="color: #000088;">$n</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'array'</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_<span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">}</span>
	<span style="color: #009900;">}</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> _<span style="color: #009900;">(</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_<span style="color: #339933;">;</span>
	<span style="color: #009900;">}</span>
<span style="color: #009900;">}</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> foo <span style="color: #009900;">{</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$bar</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">(</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> arrayReference<span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">{</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">}</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> stdClass<span style="color: #339933;">;</span>
	<span style="color: #009900;">}</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __get<span style="color: #009900;">(</span><span style="color: #000088;">$n</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">}</span>
<span style="color: #009900;">}</span>
&nbsp;
<span style="color: #000088;">$foo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> foo<span style="color: #339933;">;</span>
<span style="color: #000088;">$foo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">{</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">}</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$foo</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$foo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">{</span><span style="color: #cc66cc;">99</span><span style="color: #009900;">}</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> stdClass<span style="color: #339933;">;</span>
<span style="color: #000088;">$foo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">{</span><span style="color: #cc66cc;">99</span><span style="color: #009900;">}</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baz</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">33</span><span style="color: #339933;">;</span></pre>
</div>
</div>
<p>Which, for the adjusted syntax, actually worked out pretty well.  It might take more than an instant glance from your average PHP coder for what&#8217;s going on to make sense, or even seem syntactically correct, but it certainly worked; it even allowed for loop-based iteration by doing something like so:</p>
<div class="wp_syntax">
<div class="code">
<pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span><span style="color: #009900;">(</span><span style="color: #000088;">$foo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">array</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$v</span><span style="color: #009900;">)</span></pre>
</div>
</div>
<p>While that isn&#8217;t ideal, it&#8217;s fairly transparent about what it&#8217;s doing.</p>
<p>I wish there were a more climactic way to put this, but there isn&#8217;t: The next step involved me trying to combine the SPL&#8217;s ArrayObject built in class to allow natural array access to my wrapper class, and after a few minutes playing with my new hideous child-beast amalgamate and its Reflection, I finally settled on this for the final version of the class:</p>
<div class="wp_syntax">
<div class="code">
<pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> foo <span style="color: #009900;">{</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$bar</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">(</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> arrayObject<span style="color: #339933;">;</span>
	<span style="color: #009900;">}</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __get<span style="color: #009900;">(</span><span style="color: #000088;">$n</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">}</span>
<span style="color: #009900;">}</span></pre>
</div>
</div>
<p>No more messy syntax, no compromises, no hideous amalgamate beasts, and no figuring out how to mangle my behemoth class this lesson actually needed to be applied to in order to extend ArrayObject for the purposes of accessing just one property, as I saw <a href="http://weierophinney.net/matthew/archives/131-Overloading-arrays-in-PHP-5.2.0.html">advocated elsewhere during the googleing portion of my problem solving routine</a>.  The example I first gave?  Works just fine, and no error since the property being returned is an object, not an array.  Sometimes the best solution is fiendishly simple; the only real consideration I had to make here was that, in its actual application, the array in question was declared null so it could be lazy loaded, and since you can&#8217;t use the &#8220;new&#8221; keyword or even type-hinting in class member declarations, I had to be careful to make sure the lazy loading mechanism would still work, but I was never declaring a traditional array either: all in all, a 5 minute job to implement and test.</p>
<p>Five minutes that made the past day or so of work seem rather silly indeed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dereleased.com/2010/01/11/arrays-of-objects-and-__get-friends-forever/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On Net Neutrality &#8211; A Plea</title>
		<link>http://www.dereleased.com/2009/10/25/on-net-neutrality/</link>
		<comments>http://www.dereleased.com/2009/10/25/on-net-neutrality/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 13:56:30 +0000</pubDate>
		<dc:creator>Clark</dc:creator>
				<category><![CDATA[The Internet]]></category>
		<category><![CDATA[FCC]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[ISP]]></category>
		<category><![CDATA[McCain]]></category>
		<category><![CDATA[Net Neutrality]]></category>
		<category><![CDATA[Network Neutrality]]></category>
		<category><![CDATA[Neutrality]]></category>
		<category><![CDATA[Telco]]></category>

		<guid isPermaLink="false">http://www.dereleased.com/?p=126</guid>
		<description><![CDATA[Recently, McCain introduced a bill for consideration which would effectively block the FCC&#8217;s attempts at creating so-called &#8220;Network Neutrality&#8221; rules which ISPs and Telcos would be required to follow.  Now, setting aside for a moment the fact that McCain has received more than double as much money as the next-highest senator to be bankrolled by [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, <a title="ComputerWorld" href="http://www.computerworld.com/s/article/9139784/McCain_introduces_bill_to_block_FCC_s_net_neutrality_rules" target="_blank">McCain introduced a bill</a> for consideration which would effectively block the FCC&#8217;s <a title="The New York Times" href="http://bits.blogs.nytimes.com/2009/10/22/fcc-begins-crafting-rules-on-network-neutrality/?hpw" target="_blank">attempts at creating so-called &#8220;Network Neutrality&#8221; rules</a> which ISPs and Telcos would be required to follow.  Now, setting aside for a moment the fact that <a title="PC World" href="http://www.pcworld.com/article/174280/surprise_mccain_biggest_beneficiary_of_telcoisp_lobby_money.html" target="_blank">McCain has received more than double as much money as the next-highest senator to be bankrolled by the Telco/ISP industry</a>, and the comments made by leading nutjob crazy-person and all-around internet expert Glenn Beck, I&#8217;d like to first offer an explanation of what&#8217;s at stake here for <a title="The Huffington Post" href="http://www.huffingtonpost.com/2008/06/11/mccain-admits-he-doesnt-k_n_106478.html" target="_blank">those who don&#8217;t really understand the nuts-and-bolts of how the internet works</a>.</p>
<p>I am going to use a very general analogy for how the internet works: a city.  Now, the city that is the internet is a very strange city indeed.  This city isn&#8217;t owned by any single country or government.  Just about anyone can come and go as they please.  Now, this city has three basic pieces, and they way they blend isn&#8217;t that different from how any city works:  you have content &#8220;Servers,&#8221; content &#8220;Consumers,&#8221; and a transit system.  The Servers could be anything from a tent someone just set up for a while to a huge mall, or a towering building, but it is basically somewhere you can <strong>get some content</strong>.  In Internet City, just about anybody can become a Server.  Then, there are the Consumers.  This is probably where you fit in to Internet City &#8212; when you use the internet, you are at home, or at work, or on your phone, but you are mostly-if-not-exclusively <strong>retrieving content</strong> from these Servers (this includes posting on social media sites, such as Twitter, Facebook, MySpace, et al).</p>
<p>The third part of the city is the transit system, which is your ISP.  At the top of the chain are the people who make all the roads, the asphalt, the car you will drive around the internet city, and pretty much everything you will need to get from point A to point ∞.  These are the <a title="Wikipedia" href="http://en.wikipedia.org/wiki/Tier_1_network" target="_blank">Tier-1 Network</a> Providers (and to some extent the larger Tier-2 providers, but this discussion is beyond the scope of this analogy); they are few, and they are powerful.  Of course, they generally don&#8217;t personally make every single road; who handles the road from there just depends on where it leads, who is willing to go there, and what services they intend to offer.  These are the <a title="Wikipedia" href="http://en.wikipedia.org/wiki/Tier_2_network" target="_blank">Tier-2 and Tier3 Networks</a>, and they are probably more familiar to you.</p>
<p>Now, how fast you can get somewhere depends on three things: What kind of car you bought (your specific internet package), what kind of road the journey takes (the quality of ALL the connections from you to your destination, and back), and how far you have to go.  If you have a mac-daddy broadband connection, and you are accessing a major site (major news networks, etc), you&#8217;ll spend most of your time on the metaphorical highway, and should get your data rather quickly, and the inverse is true as well.  Any further delving into how this works is also beyond the scope of this analogy, but you get the idea.</p>
<p>So what is Net(work) Neutrality?  The idea is that no matter from where or whom traffic comes, ISPs may not give preferential treatment to it.  As fast as the hardware will carry it must it go.  Groups and people who support this include small ISPs, who don&#8217;t want their customers to get abused by the larger and higher-tier internet providers, as well as Tim Berners-Lee, a man whom you may not have heard of but whom you are in contact with right now, as he practically invented the &#8220;World Wide Web&#8221; we have come to know.  Opposing this is the idea that an ISP should be allowed to decide to give (at their own, private, and in this writer&#8217;s opinion, dubious, whim) preferential treatment to some data, at the expense of other data.  On the relatively mild side of the spectrum, they could choose to allocate their network resources in such a way that, for example, their particular <abbr title="Voice over Internet Protocol, basically 'Internet Telephone'">VoIP service</abbr> received preference over competitors such as Vonage and Skype.  This is mild, and arguably benign in the grand scheme of things (so long as they advantage isn&#8217;t dialed to extreme levels, to the point that it is a detriment to competitors), and not what the issue is about.  Given total freedom of how data flows, they could route traffic in such a way that their own VoIP service takes precedence over their competitor&#8217;s VoIP service &#8212; they could even extort a fee to avoid this sort of &#8220;traffic shaping&#8221; &#8212; all without the consumer being able to defend against this action.  The customer would then be nearly forced to use that company&#8217;s VoIP service, or any service it chose, in order to get any semblance of quality.</p>
<p>A real-world example would be like allowing the government to create a lane of traffic in which only USPS vehicles could travel, and then forcing UPS and FedEx to use 1-lane dirt roads instead of the highways, since they are a competing service.  Or, in the analogy of Internet City, it would be like the powers-that-be on the roads checking to see where you are going (in Internet City, you have to announce where you&#8217;re going or you can&#8217;t get there), and then forcing you to use smaller, slower roads, or yield to indefinite amounts of other traffic, based on whether or not you were going to one of their in-house holdings.  Nightmarish.</p>
<p>Some of the points brought up against Net Neutrality are, quite frankly, absolutely ludicrous.  As someone posted on the PC World forums:</p>
<blockquote><p><q>“What this article completely fails to state (talk about one-sided reporting!) is that Google has devoted far more money to lobbying for regulation of the Internet than the telcos have to defending itself against it. Google has given hundreds of millions of dollars to slimy DC &#8220;astroturf&#8221; groups &#8212; that is, groups that pretend to be acting in the &#8220;public interest&#8221; but in fact do what their contributors tell them to do &#8212; which are lobbying for &#8220;network neutrality&#8221; legislation and regulation. And if you look at the details of all of these regulations &#8212; which start with high-minded language that talks about &#8220;freedom&#8221; and &#8220;openness&#8221; &#8212; all of them would tie the hands of ISPs and of Google&#8217;s competitors, while giving Google free rein to do whatever it wants, including to serve as an Internet gatekeeper. The regulations would also raise the price of Internet service, lower the quality of that service, and reduce consumers&#8217; competitive choices by putting small providers out of business.<br style="line-height:1em;" /><br style="line-height:1em;" />Remember: corporations don&#8217;t act out of the goodness of their hearts. Monopolist Google wouldn&#8217;t be doing this if it weren&#8217;t seeking to maximize its profits at the expense of consumers. So, remember: &#8220;network neutrality&#8221; isn&#8217;t neutral. It is Google&#8217;s corporate agenda, and it strongly favors Google.”</q></p></blockquote>
<p>Wow, that is a lot of Big Brother Meets Google conspiracy theorizing (Ballmer, is that you?)!  Aside from that, the points this person raises are thus:</p>
<ol>
<li><strong>It will raise the price of internet service.</strong> How, exactly?  One of the possibilities is that, after some time (maybe a few years) of ISPs shaping traffic however they please, they will offer a new &#8220;unshaped&#8221; plan for only $20.00 more per month, thereby allowing them to charge you more for the same service you&#8217;re getting at the time this article was written.  However, if we are given true Net Neutrality, there is no reason for the price to go up (other than inflation, which doesn&#8217;t count).  After all, if nothing changes, then there&#8217;s no new way to sell us back what we&#8217;re already getting.</li>
<li><strong>It would lower the quality of internet service.</strong> Again, how?  If you think that internet service means that all you do all day is browse your ISPs website and use their video service, their email service, their phone service, and so on, then maybe it would &#8220;lower&#8221; the quality from the standpoint that it would not be &#8220;increasing&#8221; the quality, which as previously mentioned would be at the expense of everyone else.  Quality won&#8217;t degrade because we didn&#8217;t decide to let the ISPs tell us what is more valuable.  To re-iterate the point, Net Neutrality basically means nothing changes.</li>
<li><strong>It will reduce consumers&#8217; competitive choices by putting small providers out of business.</strong> No, just no.  <a title="PC World (2nd Paragraph)" href="http://www.pcworld.com/article/174062/canada_weighs_in_with_net_neutrality_ruling.html" target="_blank">Small ISPs in Canada came out strongly in favor of Net Neutrality</a> before such legislation was passed anyway.  The larger wholesale (Tier-2) internet providers were shaping bandwidth to the point that it affected large numbers of users of the smaller Tier-3 providers, and the small providers resisted, but at the end of the day they are buying internet (albeit in larger increments than you or I) from the Tier-1 providers, and they are the ones against Net Neutrality.  Funny how the exact people who are against neutrality are feeding you the exact opposite of truth about what will happen to the &#8220;competition.&#8221;  And, to round out this bullet point, Tier-1 providers who are going to bat on this one (AT&amp;T, Cogent, et al) just don&#8217;t care what the little guys are doing: they have the pipes in the middle, and everyone else needs them.</li>
</ol>
<p>Of course, these are just the arguments on Net Neutrality that actually have something to do with the subject at hand!  Then there are the downright lies spread by, among others, Glenn Beck, such as:</p>
<ol>
<li><strong>Net Neutrality will bring the Fairness Doctrine to the internet, resulting in government censorship/control of the content on the internet.</strong> It is extremely important to remember that, above all, the Internet does not exist solely in America.  The internet is no longer any more an American thing than it is a Russian thing or any other location-based thing.  The internet is vast, it is (from the point of view of the average user) limitless, and no one country owns it.  America could try to censor the content located in America.  America might even try to create treaties with other nations to control what is hosted in their countries.  However, all this will do is open up a market for &#8220;regulation-free&#8221; hosts, in countries who wouldn&#8217;t sign any such treaty (maybe a nice time to wire-up some third-world African nations?), or something else like it.  Let me, again, put this in the simplest terms possible: <strong>NO SINGLE COUNTRY CAN CONTROL THE CONTENT OF THE INTERNET.  IN ALL LIKELIHOOD, NO COMBINATION OF COUNTRIES CAN CONTROL THE CONTENT OF THE INTERNET</strong>.The internet is not just one person, one company, or one country.<br style="line-height:1em;" /><br style="line-height:1em;" />And to think, I said all of that without even mentioning that <strong>NET NEUTRALITY DOES NOT IN ANY WAY, SHAPE OR FORM REFERENCE OR ATTEMPT TO INSTITUTE ANY SORT OF FAIRNESS DOCTRINE.</strong> This argument would be laughable if it weren&#8217;t given so much credence by lying morons like Glenn Beck who, like McCain (from whom I respectfully withhold the indictment of &#8220;lying moron&#8221;), really don&#8217;t know the first thing about the technology they are so passionately speaking about, and the credence it will be given by the people that listen to and trust them.  This issue is a <span style="color: #ff0000;">Red Herring</span>.</li>
<li><strong>The government will be stepping in as a watchdog of the internet.</strong> No, the government would simply be stepping in to maintain the status quo so that Tier-1 providers don&#8217;t start exploiting their customers in unfair ways.  Everybody, whether Servers or Consumers, pays for the &#8220;pipes in the middle&#8221; that is the transit system &#8212; why does the transit system then get to start deciding at what speed or priority I get to receive the content I&#8217;ve payed them good money to get?  This issue is a misunderstanding.</li>
<li><strong>Net Neutrality is a ploy by left-wing liberals to socialize internet access.</strong> I don&#8217;t even have a diatribe for this one, I&#8217;ll just rest on saying that no, it&#8217;s not in the bill, it&#8217;s not on the table, no.  Prominent liberals, such as <a title="Wikipedia" href="http://en.wikipedia.org/wiki/Van_Jones" target="_blank">“Van” Jones</a>, have spoken about how we should be giving broadband access, for free, to everyone, like they do in some other countries, but this is a separate goal from the standpoints of the technology, the FCC, and the implementation, as well as the bill that is on the table.  These views are not encompassed by Net Neutrality, but are in fact a <span style="color: #ff0000;">Red Herring</span>.</li>
<li><strong>Revolution!  Marxism!  Destroying Capitalism!  Rabble rabble!</strong> It is important to remember that you can hire someone to kill someone else, but this is considered an unfair, immoral, and reprehensible business practice and thus it is forbidden.  Regulations on how you can do business with respect to, quite frankly, not just plain crapping all over the environment, the public, and your own consumers, are commonplace in our legal system; you really, really wouldn&#8217;t want to live in a world where companies could do whatever they wanted any time as long as it turned a buck.  And as for all the talks of people somehow magically using Net Neutrality for revolutionary and/or Marxist goals?  These are, you guessed it, <span style="color: #ff0000;">Red Herrings</span>!  And a special breed of Ad Hominem Red Herrings at that!  In fact, given the blatantly untrue and often unfounded accusations that Beck has made against his opponents, I&#8217;d say this also qualifies as a <span style="color: #ffff00;">Straw Man Fallacy</span>.</li>
<li><strong>The government will be controlling content.</strong> No, see argument 1.</li>
<li><strong>The internet won&#8217;t work as well, things will load slowly, etc.</strong> The reason given here is/was that there won&#8217;t be enough competition and so on.  Again, Network Neutrality advocates the status quo &#8212; that is, just because you have the traffic before you sell it doesn&#8217;t mean you can decide how it&#8217;s used once you&#8217;ve sold it to me.  This is an <span style="color: #ccffcc;">Outright Lie</span>.</li>
<li><strong>Net Neutrality does not help innovate business.</strong> You&#8217;re right, it doesn&#8217;t.  It protects the little guy from having big businesses &#8220;innovate&#8221; more money out of his wallet.  Next.</li>
<li><strong>The government will take over the internet.</strong> Again, see argument 1 &#8212; the American government can no more regulate the internet than it can nail Jell-O to a tree.  The long and the short of it is that, even if the government suddenly decided it wanted to own all hosting services (remember, content is DISTINCT from transport), anyone can set up a server on any computer connected to the internet, and suddenly they are content providers.  The internet is a vast, untamed, wild environment.  <strong>THE GOVERNMENT CANNOT CONTROL IT</strong>.</li>
</ol>
<p>Mark Lloyd said something very important that bears quoting:</p>
<blockquote><p><q>“Unfortunately, the powerful cable and telecom industry doesn&#8217;t value the Internet for its public interest benefits.  Instead, these companies too often believe that to safeguard their profits … they must control what content you see and how you get it.  Their plans could have dire consequences for those whose voices are often marginalized by our nation&#8217;s media system.” -Mark Lloyd, Federal Communications Commission.</q></p></blockquote>
<p>Beck&#8217;s guest then attacked him, specifically saying &#8220;they turn things inside out,&#8221; then going on to imply that Lloyd wanted to use Net Neutrality as a means to Government Control and a re-introduction of the fairness doctrine, and that he would use this new government brand internet to give voices to the &#8220;marginalized people&#8221; a la the fairness doctrine.  He not only completely misconstrued (I&#8217;d say misunderstood except I believe that he is an evil little man) the quote but, in fact, turned it as inside out as he claimed the Net Neutrality proponents are doing.</p>
<p><span style="font-size:2em;font-weight:bold;">TL;DR</span> Net Neutrality, though technically regulation, is very mild and serves only to prevent the ISPs and Telecoms from regulating how the traffic you pay for gets shaped; it provides no slippery slope nor sets any precedent for the government to control the internet.  Supporting Net Neutrality (and opposing Sen. McCain&#8217;s bill) is supporting the status quo, and supporting the rights of the consumer.  The government cannot, and will not, control the content of the internet; not only is not that even on the table here, it is fundamentally impossible, and outside the scope of even the FCC.  Before you overreact, learn what&#8217;s actually going on.  Please.</p>
<p>P.S., for another well-thought-ought viewpoint on net neutrality, check out <a title="Brad Ideas" href="http://ideas.4brad.com/remaining-neutral-network-neutrality-its-monopoly-stupid" target="_blank">this post on Brad Ideas</a>.  He believes that we don&#8217;t need to codify Net Neutrality into law, but I think he would also support the not coding into law of the exact opposite.  I disagree with him, and think that we should make it law, if only because this is the second time that opposition has arisen loudly in government, but his opinion is worth reading nonetheless.</p>
<p>Additional Link: <a href="http://www.ethioplanet.com/news/2009/10/25/google-verizon-join-forces-to-support-net-neutrality/">http://www.ethioplanet.com/news/2009/10/25/google-verizon-join-forces-to-support-net-neutrality/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dereleased.com/2009/10/25/on-net-neutrality/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML Is Like Violence&#8230;</title>
		<link>http://www.dereleased.com/2009/09/30/xml-is-like-violence/</link>
		<comments>http://www.dereleased.com/2009/09/30/xml-is-like-violence/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 22:29:05 +0000</pubDate>
		<dc:creator>Clark</dc:creator>
				<category><![CDATA[The Internet]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.dereleased.com/?p=114</guid>
		<description><![CDATA[&#8230;if it hasn&#8217;t solved your problem yet, you&#8217;re not using enough. Curiously, I always thought of that little quip as a subtle indictment of the problems with XML, but it seems to almost be a rallying cry for proponents of the standard (I refuse to recognize XML as a &#8220;language&#8221;).  And when I say proponents, [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230;if it hasn&#8217;t solved your problem yet, you&#8217;re not using enough.  Curiously, I always thought of that little quip as a subtle indictment of the problems with XML, but it seems to almost be a <a title="XML Is Like Violence Dot Com" href="http://www.xmlislikeviolence.com/" target="_blank">rallying cry for proponents of the standard</a> (I refuse to recognize XML as a &#8220;language&#8221;).  And when I say proponents, I actually mean &#8220;fanatics.&#8221;</p>
<p>The problem I have with XML, my &#8220;beef&#8221; if you will, is certainly not XML&#8217;s fault; it&#8217;s the fault of the overzealous developer who wants to use <a title="TheDailyWTF.com :: Interesting Bitmap" href="http://thedailywtf.com/Articles/Interesting-Bitmap.aspx" target="_blank">XML as a way to transmit pixel data over the network</a>.  If you look at that post and your first thought is something like:</p>
<blockquote><p>Well, duh, of course that&#8217;s the wrong way to do it, I&#8217;d use something like:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;signature<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pixel</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">"127"</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">"90"</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pixel</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">"128"</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">"91"</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/signature<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
</blockquote>
<p>Well, you&#8217;re probably already too far gone; this post isn&#8217;t for you.</p>
<p>Of course, you still have to send your data somehow, and since raw bytestreams are out this fall, why not look into an alternative format?  May I recommend some <a title="JSON - The Fat-Free Alternative to XML" href="http://www.json.org" target="_blank">JSON</a>?  Let&#8217;s take a look at a simple and realistic (ish) case of JSON -vs- XML: representing an order in a format that a person and a computer can read.</p>
<p>For this experiment, I will be placing order number 233 on behalf of customer number 971.  Said customer would like 2 each of item number 2751 and item number 1765, &#8220;beef brats&#8221; and &#8220;brat buns&#8221; respectively.  Said customer would also like the buns warmed but not toasted, and the brats to be of the &#8220;Beer Basted&#8221; variety, but not filled with cheese.  Here we go.</p>
<p>JSON:</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> order <span style="color: #339933;">=</span> <span style="color: #009900;">{</span>
	orderId<span style="color: #339933;">:</span> <span style="color: #CC0000;">233</span><span style="color: #339933;">,</span>
	customerId<span style="color: #339933;">:</span> <span style="color: #CC0000;">971</span><span style="color: #339933;">,</span>
	items<span style="color: #339933;">:</span> <span style="color: #009900;">[</span>
		<span style="color: #009900;">{</span>
			itemId<span style="color: #339933;">:</span> <span style="color: #CC0000;">2751</span><span style="color: #339933;">,</span>
			<span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"Beef Brats"</span><span style="color: #339933;">,</span>
			quantity<span style="color: #339933;">:</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span>
			options<span style="color: #339933;">:</span> <span style="color: #009900;">[</span>
				<span style="color: #009900;">{</span>
					<span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"beerbasted"</span><span style="color: #339933;">,</span>
					value<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span>
				<span style="color: #009900;">}</span><span style="color: #339933;">,</span>
				<span style="color: #009900;">{</span>
					<span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"cheesefilled"</span><span style="color: #339933;">,</span>
					value<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
				<span style="color: #009900;">}</span>
			<span style="color: #009900;">]</span>
		<span style="color: #009900;">}</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">{</span>
			itemId<span style="color: #339933;">:</span> <span style="color: #CC0000;">1765</span><span style="color: #339933;">,</span>
			<span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"Brat Buns"</span><span style="color: #339933;">,</span>
			quanity<span style="color: #339933;">:</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span>
			options<span style="color: #339933;">:</span> <span style="color: #009900;">[</span>
				<span style="color: #009900;">{</span>
					<span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"warmed"</span><span style="color: #339933;">,</span>
					value<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span>
				<span style="color: #009900;">}</span><span style="color: #339933;">,</span>
				<span style="color: #009900;">{</span>
					<span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">"toasted"</span><span style="color: #339933;">,</span>
					value<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
				<span style="color: #009900;">}</span>
			<span style="color: #009900;">]</span>
		<span style="color: #009900;">}</span>
	<span style="color: #009900;">]</span>
<span style="color: #009900;">}</span><span style="color: #339933;">;</span></pre>
</div>
</div>
<p><span style="font-size: 9px; color: #CCC">EDIT: I noticed the objects weren&#8217;t exactly semantically similar; I fixed this because fair&#8217;s fair (and it only increases the size of the JSON by about 20 bytes, whereas the equivalent XML correction might have taken triple that</span></p>
<p>Versus the contender, XML:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">"1.0"</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">"UTF-8"</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>233<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;customerId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>971<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/customerId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2751<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>beef brats<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;quantity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/quantity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>beer basted<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>cheese filled<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1765<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>brat buns<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;quantity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/quantity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>warmed<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>toasted<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>Now, XML proponents likely will not take this one lying down.  They&#8217;ll look at that document and accuse me of being the worst, most evil, vile, baby-eating slanderer ever to take a crack at their beloved XML.  After all, one could just as easily use documents with more concise structure, something that doesn&#8217;t just look so gigantic, like one of these:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">"1.0"</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">"UTF-8"</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;order</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"233"</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;customer</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"971"</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"2751"</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>beef brats<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;quantity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/quantity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"beerbasted"</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"cheesefilled"</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"1765"</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>brat buns<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;quantity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/quantity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"warmed"</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"toasted"</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">"1.0"</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">"UTF-8"</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;order</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"233"</span> <span style="color: #000066;">customerid</span>=<span style="color: #ff0000;">"971"</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"2751"</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"beef brats"</span> <span style="color: #000066;">quantity</span>=<span style="color: #ff0000;">"2"</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"beerbasted"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"true"</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"cheesefilled"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"false"</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"1765"</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"brat buns"</span> <span style="color: #000066;">quantity</span>=<span style="color: #ff0000;">"2"</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"warmed"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"true"</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"toasted"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"false"</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">"1.0"</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">"UTF-8"</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;order</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"233"</span> <span style="color: #000066;">customerid</span>=<span style="color: #ff0000;">"971"</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"2751"</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"beef brats"</span> <span style="color: #000066;">quantity</span>=<span style="color: #ff0000;">"2"</span> <span style="color: #000066;">beerbasted</span>=<span style="color: #ff0000;">"true"</span> <span style="color: #000066;">cheesefilled</span>=<span style="color: #ff0000;">"false"</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"1765"</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"brat buns"</span> <span style="color: #000066;">quantity</span>=<span style="color: #ff0000;">"2"</span> <span style="color: #000066;">warmed</span>=<span style="color: #ff0000;">"true"</span> <span style="color: #000066;">toasted</span>=<span style="color: #ff0000;">"false"</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>The reason I don&#8217;t list these as the primary contention against JSON, even though that&#8217;s what the advocates would probably have written?  Simple.  Those representations don&#8217;t match, when treated as a representation of an object, the order I started out with.  They are close, yes, and they convey the same information, but the syntax is entirely different, and therefore the parsing is not only more complex, especially when it comes to converting the XML back into an objectm, not to mention that you start to lose the &#8220;human readable&#8221;-ness of the document by trying to cram it into less and less space.</p>
<p>Furthermore, with JSON, exporting objects, arrays, or both, is extremely easy to do &#8212; in PHP, for instance, it&#8217;s actually native since version 5.2, and <a title="JSON - The Fat-Free Alternative to XML" href="http://www.json.org" target="_blank">json.org</a> has plenty of easy-to-use implementations in most languages in common use.</p>
<p>In order to arrive at the XML I chose as a contender, I did a <a href="http://www.lmgtfy.com/?q=array+to+XML+php" target="_blank">google search for &#8220;array to XML PHP&#8221;</a> and checked the <a href="http://snipplr.com/view/3491/convert-php-array-to-xml-or-simple-xml-object-if-you-wish/" target="_blank">top result</a>, which was a function (for some unknown reason static-inside-a-class-as-the-only-member, maybe written by a namespace-nazi?) that seemed to do a more-or-less standardized conversion.  Now, again, we could argue all day about whether or not that is even a worthy implementation, but before that argument starts let me squash it by saying this: whether or not any of those syntaxes is correct or not is less important than the simple point that any and all of them are technically correct.</p>
<p>Semantics aside, all of those XML versions of the same &#8220;object&#8221; are valid and well-formed XML documents, and they, depending on your method of &#8220;serialization&#8221; into and out of XML, all describe the same order.  And that, ladies and gentlemen, is a problem I consider to be worst of all.  Which one of those is right?  Is it the smallest, the one that&#8217;s most clear, the one that is most loyal to the original order object?</p>
<p>Because of XML&#8217;s loose specification, which is a good thing in cases where XML is appropriate, there isn&#8217;t really a consistent way to represent these objects as XML that everyone agrees on.  Some people, as in the last example, would put everything into an attribute=value pair, while many automated methods for de/serialization would use almost no attributes, instead favoring raw tags.</p>
<p>Before this gets too far away from me, let me draw it to a close.  Because of the standard&#8217;s, if you&#8217;ll pardon the sub-pun, lack of standardization, I propose we stop, for the love of all that is good and pure, using XML to represent every single object and data-fragment we come across.  It&#8217;s time to let go.  There are just too many ways to do it, and we&#8217;re <i>running out of patience&#8230;</i></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dereleased.com/2009/09/30/xml-is-like-violence/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

