<?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>Yet another blog about PHP, HTML and CSS &#187; Design Techniques</title>
	<atom:link href="http://blog.pepa.info/php-html-css/category/design-techniques/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pepa.info</link>
	<description>Petr 'PePa' Pavel</description>
	<lastBuildDate>Thu, 19 Aug 2010 18:17:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Calculating time difference in months as a decimal number</title>
		<link>http://blog.pepa.info/php-html-css/design-techniques/calculating-time-difference-in-months-as-a-decimal-number/</link>
		<comments>http://blog.pepa.info/php-html-css/design-techniques/calculating-time-difference-in-months-as-a-decimal-number/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 20:54:21 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[Design Techniques]]></category>
		<category><![CDATA[Programming Techniques]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/?p=44</guid>
		<description><![CDATA[There&#8217;s a number of functions out there for calculating the length of time in months but they only provide integer results. MySQL can do it too, for instance. But what if you need to get a precise number? 2008-11-15 minus 2008-10-01 can&#8217;t be one if you&#8217;re calculating rent. It must be 1.466&#8230; function monthCount&#40;$start, $end&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a number of functions out there for calculating the length of time in months but they only provide integer results. MySQL can do it too, for instance. But what if you need to get a precise number?</p>
<p>2008-11-15 minus 2008-10-01 can&#8217;t be one if you&#8217;re calculating rent. It must be 1.466&#8230;</p>
<p><span id="more-44"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> monthCount<span class="br0">&#40;</span><span class="re0">$start</span>, <span class="re0">$end</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="re0">$startYear</span>, <span class="re0">$startMonth</span>, <span class="re0">$startDay</span><span class="br0">&#41;</span> = <a href="http://www.php.net/split"><span class="kw3">split</span></a><span class="br0">&#40;</span><span class="st0">&#8216;-&#8217;</span>, <span class="re0">$start</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="re0">$endYear</span>, <span class="re0">$endMonth</span>, <span class="re0">$endDay</span><span class="br0">&#41;</span> = <a href="http://www.php.net/split"><span class="kw3">split</span></a><span class="br0">&#40;</span><span class="st0">&#8216;-&#8217;</span>, <span class="re0">$end</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="re0">$startMonthCount</span> =</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#40;</span><span class="re0">$startYear</span> * <span class="nu0">12</span><span class="br0">&#41;</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// number of months since the beginning of our calendar</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$startMonth</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// month number</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#40;</span> <span class="br0">&#40;</span><span class="re0">$startDay</span> &#8211; <span class="nu0">1</span><span class="br0">&#41;</span> / <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;t&quot;</span>, <a href="http://www.php.net/strtotime"><span class="kw3">strtotime</span></a><span class="br0">&#40;</span><span class="re0">$start</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// day number divided by the number of days in that month</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$endMonthCount</span> = <span class="br0">&#40;</span><span class="re0">$endYear</span> * <span class="nu0">12</span><span class="br0">&#41;</span> + <span class="re0">$endMonth</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#40;</span> <span class="br0">&#40;</span><span class="re0">$endDay</span> &#8211; <span class="nu0">1</span><span class="br0">&#41;</span> / <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;t&quot;</span>, <a href="http://www.php.net/strtotime"><span class="kw3">strtotime</span></a><span class="br0">&#40;</span><span class="re0">$end</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="re0">$endMonthCount</span> &#8211; <span class="re0">$startMonthCount</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Note: end date is not inclusive.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/design-techniques/calculating-time-difference-in-months-as-a-decimal-number/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>eXtreme Programming eXplained: Embrace Change</title>
		<link>http://blog.pepa.info/php-html-css/literature/extreme-programming-explained-embrace-change/</link>
		<comments>http://blog.pepa.info/php-html-css/literature/extreme-programming-explained-embrace-change/#comments</comments>
		<pubDate>Fri, 02 Mar 2007 10:10:12 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[Design Techniques]]></category>
		<category><![CDATA[Literature]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/2007/03/literature/extreme-programming-explained-embrace-change/</guid>
		<description><![CDATA[Delivery delays, changes in specification that should have been known beforehand, bad and outdated documentation, team-mates who cause more damage than good. These things (among many others) make programming difficult to like. The ol&#8217; good way is to think first, then do the job, deploy it and go have a break. The first paragraph describes [...]]]></description>
			<content:encoded><![CDATA[<p>Delivery delays, changes in specification that should have been known beforehand, bad and outdated documentation, team-mates who cause more damage than good.<br />
These things (among many others) make programming difficult to like.</p>
<p><span id="more-4"></span>The ol&#8217; good way is to think first, then do the job, deploy it and go have a break. The first paragraph describes what you get if you still believe in the old good way.</p>
<p><span style="font-weight: bold">Extreme Programming Explained: Embrace Change</span> by Kent Beck, <a target="_blank" href="http://www.amazon.com/Extreme-Programming-Explained-Embrace-Change/dp/0201616416">ISBN: 0201616416</a>, Addison-Wesley Professional (Czech translation: <span class="link">ExtrÃ©mnÃ­ programovÃ¡nÃ­</span>, <a target="_blank" href="http://interval.inshop.cz/inshop/scripts/detail.asp?kat=181"><font class="black">ISBN: 80-247-0300-9</font></a>, Grada Publishing a.s.)</p>
<p>Reading this book may help you to change your world view &#8211; at least from the programming point. There always will be a change so why won&#8217;t you accept it and do everything possible to cut its cost. Not having experience with XP as such I cannot advocate for adopting it totally. However, reading the book did change me:</p>
<ul>
<li>I no longer think that I can predict changes</li>
<li>I organize projects into phases, deploy as soon as possible and add functionality incrementally</li>
<li>I don&#8217;t blame users for not being able to give me good specs until they get their hands on the finished software (it&#8217;s like blaming rain for being wet)</li>
<li>I write my code so that a kid can understand it (i.e. me after two months)</li>
<li>I don&#8217;t worry about rewriting half of my application next week &#8211; I take it into account when giving quotation in the first place (multiply it by two)</li>
<li>When I get specs (the first version) I&#8217;m not surprised that they&#8217;re worthless. Hey, it&#8217;s just something to start with. Just don&#8217;t forget to take it into account when giving quotation. (again: * 2)</li>
<li>Speaking about quotations: I write the specs not the customer. The customer sends me his ideas (he calls it specs, of course), I rewrite it into specs and have it confirmed. Repeat {} until (confirmed == true); Then I give the price.</li>
<li>I know that never-ending projects are ok. There&#8217;s no &#8220;we&#8217;re done let&#8217;s go home&#8221;. Plan your time so that you still have some after the project&#8217;s deployed. (That&#8217;s not the deadline, mind you.)</li>
</ul>
<p>Now that you know how clever I am &#8211; go get the book from local library and be that way too :-)</p>
<p><strong>Question 1</strong></p>
<p>Have you ever tried programming in a pair? What transition were you going through after you started doing so? Did you like it right from the beginning? Are you glad you returned to working alone?</p>
<p><strong>Question 2</strong></p>
<p>Do you think programming in a pair can work over <a target="_blank" href="http://share.skype.com/in/102/268276">Skype</a> + shared desktop? A webcam comes handy? Any experience?</p>
<p style="font-weight: bold">Question 3</p>
<p>Do you know of any literature on how to give quotations? Let&#8217;s face it &#8211; it&#8217;s a major part of our work and a bad quotation can turn a project into hell.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/literature/extreme-programming-explained-embrace-change/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Conversation with Erich Gamma</title>
		<link>http://blog.pepa.info/php-html-css/design-techniques/a-conversation-with-erich-gamma/</link>
		<comments>http://blog.pepa.info/php-html-css/design-techniques/a-conversation-with-erich-gamma/#comments</comments>
		<pubDate>Fri, 03 Nov 2006 15:16:19 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[Design Techniques]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/2006/11/design-techniques/a-conversation-with-erich-gamma/</guid>
		<description><![CDATA[When searching for more information on design patterns I found a series of interviews with Erich Gamma, co-author of the book, Design Patterns: Elements of Reusable Object-Oriented Software, on Artima Software website. How to Use Design Patterns Erich Gamma on Flexibility and Reuse Design Principles from Design Patterns Patterns and Practice Eclipse&#8217;s Culture of Shipping [...]]]></description>
			<content:encoded><![CDATA[<p>When searching for more information on design patterns I found a series of interviews with Erich Gamma, co-author of the book, <a target="_blank" href="http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612">Design Patterns: Elements of Reusable Object-Oriented Software</a>, on <a target="_blank" href="http://www.artima.com/">Artima Software website</a>.<span id="more-6"></span></p>
<ol>
<li><a target="_blank" href="http://www.artima.com/lejava/articles/gammadpP.html">How to Use Design Patterns</a></li>
<li><a target="_blank" href="http://www.artima.com/lejava/articles/reuseP.html">Erich Gamma on Flexibility and Reuse</a></li>
<li><a target="_blank" href="http://www.artima.com/lejava/articles/designprinciplesP.html">Design Principles from Design Patterns</a></li>
<li><a target="_blank" href="http://www.artima.com/lejava/articles/patterns_practiceP.html">Patterns and Practice</a></li>
<li><a target="_blank" href="http://www.artima.com/lejava/articles/eclipse_cultureP.html"><span class="ts">Eclipse&#8217;s Culture of Shipping</span></a></li>
</ol>
<p>At the end of the fifth part the author promises next one to come on July 11th but I failed to find any.</p>
<p><strong>Question<br />
</strong></p>
<p>How do you work with design patterns? Do you go back to your favourite book and refresh your memory from time to time? Do you work up your own patterns? When you have a situation you need to solve do you go googling to see if there already is a pattern for it?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/design-techniques/a-conversation-with-erich-gamma/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Refactoring: Improving the Design of Existing Code</title>
		<link>http://blog.pepa.info/php-html-css/literature/refactoring-improving-the-design-of-existing-code/</link>
		<comments>http://blog.pepa.info/php-html-css/literature/refactoring-improving-the-design-of-existing-code/#comments</comments>
		<pubDate>Tue, 12 Sep 2006 09:10:21 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[Design Techniques]]></category>
		<category><![CDATA[Literature]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/2006/09/literature/refactoring-improving-the-design-of-existing-code/</guid>
		<description><![CDATA[When thinking about what makes an effective programmer I realized that as with any advanced skill you learn what are the best techniques to do something and you end up using them together as an atomic procedure. You no longer think of the best way to get information from a form and save it into [...]]]></description>
			<content:encoded><![CDATA[<p>When thinking about what makes an effective programmer I realized that as with any advanced skill you learn what are the best techniques to do something and you end up using them together as an atomic procedure. You no longer think of the best way to get information from a form and save it into database. You&#8217;ve brushed it up already and now you use it without thinking twice. You surely have a set of functions / objects to do it but that&#8217;s not my point. I&#8217;m talking about the patterns, not their implementation.<br />
So how do I take a short cut so that I don&#8217;t have to waste my time with inventing my own patterns. I answered to myself: RTFM :-)</p>
<p><span id="more-3"></span></p>
<p><font class="black">That&#8217;s how I found <a target="_blank" href="http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29">design patterns</a> and <a target="_blank" href="http://en.wikipedia.org/wiki/Design_Patterns"><strong>Design Patterns: Elements of Reusable Object-Oriented Software</strong></a> by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (</font><a target="_blank" href="http://www.amazon.com/dp/0201633612">ISBN: 0201633612</a>, Addison-Wesley Professional<font class="black">). </font></p>
<p><font class="black">Surprisingly enough it wasn&#8217;t and is not going to be translated by major Czech publisher of computer related literature Grada. Costs for getting it from Amazon.com are discouraging so what now. <em>(see Update below)</em><br />
</font></p>
<p><font class="black"><strong>Refactoring: Improving the Design of Existing Code</strong> by Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts (</font><font class="black"><a target="_blank" href="http://www.amazon.com/dp/0201485672">ISBN: 0201485672</a>, </font><font class="black">Addison-Wesley Professional).</font></p>
<p><font class="black">This book was </font><font class="black">excellently translated by VladimÃ­r Lahoda as </font><font class="black">Refaktoring: ZlepÅ¡enÃ­ existujÃ­cÃ­ho kÃ³du (<a target="_blank" href="http://www.grada.cz/katalog/kniha/refaktoring/">ISBN: 80-247-0299-1</a>, Grada Publishing a.s.</font>) so I was able to get it from a local library for free. <a target="_blank" href="http://en.wikipedia.org/wiki/Refactoring">Refactoring</a> in general may not be always related to what I set out to look for however, this book is full of design patterns indeed.</p>
<p>You learn here how to proceed when you want to change your code without changing the program&#8217;s behaviour. You actually get a cook book of common design problems and step-by-step instructions how to solve them. Please note that it&#8217;s about design &#8211; not implementation or performance problems.</p>
<p>Here&#8217;s what I think this books brings apart from what&#8217;s its obvious goal.</p>
<p><strong><a target="_blank" href="http://en.wikipedia.org/wiki/Code_smell">Code Smells</a> Hints</strong></p>
<p>Because it lists problematic code and solutions to it you get to learn what a problematic code is and why.</p>
<p><strong>You learn OOP as you read it</strong></p>
<p>My blog is meant to be about PHP and this book uses Java for its examples. I don&#8217;t think it matters. The OOP principles behind it are the same.</p>
<p><strong>Gives you arguments</strong></p>
<p>If you ever had to lead a team you know what it means to know the right way but to miss the arguments to support your point of view. You know it but you&#8217;re unable to convince the rest of the team. Now you can use parts of the book.</p>
<p><strong>Question 1</strong></p>
<p>Do you <strong>re</strong>write your code to make it easier to read? Or do you do your best when you write it at the first time and when you need to add more features you just try to hack it as nicely as possible? What are your criteria for a project that is worth refactoring?</p>
<p><strong>Question 2</strong></p>
<p>How do you deal with refactoring from the project management point of view? If you are the boss then how do you promote refactoring &#8211; or how do you keep it within reasonable bounds? If you are the programmer then how do you persuade your boss that refactoring is crucial for your application in the long run? Maybe you don&#8217;t tell him at all and steal time for it like Robin Hood :-)</p>
<p><em>Update</em>:<br />
I just learnt that Czech translation of Design Patterns exists: <strong>NÃ¡vrh programÅ¯ pomocÃ­ vzorÅ¯</strong> (<a target="_blank" href="http://interval.inshop.cz/inshop/scripts/detail.asp?itemid=289">ISBN: 80-247-0302-5</a>, GRADA Publishing<font class="black"> a.s.)</font>. It is sold out though, and Grada doesn&#8217;t plan any reprints.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/literature/refactoring-improving-the-design-of-existing-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Welcome</title>
		<link>http://blog.pepa.info/php-html-css/literature/welcome/</link>
		<comments>http://blog.pepa.info/php-html-css/literature/welcome/#comments</comments>
		<pubDate>Sun, 10 Sep 2006 16:34:01 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[Design Techniques]]></category>
		<category><![CDATA[Literature]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/2006/09/uncategorized/welcome/</guid>
		<description><![CDATA[The reason why I have ever started this blog was to share good ideas with you, the accidental visitor. And hopefully to learn new things through your comments. I&#8217;m working on a post about a book I read (Refactoring: Improving the Design of Existing Code) so subscribe to my RSS feed to get it fresh. [...]]]></description>
			<content:encoded><![CDATA[<p>The reason why I have ever started this blog was to share good ideas with you, the accidental visitor. And hopefully to learn new things through your comments.</p>
<p>I&#8217;m working on a post about a book I read (<a href="http://blog.pepa.info/2006/09/literature/refactoring-improving-the-design-of-existing-code/">Refactoring: Improving the Design of Existing Code</a>) so subscribe to my RSS feed to get it fresh.</p>
<p>I plan to end all of my posts with a set of questions to stir up the conversation and to guide your comments to topics that I&#8217;m insterested in. Read further to see what I come up with to start.<br />
<strong><span id="more-5"></span></strong></p>
<p><strong>Question 1</strong></p>
<p>As far as I know OOP encourages programmers to use a lot of small-task classes and methods as opposed to a little of big-task methods/functions. I understand the advantages but how do you ensure that all methods and their purpose is known to all programmers so that they actually use them instead of writting their own again?<br />
Do you print a diagram of the whole system each month and post it on the office wall?</p>
<p><strong>Question 2</strong></p>
<p>The only projects I deal with are web pages or intranet/extranet applications. For a simple booking script would you still use OOP or would you not mind using well structured linear programming? By well structured I mean a library with shared functions, associative arrays with definitions, constants for types etc. If you would intentionally use OOP (that means not just because you are used to it) then why?</p>
<p>Well, thanks in advance for your comments. Hopefully we all will benefit.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/literature/welcome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
