<?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>Dan Polant :: Web Interaction Designer &#187; object oriented</title>
	<atom:link href="http://danpolant.com/tag/object-oriented/feed/" rel="self" type="application/rss+xml" />
	<link>http://danpolant.com</link>
	<description></description>
	<lastBuildDate>Fri, 04 May 2012 04:24:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Object orientation and natural language</title>
		<link>http://danpolant.com/object-orientation-and-natural-language/</link>
		<comments>http://danpolant.com/object-orientation-and-natural-language/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 08:25:57 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Critical Writing]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[object oriented]]></category>

		<guid isPermaLink="false">http://danpolant.com/?p=117</guid>
		<description><![CDATA[If I had to pick one word that said the most about information processing and presentation, I would choose &#8220;abstraction.&#8221; Its Latin roots give it a derivative meaning of &#8220;to drag out;&#8221; it might be more useful to think of it as meaning &#8220;to pull out&#8221; or &#8220;to distill.&#8221; Often we think of abstraction as [...]]]></description>
			<content:encoded><![CDATA[<p>If I had to pick one word that said the most about information processing and presentation, I would choose &#8220;abstraction.&#8221; Its Latin roots give it a derivative meaning of &#8220;to drag out;&#8221; it might be more useful to think of it as meaning &#8220;to pull out&#8221; or &#8220;to distill.&#8221; Often we think of abstraction as an ability that humans have and other animals don&#8217;t. A metaphor is an example of an abstraction, being a shorter linguistic string pulled out of and derived to represent an invariably complex situation.</p>
<div id="attachment_130" class="wp-caption alignright" style="width: 281px"><img class="size-full wp-image-130 " title="logic_gates_1" src="http://danpolant.com/wp-content/uploads/2009/10/logic_gates_1.jpg" alt="A NAND logic gate. Computer circuits are set up to only care about the input and output of these constructs, and don't get involved in the inner workings" width="271" height="241" /><p class="wp-caption-text">A NAND logic gate. Computer circuits are set up to only care about the input and output of these constructs, and don&#39;t get involved in the inner workings</p></div>
<p>Abstraction also applies to digital technology. A common structure inside computers is a set of transistors set up to process two binary inputs and create an output based on the binary value of each input. We call this thing &#8220;logic gate.&#8221; We can talk about logic gates without talking about what they&#8217;re made out of. We talk this way when what is inside doesn&#8217;t matter.</p>
<h3>Computers are like us</h3>
<p>Computers make abstractions the same way we do. A binary adding circuit has no interaction with the transistors inside a logic gate. It knows inputs and outputs only. An adding circuit would only be affected by changes within the logic gate if those changes altered the way that inputs and outputs resolved. It is easy and extremely useful to set up a machine in a way that makes use of the concept of abstraction.</p>
<p>In most cases, it is worthwhile to also set up computer programs as sets of interacting abstractions. Lets stop for a moment: why is this the case? It has to do with the limited capacity of human memory and mental processing capabilities. Back to the hardware: when computer scientists talk about logic gates, brilliant as they are, they do not have the mental resources to conceptualize the path of electricity through a logic gate every time they wish to talk about the interaction between logic gates. By assigning meaning, language eliminates redundancy. Abstractions make complex systems understandable to human beings.</p>
<h3>$spot -> sit() !!!</h3>
<p>Object orientation is a programming practice that brings computer language very close to human language. Human languages have evolved over millions of years, and represent very closely our ideal way of affecting our environment. If you own a dog, take a minute to imagine it sitting in front of you. Your goal is to make the dog sit down, then lie down. Its name is Spot. You&#8217;ve trained your dog to respond correctly to &#8220;Spot sit&#8221; and &#8220;Spot lie down.&#8221; You say, &#8220;Spot, sit.&#8221; He sits. &#8220;Spot, lie down.&#8221; He lies down.</p>
<p>&#8220;Good boy Spot!&#8221; Caesar Milan would be proud.</p>
<div id="attachment_138" class="wp-caption alignright" style="width: 297px"><img src="http://danpolant.com/wp-content/uploads/2009/10/dogs.jpg" alt="$ripple -&gt; sit();" title="dogs" width="287" height="453" class="size-full wp-image-138" /><p class="wp-caption-text">$ripple -> sit();</p></div>
<p>Object orientation (OO) is a straight-forward, dominant, command oriented approach to getting what you want from computers. In OO you would say (php style):</p>
<p><code>$spot-&gt;sit()</code> and then <code>$spot-&gt;lie_down()</code></p>
<p>Now that&#8217;s calm, assertive leadership! First of course, you have to define <code>$spot</code> as an instantiation of <code>class dog</code>, sort of like training him. Dogs are like computers in that they will do what you want if you command them directly in language that they understand.</p>
<p>But computers are much more tractable even than dogs. Software will do what you want even if you don&#8217;t use an object oriented demeanor. So why do things this way? Sometimes its just not practical. But the rule of thumb is to use object orientation if it eliminates enough redundancy to make up for the extra code spent defining the objects. And it doesn&#8217;t always do this.</p>
<p>Normal WordPress, for example, isn&#8217;t very object oriented. We don&#8217;t say <code>$post-&gt;publish()</code>, but rather something like <code>wp_insert_post(array('title' =&gt; 'whatever'))</code>.  This makes sense because WordPress posts don&#8217;t really do very much. They make more sense as arrays, because their only real value is their properties. WordPress posts are passive, not assertive.  They are always accusative direct objects of functions, like <code>wp_insert_post()</code>, or functions that load data from the database and create a <code>$post</code> array to be further manipulated.</p>
<h3>Verbs and nouns</h3>
<p>The language around WordPress posts is heavily verb focused, very much like Latin. My Latin professor used to remind us that in Latin &#8220;the verb was the train that pulled the freight of the sentence.&#8221; In function-oriented code, all power to change the state of the software rests within the function, and variables and arrays are just the values required variously within. Functions are wonderful abstractions of sequential operations. An ancient Roman, or the Pope would &#8220;get&#8221; functions pretty quickly.</p>
<p>OO treats the noun as the engine of affect. Fundamentally, the difference between OO and not-OO is the difference between the passive and the active voice. <code>$spot-&gt;sit()</code> resolves to &#8220;Spot sits,&#8221; whereas <code>sit($spot)</code> resolves to &#8220;Spot is made to sit&#8221;, or maybe &#8220;sitting happens and Spot is the sitter.&#8221; In English, the active voice comes across as more direct and less verbose. In Latin, it doesn&#8217;t matter and in fact the passive voice is often preferred. Is this simply a difference of taste?</p>
<h3>Transitivity</h3>
<p>What does it mean for an application to be &#8220;object oriented?&#8221; Lets think about Buddypress as opposed to standard WordPress. Buddypress has constructs like &#8220;group,&#8221; &#8220;friend,&#8221; &#8220;group member,&#8221; &#8220;message,&#8221; and anything else you might find on sites like facebook.com and myspace.com. Many of these constructs have transitive relationships, meaning that they affect other objects by means of a verb. For example, messages and group members all reference a person. Here is the object oriented literal phrasing of one such transitive interaction:</p>
<blockquote><p>&#8220;Person A prepares a message. The content is &#8216;hello,&#8217; and the recipient is Person B. Then Person A sends the message.&#8221;</p></blockquote>
<p>And its non object oriented phrasing:</p>
<blockquote><p>&#8220;message sending, a process in which the sender is denoted by being the first of two nouns separated by the preposition &#8220;between,&#8221; and in which the content of the message is denoted by a preceding &#8220;regarding,&#8221; occurs between Person A and Person B regarding &#8220;hello.&#8221;</p></blockquote>
<p>Functions have a fatal flaw &#8211; variables don&#8217;t have a &#8220;case&#8221; to describe what they do in a function. For example, the verb &#8220;message send&#8221; would be considered a dative verb, because it has takes a nominative (the sender), an accusative (the message) and an indirect object (the recipient). In Latin, these nouns are construed in their appropriate cases to signify this. But in a computer program, such abstractions don&#8217;t exist.</p>
<h3>Object orientation disambiguates</h3>
<p>Object oriented programming keeps things simple. Instead of trying to describe an entire process as happening in one function, objects provide a way to describe processes as &#8220;things doing things,&#8221; and changing their own properties as well as the properties of their direct and indirect objects. Object oriented code essentially self-documents, because variable values exist connected with their roles, not simply listed as parameters of a function. Take the following example from bp-messages.php:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$message</span> = <span class="kw2">new</span> BP_Messages_Message;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$message</span>-&gt;<span class="me1">thread_id</span> = <span class="re0">$thread_id</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$message</span>-&gt;<span class="me1">sender_id</span> = <span class="re0">$sender_id</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$message</span>-&gt;<span class="me1">subject</span> = <span class="re0">$subject</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$message</span>-&gt;<span class="me1">message</span> = <span class="re0">$content</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$message</span>-&gt;<span class="me1">date_sent</span> = <span class="re0">$date_sent</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/* If we have a thread ID, use the existing recipients, otherwise use the recipients passed */</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span> <span class="re0">$thread_id</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$thread</span> = <span class="kw2">new</span> BP_Messages_Thread<span class="br0">&#40;</span><span class="re0">$thread_id</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$message</span>-&gt;<span class="me1">recipients</span> = <span class="re0">$thread</span>-&gt;<span class="me1">get_recipients</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>&#8230;<span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$message</span>-&gt;<span class="me1">send</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>With object orientation, you can signify variable roles inline. You can only do this with functions to a limited extent &#8211; and specifically not when you are passing two variables of the same type (like two people) as arguments. <code>function send_message('p1', 'p2', 'hello')</code> does not intrinsically signify a transitive direction. In the realm of spoken languages, English primarily uses word position and Latin primarily case endings to disambiguate these situations. Object orientation disambiguates by pairing each variable value with a property key the meaning of which signifies the value&#8217;s role in the application.</p>
]]></content:encoded>
			<wfw:commentRss>http://danpolant.com/object-orientation-and-natural-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

