<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: some thoughts on php and oop</title>
	<atom:link href="http://wonkabar.org/2010/02/03/some-thoughts-on-php-and-oop/feed/" rel="self" type="application/rss+xml" />
	<link>http://wonkabar.org/2010/02/03/some-thoughts-on-php-and-oop/</link>
	<description>linux, databases, cartoons and cornflakes</description>
	<lastBuildDate>Fri, 09 Jul 2010 19:46:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: James</title>
		<link>http://wonkabar.org/2010/02/03/some-thoughts-on-php-and-oop/comment-page-1/#comment-51208</link>
		<dc:creator>James</dc:creator>
		<pubDate>Tue, 09 Feb 2010 17:09:53 +0000</pubDate>
		<guid isPermaLink="false">http://wonkabar.org/?p=1150#comment-51208</guid>
		<description>You might want to read this post by Ned Batchelder where he argues that exceptions are better.  It assumes the reader already understands the mechanics of exceptions and wants to understand why they are useful.

http://nedbatchelder.com/text/exceptions-vs-status.html</description>
		<content:encoded><![CDATA[<p>You might want to read this post by Ned Batchelder where he argues that exceptions are better.  It assumes the reader already understands the mechanics of exceptions and wants to understand why they are useful.</p>
<p><a href="http://nedbatchelder.com/text/exceptions-vs-status.html" rel="nofollow">http://nedbatchelder.com/text/exceptions-vs-status.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ant</title>
		<link>http://wonkabar.org/2010/02/03/some-thoughts-on-php-and-oop/comment-page-1/#comment-51206</link>
		<dc:creator>ant</dc:creator>
		<pubDate>Mon, 08 Feb 2010 22:37:28 +0000</pubDate>
		<guid isPermaLink="false">http://wonkabar.org/?p=1150#comment-51206</guid>
		<description>+1 for xdebug.

There&#039;s also &lt;a href=&quot;http://forums.gentoo.org/viewtopic-t-813536.html&quot; rel=&quot;nofollow&quot;&gt;gprof2dot&lt;/a&gt; as an alternative to kcachegrind that gives you its main functionality (pretty tree graphs of where all your page load time is coming from).</description>
		<content:encoded><![CDATA[<p>+1 for xdebug.</p>
<p>There's also <a href="http://forums.gentoo.org/viewtopic-t-813536.html" rel="nofollow">gprof2dot</a> as an alternative to kcachegrind that gives you its main functionality (pretty tree graphs of where all your page load time is coming from).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ewoud Kohl van Wijngaarden</title>
		<link>http://wonkabar.org/2010/02/03/some-thoughts-on-php-and-oop/comment-page-1/#comment-51186</link>
		<dc:creator>Ewoud Kohl van Wijngaarden</dc:creator>
		<pubDate>Fri, 05 Feb 2010 04:39:33 +0000</pubDate>
		<guid isPermaLink="false">http://wonkabar.org/?p=1150#comment-51186</guid>
		<description>Have you tried &lt;a href=&quot;http://xdebug.org&quot; rel=&quot;nofollow&quot;&gt;xdebug&lt;/a&gt;? It can be used together with for example &lt;a href=&quot;http://kcachegrind.sourceforge.net/html/Home.html&quot; rel=&quot;nofollow&quot;&gt;kcachegrind&lt;/a&gt; to profile your PHP application.</description>
		<content:encoded><![CDATA[<p>Have you tried <a href="http://xdebug.org" rel="nofollow">xdebug</a>? It can be used together with for example <a href="http://kcachegrind.sourceforge.net/html/Home.html" rel="nofollow">kcachegrind</a> to profile your PHP application.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andrew</title>
		<link>http://wonkabar.org/2010/02/03/some-thoughts-on-php-and-oop/comment-page-1/#comment-51174</link>
		<dc:creator>andrew</dc:creator>
		<pubDate>Thu, 04 Feb 2010 08:24:45 +0000</pubDate>
		<guid isPermaLink="false">http://wonkabar.org/?p=1150#comment-51174</guid>
		<description>&lt;blockquote&gt;I thought it made sense to just extend the PortageTree class on PortageCategory&lt;/blockquote&gt;
You might want to recheck the Object Oriented Design rules. A Category &lt;strong&gt;is-not-a&lt;/strong&gt; Tree, unless you are trying to say that a Category is interchangeable with the root node of the portage tree which I didn&#039;t think was the case. You&#039;re looking for &lt;em&gt;Composition&lt;/em&gt;, a Category &lt;strong&gt;has-a&lt;/strong&gt; owning tree, but it is not actually a tree itself. The singleton approach is good enough, though if you want to include overlays (sunrise?) in it then you may want to allow multiple &lt;code&gt;PortageTree&lt;/code&gt; instances for each overlay.

The main OOD/OOP class design rules I remember are:
Classes represent things. A File, a Person, a Button.
A class must do one thing, and only one thing. All functions should be aligned towards one purpose (The rule of cohesion). eg. A Database class should only operate on the contents of a database, it should not include public functions to open or delete files, network connections, calculate taxes, etc.
A class can be a &lt;em&gt;more specific&lt;/em&gt; type of something else (Inheritance, the &lt;strong&gt;is-a&lt;/strong&gt; relationship). For example, an IceCreamTruck &lt;strong&gt;is-a&lt;/strong&gt; Truck &lt;strong&gt;is-a&lt;/strong&gt; Vehicle.
A class can be made from &quot;parts&quot;, that is, member variables which reference other objects (Composition, the &lt;strong&gt;has-a&lt;/strong&gt; relationship). Example: A Truck &lt;strong&gt;has-a&lt;/strong&gt; Wheel, but it is &lt;em&gt;not&lt;/em&gt; a Wheel itself.

You need to be careful that you don&#039;t try to use inheritance as a shortcut, even if that means rewriting similar code, as you&#039;ll usually just end up making the code more tightly coupled (inter-dependent) and that makes it harder to fix or improve later on.

---
For exceptions, the jury is still out on that. Usual arguments are that exceptions make code visually leaner since you don&#039;t have to use lots of &quot;&lt;code&gt;if (errCode != 0) return errCode;&lt;/code&gt;&quot; things, however, the &quot;try/catch&quot; structure is often more ugly. Some people claim that it stops the error recovery from obscuring the normal behaviour when reading code but others claim that it makes it too easy to ignore error cases, allowing them to propagate and cause a crash [the same is said of forgotten error code tests though]. It can also enable you to use multiple functions that may fail in a single statement without intermediate variables and error testing and give a minor performance benefit in some cases. Generally, the best you can do is use the convention of the language; if the language doesn&#039;t have much of a convention then just use the same style that everyone else is using on the project; if it&#039;s your own project then you can do it whichever way you want. Most of it is just opinion.</description>
		<content:encoded><![CDATA[<blockquote><p>I thought it made sense to just extend the PortageTree class on PortageCategory</p></blockquote>
<p>You might want to recheck the Object Oriented Design rules. A Category <strong>is-not-a</strong> Tree, unless you are trying to say that a Category is interchangeable with the root node of the portage tree which I didn't think was the case. You're looking for <em>Composition</em>, a Category <strong>has-a</strong> owning tree, but it is not actually a tree itself. The singleton approach is good enough, though if you want to include overlays (sunrise?) in it then you may want to allow multiple <code>PortageTree</code> instances for each overlay.</p>
<p>The main OOD/OOP class design rules I remember are:<br />
Classes represent things. A File, a Person, a Button.<br />
A class must do one thing, and only one thing. All functions should be aligned towards one purpose (The rule of cohesion). eg. A Database class should only operate on the contents of a database, it should not include public functions to open or delete files, network connections, calculate taxes, etc.<br />
A class can be a <em>more specific</em> type of something else (Inheritance, the <strong>is-a</strong> relationship). For example, an IceCreamTruck <strong>is-a</strong> Truck <strong>is-a</strong> Vehicle.<br />
A class can be made from "parts", that is, member variables which reference other objects (Composition, the <strong>has-a</strong> relationship). Example: A Truck <strong>has-a</strong> Wheel, but it is <em>not</em> a Wheel itself.</p>
<p>You need to be careful that you don't try to use inheritance as a shortcut, even if that means rewriting similar code, as you'll usually just end up making the code more tightly coupled (inter-dependent) and that makes it harder to fix or improve later on.</p>
<p>---<br />
For exceptions, the jury is still out on that. Usual arguments are that exceptions make code visually leaner since you don't have to use lots of "<code>if (errCode != 0) return errCode;</code>" things, however, the "try/catch" structure is often more ugly. Some people claim that it stops the error recovery from obscuring the normal behaviour when reading code but others claim that it makes it too easy to ignore error cases, allowing them to propagate and cause a crash [the same is said of forgotten error code tests though]. It can also enable you to use multiple functions that may fail in a single statement without intermediate variables and error testing and give a minor performance benefit in some cases. Generally, the best you can do is use the convention of the language; if the language doesn't have much of a convention then just use the same style that everyone else is using on the project; if it's your own project then you can do it whichever way you want. Most of it is just opinion.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Bowling</title>
		<link>http://wonkabar.org/2010/02/03/some-thoughts-on-php-and-oop/comment-page-1/#comment-51166</link>
		<dc:creator>Kevin Bowling</dc:creator>
		<pubDate>Wed, 03 Feb 2010 20:24:12 +0000</pubDate>
		<guid isPermaLink="false">http://wonkabar.org/?p=1150#comment-51166</guid>
		<description>For learning good OOP practice, Java is an excellent language even if you don&#039;t plan on using it in practice.  &quot;Big Java&quot; by Cay Horstmann is a decent book w/o being too dry, and if you have previous programming experience you will breeze through it.

Bjarne Stroustrup also has a book out similar in scope by using C++.  I haven&#039;t purchased it yet, but it probably goes into more depth albeit more dense and difficult due to C++.</description>
		<content:encoded><![CDATA[<p>For learning good OOP practice, Java is an excellent language even if you don't plan on using it in practice.  "Big Java" by Cay Horstmann is a decent book w/o being too dry, and if you have previous programming experience you will breeze through it.</p>
<p>Bjarne Stroustrup also has a book out similar in scope by using C++.  I haven't purchased it yet, but it probably goes into more depth albeit more dense and difficult due to C++.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Armando Di Cianno</title>
		<link>http://wonkabar.org/2010/02/03/some-thoughts-on-php-and-oop/comment-page-1/#comment-51163</link>
		<dc:creator>Armando Di Cianno</dc:creator>
		<pubDate>Wed, 03 Feb 2010 19:38:11 +0000</pubDate>
		<guid isPermaLink="false">http://wonkabar.org/?p=1150#comment-51163</guid>
		<description>There&#039;s two schools of thought with regard to exceptions.  The first is that exceptions should only be for, well, /exceptional/ cases.  The second is that exceptions are very handy to use for flow control (wrt jumping back up the stack).

I recall trying to explain this to someone at work a while back.  The analogy I used was that a person driving a car into a wall would be a normal error code, but a unicorn driving a car at all would be an exception.

I&#039;ve been on both sides of the fence with this.  Lately, especially since having learned more Python, I find that it is really up to the language and culture around it to decide what an exception is used for.  For Python, it seems Pythonic to attempt an operation first, whilst catching exceptions, rather than to lay down a number of state checks before attempting an operation, for example.

2¢</description>
		<content:encoded><![CDATA[<p>There's two schools of thought with regard to exceptions.  The first is that exceptions should only be for, well, /exceptional/ cases.  The second is that exceptions are very handy to use for flow control (wrt jumping back up the stack).</p>
<p>I recall trying to explain this to someone at work a while back.  The analogy I used was that a person driving a car into a wall would be a normal error code, but a unicorn driving a car at all would be an exception.</p>
<p>I've been on both sides of the fence with this.  Lately, especially since having learned more Python, I find that it is really up to the language and culture around it to decide what an exception is used for.  For Python, it seems Pythonic to attempt an operation first, whilst catching exceptions, rather than to lay down a number of state checks before attempting an operation, for example.</p>
<p>2¢</p>
]]></content:encoded>
	</item>
</channel>
</rss>
