<?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>Netfactory &#187; Development</title>
	<atom:link href="http://netfactory.dk/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://netfactory.dk</link>
	<description>WebDevelopment</description>
	<lastBuildDate>Sun, 23 Jan 2011 15:56:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Moving to PHP on 64 bit&#8230; the isssues &amp; challenges</title>
		<link>http://netfactory.dk/2011/01/23/moving-to-php-on-64-bit-the-isssues-challenges/</link>
		<comments>http://netfactory.dk/2011/01/23/moving-to-php-on-64-bit-the-isssues-challenges/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 15:56:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[64bit]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[integer]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://netfactory.dk/?p=2912</guid>
		<description><![CDATA[So your current website &#8211; if running PHP &#8211; and it seems to work just fine. I am however working on a project, where the new servers are running on a 64 bit version of the OS. This change seem to cause a number of potential issues, and as there didn&#8217;t seem to be a [...]]]></description>
			<content:encoded><![CDATA[<p><a  href="http://netfactory.dk/wp-content/uploads/2011/01/64bitshield.png" class="thickbox no_icon" rel="gallery-2912" title="64bitshield"><img class="alignright size-full wp-image-2913" title="64bitshield" src="http://netfactory.dk/wp-content/uploads/2011/01/64bitshield.png" alt="" width="100" height="100" /></a>So your current website &#8211; if running PHP &#8211; and it seems to work just fine. I am however working on a project, where the new servers are running on a 64 bit version of the OS. This change seem to cause a number of potential issues, and as there didn&#8217;t seem to be a resource collection the issues, I&#8217;ll try to post a few notes on the experience. Please feel free to add applicable notes and links in the comments.</p>
<p>Our first experience was that all our scripts seemed to use a lot more memory than it did on the old server, but there are also number of other 64 bit challenges, you should be aware of. This post is trying to provide an overview of these changes.</p>
<h2>The Integer issue</h2>
<p>On a 32bit OS, PHP uses 4 bytes (of 8 bit) to define an integer. On a 64 bit system, PHP uses 8 bytes (of 8 bit) to define an integer and thus allows it to store a far langer range of numbers.</p>
<p>You can test this with a simple script such as this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'The integer size on this system is: '</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">echo</span> PHP_INT_SIZE<span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;br&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'The maximum value you can save in an integer is: '</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">echo</span> PHP_INT_MAX<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>On 32 bit, the script will output:</p>
<pre>
The integer size on this system is: 4
The maximum value you can save in an integer is: 2147483647
</pre>
<p>On 64 bit, the script will output:</p>
<pre>
The integer size on this system is: 8
The maximum value you can save in an integer is: 9223372036854775807
</pre>
<p>Generally speaking the only drawbacks of this approach is an increased memory usage and maybe a lower performance &#8211; given you script doesn&#8217;t need the etra 32 bits provided on a 64 bit system.</p>
<p>This simple little script can simply illustrate the increased memory use:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$counter</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$counter</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">10000</span><span style="color: #339933;">;</span> <span style="color: #000088;">$counter</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$test</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$counter</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$counter</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Memory peak usage: &quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">memory_get_peak_usage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>On a 32 bit system the number output from the script is (roughly):<br />
810020.<br />
On a 64 bit system the number output from the script is (roughly):<br />
1517960.<br />
That&#8217;s an increase of memory usage of more than 80% on a simple integer array!</p>
<h3>Time and dates</h3>
<p>Beware that many time related functions in PHP works with integers &#8211; such as <a  href="http://php.net/manual/en/function.mktime.php">mktime</a>, <a  href="http://php.net/manual/en/function.strtotime.php">strtotime</a> and others uses integers as return values. As long as you use and work with these within the 32bit boundaries, you should be fine.</p>
<p>On 64 bit systems, they are able to handle much larger ranges, which could cause issues, if you allow that to happen.</p>
<h3>Memory and performance</h3>
<p>As the data volumes being moved around is increased, you could expect a performance penalty. On sites with low traffic volumes, it&#8217;s probably not an issue, but if you&#8217;re hosting a high volume site, it might be to some extend.</p>
<p>The extra memory seems to be a much larger issue to be aware of. While you may only assume you use a small number of integers, PHP itself does use them many places. When you&#8217;re creating arrays &#8211; they probably are indexed by integers and many functions return integers as control codes. While the required memory doesn&#8217;t double, do expect an overhead of 25-50% depending on what the script does &#8211; from the initial experiences; it does seem to be the case.</p>
<h2>Bit shifting</h2>
<p>Generally speaking, you should be aware every where you use <a  href="http://php.net/manual/en/language.operators.bitwise.php">bit shifting operations</a>, as they by their very nature, is quite dependent on the number of bits in the variables available.</p>
<h2>Handling Hashes</h2>
<p>If you&#8217;re using hashes for checksums, beware. Some 64 bit issues may occur.</p>
<p>We&#8217;ve seen this issue on the crc32-function. If the result of the CRC32 is a positive number (on a 32 bit system), it will be the same on a 64 bit system. If the CRC32 results in a negative number however, the return result on a 64 bit sytem will be different.</p>
<p>This script:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;Letters 'ab'&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #990000;">crc32</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ab'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Produces the following output on a 32bit system:</p>
<pre>
Letters 'ab'
-1635563411
</pre>
<p>But on a 64 bit system, it produces this output:</p>
<pre>
Letters 'ab'
2659403885
</pre>
<p>Note the returned hash is always the same, so if you&#8217;re using the crc32-hash on a completely 32bit setup OR a complete 64 bit setup, you&#8217;re might see any issues, whereas a mixed environment probably will cause issues.</p>
<p>Hash functions such as MD5, SHA1 and others &#8211; will always produce the same result no matter what system they&#8217;re running on.</p>
<h2>PHP, MySQL and 64 bit</h2>
<p>Mysql handles integers different than PHP. An integer in mysql has always the same size no matter if it&#8217;s running on 32 or 64 bit systems. An integer is always 32 bit. If you need to store a 64bit integer, mysql has an explicit data type &#8211; BigInt for this purpose, which is a 64 bit Integer (see <a  href="http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html">mysql manual on Numerical types</a>).</p>
<p>How to handle mysql seems to depend on what kind of PHP solution you&#8217;re building. If your application is deployed across several servers (which may be a mix of 32 and 64 bit systems), to two core strategies &#8211; is to either handle it in PHP or in Mysql.</p>
<p>Handling the issue in PHP would probably suggest, that you some how &#8220;range check&#8221; the PHP integer values and make sure the value is within the range allowed by a 32 bit integer.</p>
<p>Handling the issue in Mysql, would mean to just change the integers in the database to BigInts. This would always work, but for all 32 bit system be a less efficient solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://netfactory.dk/2011/01/23/moving-to-php-on-64-bit-the-isssues-challenges/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Defaults may be wrong&#8230;</title>
		<link>http://netfactory.dk/2010/12/30/defaults-may-be-wrong/</link>
		<comments>http://netfactory.dk/2010/12/30/defaults-may-be-wrong/#comments</comments>
		<pubDate>Thu, 30 Dec 2010 10:35:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[optimizing]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[refactoring]]></category>

		<guid isPermaLink="false">http://netfactory.dk/?p=2586</guid>
		<description><![CDATA[Just a word of warning when using PHP and Mysql &#8211; if you&#8217;re trying to make efficient code and not utilizing all sort of frameworks and abstractions, you might be in for a small surprise in a default setting. Usually is slightly lazy and often use the mysql_fetch_assoc function. It provides each row as an [...]]]></description>
			<content:encoded><![CDATA[<p>Just a word of warning when using PHP and Mysql &#8211; if you&#8217;re trying to make efficient code and not utilizing all sort of frameworks and abstractions, you might be in for a small surprise in a default setting.</p>
<p>Usually is slightly lazy and often use the <a  href="http://php.net/manual/en/function.mysql-fetch-assoc.php">mysql_fetch_assoc</a> function. It provides each row as an associative array, and is quite convenient to work with. Recently however while optimizing some code, I figured I&#8217;d switch to using <a  href="http://dk2.php.net/manual/en/function.mysql-fetch-array.php">mysql_fetch_array</a> assuming it should be more efficient. The logic being that mapping hash keys to array values wouldn&#8217;t be needed and it should use less memory.</p>
<p>It wasn&#8217;t the case out of the box. Switching from mysql_fetch_assoc to mysql_fetch_array without doing anything else actually increases you memory use, and is probably slightly slower. By default mysql_fetch_array does not just provide the field values as array indexes, but still maintains the hash keys too.</p>
<p>If you only want the indexes in the returned rows, you need to add an extra parameter to the function stating this explicitly.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span> MYSQL_NUM<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I wonder why it was made so. It seems like an odd choice when mysql_fetch_assoc kan provide the row indexed with hash keys &#8211; The correct behavior for mysql_fetch_array (by default) ought to be to just return the array without the hashkeys &#8211; and have that option available if needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://netfactory.dk/2010/12/30/defaults-may-be-wrong/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Function names as signaling</title>
		<link>http://netfactory.dk/2010/05/16/function-names-as-signaling/</link>
		<comments>http://netfactory.dk/2010/05/16/function-names-as-signaling/#comments</comments>
		<pubDate>Sun, 16 May 2010 20:49:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://netfactory.dk/?p=2569</guid>
		<description><![CDATA[In most web applications there&#8217;s a host of functions (or methods if speaking in the object-oriented world). It&#8217;s widely recognized, that it&#8217;s probably a good idea to name them something, which may suggest the purpose or functionality of what the function is doing, but often developers seem to fail at making a stringent naming convention. [...]]]></description>
			<content:encoded><![CDATA[<p>In most web applications there&#8217;s a host of functions (or methods if speaking in the object-oriented world). It&#8217;s widely recognized, that it&#8217;s probably a good idea to name them something, which may suggest the purpose or functionality of what the function is doing, but often developers seem to fail at making a stringent naming convention. Before starting on your next big development adventure, here are a three suggested rules for naming functions.<br />
<!-- more --></p>
<h3>1. It&#8217;s more important to have a suggestive name, than a short one.</h3>
<p>Never call a function something short but meaningless. Instead use CamelCase and make a sentence suggesting what the function does.</p>
<ul>
<li>Bad examples found in live code: &#8220;process&#8221;, &#8220;fixit&#8221;, &#8220;cleanup&#8221;.</li>
<li>Good examples: &#8220;saveToDatabase&#8221;, &#8220;convertIpnumberToDomainName&#8221;, &#8220;calculateTotalPricing&#8221;.</li>
</ul>
<h3>2. Use prefixes on functions </h3>
<p>Reserve common names (more if you like) for specific type of functions. Here are a few suggested rules:</p>
<ul>
<li> &#8220;get&#8221;-functions should always retrieve and return data &#8211; never print data.</li>
<li> &#8220;print&#8221;-functions shoudl always print data to &#8220;standard out&#8221;.</li>
<li> &#8220;set&#8221;-functions should ways set data to an object (and choose if &#8220;set&#8221; also saves data or not).</li>
<li> &#8220;save&#8221;-functions (if set-functions doesn&#8217;t save properties) saves all current properties to the persistent storage (usually database).</li>
</ul>
<h3>3. Reuse data model objects in function names</h3>
<p>If you&#8217;re data model (or object model) already contains names of entities, reuse these in function names. If a table is named &#8220;Travel&#8221;, call the function &#8220;saveTravelRecord&#8221;, Not just &#8220;saveDataRecord&#8221;.<br />
Make consistent use of the same names, field names, properties and other entities found in the application. Using the same name for the same object all across the application, may seem obvious, but somehow developers seem to find slightly different names for the same object again and again.</p>
<p>While the three above tips may seem simple, do check your code and see how many places they are broken. I&#8217;ve seen countless times, and getting it right from the beginning would have cost a small effort, refactoring  the code years later is a much bigger effort.</p>
]]></content:encoded>
			<wfw:commentRss>http://netfactory.dk/2010/05/16/function-names-as-signaling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bread crumbs in version control</title>
		<link>http://netfactory.dk/2010/05/09/bread-crumbs-in-version-control/</link>
		<comments>http://netfactory.dk/2010/05/09/bread-crumbs-in-version-control/#comments</comments>
		<pubDate>Sun, 09 May 2010 21:32:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[cvs]]></category>

		<guid isPermaLink="false">http://netfactory.dk/?p=2491</guid>
		<description><![CDATA[I’m sorry but sometimes I really don’t get why even seasoned developers doesn’t learn the art of the commit message in version control system. All too often I’ve come across check-ins where the entire commit message just reads “bugfix”, “change”, “oops” or something just as mindless. The effort of writing a useful message compared to [...]]]></description>
			<content:encoded><![CDATA[<p>I’m sorry but sometimes I really don’t get why even seasoned developers doesn’t learn the art of the commit message in version control system. All too often I’ve come across check-ins where the entire commit message just reads “bugfix”, “change”, “oops” or something just as mindless.</p>
<p>The effort of writing a useful message compared to the potential benefit seems to be one the best ratios &#8211; but of course the pay-back is usually some time away &#8211; too bad. Once you work on the same code for years &#8211; or even better inherit code from others, you’ll quickly learn to appreciate anyone who used more than 10 seconds on composing a thoughtful message for the future.</p>
<p>Here are 3 rules you should always, always obey when committing to a version control system.<br />
<!-- more --></p>
<h3>Always leave a reference to the issue/bug tracking system.</h3>
<p>All professional development uses some sort of issue tracking system, to keep track of bugs, new features and other changes to the system. The issue tracking system should always be able to tell who asked for a change, why it was asked for and what considerations was made before the code change. By leaving a reference to the issue tracker, it’s often much easier to get “the big picture” if the change need to be changed years later. To make sure you get it in, just write “Bug #number#: “ as the initial part of the commit message.</p>
<h3>Don’t write what, write why</h3>
<p>Don’t write it’s a bug fix &#8211; most people will know it from look either at the code or in the issue tracking system (see point 1 above), rather write why it fixes the issue (“New check to check for missing parameters”, “Now handles no search result from db correct” &#8211; not just “bugfix”).</p>
<h3>Keep it brief.</h3>
<p>Log messages are not a place to store documentation, user guides or any other important information. You can assume it’s the future you (or another future fellow developer) who will look at the code and try to make sense of it. Think of this, when writing the message &#8211; it’s not for the project manager, it’s not for the end-users &#8211; it’s for a developer doing maintenance work on the code in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://netfactory.dk/2010/05/09/bread-crumbs-in-version-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP best practice: Function Parameters</title>
		<link>http://netfactory.dk/2010/05/01/php-best-practice-function-parameters/</link>
		<comments>http://netfactory.dk/2010/05/01/php-best-practice-function-parameters/#comments</comments>
		<pubDate>Sat, 01 May 2010 17:00:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://netfactory.dk/?p=2474</guid>
		<description><![CDATA[I&#8217;ve been developing web applications for some years now, and while I make no claims to being the world greatest developer, I do figure, that I do have some solid experience which may help others &#8211; or at least encourage thoughts and discussion. This is the first in a series of posts, and while it [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been developing web applications for some years now, and while I make no claims to being the world greatest developer, I do figure, that I do have some solid experience which may help others &#8211; or at least encourage thoughts and discussion. This is the first in a series of posts, and while it may be from a PHP developers point of view, it may applicable to other programming languages, and maybe even beyond web applications. Here are my four tips on function parameters.</p>
<h3>Always have a default value on all parameters</h3>
<p>Functions parameters are often used as input to SQL queries, calling webservices or computations. Null or non-existing values often tend to break these things and throws horrible messages to the end-user.</p>
<p>While the parts of the program using your function always should provide proper values, laziness, oversights or unexpected scenarios, may prove it not to be the case. If at all possible, always try to provide default values on all parameters to a function &#8211; and if you really can&#8217;t make sure it&#8217;s handled gracefully.</p>
<h3>Choose reasonable defaults</h3>
<p>When providing default values, don&#8217;t choose extremes. If you&#8217;re browsing in a list of usernames, don&#8217;t use a (pure) wildcard as default value &#8211; use an &#8220;A&#8221; to list all users starting with the letter A.  If you&#8217;re function allows a limit on the number of rows returned form a database query (say for paging purposes), set the default to 10, 20 or some other low number, don&#8217;t go for worst case scenarios like 9999, or 999999.</p>
<p>If the developer using the function needs plenty of rows, it&#8217;s easy to pass a specific value, and if the developer forgets to specify the number of rows, expected, they get a reasonable result, which may help them to ask for more (if actually needed).</p>
<h3>Always sanitize input</h3>
<p>Even though a given function naturally only will be used with valid input and so on, every function should take steps to  secure them selves.<br />
One of the most basic steps is to make sure all input is sanitized. Protecting your function from making <a  href="http://en.wikipedia.org/wiki/SQL_injection">SQL injection</a> threats or other security issues, is not the responsibility of the places utilizing the function, but the responsibility of the function it self, and thus it should take steps to make sure it doesn&#8217;t introduce security issues.</p>
<p>As basic validation of simple input parameters, look at the <a  href="http://php.net/manual/en/book.ctype.php">ctype functions in PHP</a>. If you can always try to validate against <a  href="http://en.wikipedia.org/wiki/Whitelist">a whitelist</a> (which characters are allowed) instead of <a  href="http://en.wikipedia.org/wiki/Blacklist">blacklists</a> (these characters are not allowed) as missing things which may introduce issues in a black list is harder, than allowing what you expect, to pass through.</p>
<h3>Accept an array of key value pairs</h3>
<p>If a simple function accepts a single or two parameters, they may be passed as regular parameters, but once the list of possible parameters starts to grow, changing it a single parameter &#8211; which is an array with key/value-pairs, seems to be a much more solid long-term solution on keeping the interface developer friendly. Sure you can have endless lists of 10-15 parameters, but if you have default values on the first 14 values and just need to change the last, the code ought to be much more clean by being able to pass an array with the single key/value-pair needed to be changed from the default value.</p>
<p>That was the first four tips on function parameters. More on <a  href="http://netfactory.dk/tag/php/">PHP</a> and <a  href="http://netfactory.dk/tag/security/">Security</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://netfactory.dk/2010/05/01/php-best-practice-function-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build-in time bombs</title>
		<link>http://netfactory.dk/2010/02/09/build-in-time-bombs/</link>
		<comments>http://netfactory.dk/2010/02/09/build-in-time-bombs/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 21:50:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[maintenance]]></category>

		<guid isPermaLink="false">http://netfactory.dk/?p=1831</guid>
		<description><![CDATA[I&#8217;ve been refactoring and refactoring some old code, and it&#8217;s kind of odd what short-cuts (or even time bombs), you&#8217;ll find in code, which apparently wasn&#8217;t supposed to live on for years. In a now retired CMS system, we had an issue every new year, when some kind of bug would reset all &#8220;schedules&#8221; for [...]]]></description>
			<content:encoded><![CDATA[<p><a  href="http://www.netfactory.dk/wp-content/uploads/2010/02/dynamiteclock.jpg" class="thickbox no_icon" rel="gallery-1831" title=""><img src="http://www.netfactory.dk/wp-content/uploads/2010/02/dynamiteclock.jpg" alt="" title="dynamiteclock" width="130" height="83" class="alignright size-full wp-image-1832" /></a>I&#8217;ve been refactoring and refactoring some old code, and it&#8217;s kind of odd what short-cuts (or even time bombs), you&#8217;ll find in code, which apparently wasn&#8217;t supposed to live on for years.<br />
In a now retired CMS system, we had an issue every new year, when some kind of bug would reset all &#8220;schedules&#8221; for upcoming stories and content. No-one ever got around to fix it, as the system was soon to be decommissioned &#8211; but sadly the bug did survive a few years anyway.</p>
<p>These days, I&#8217;m was working in the system, which came to replace the broken system from before. Here&#8217;s another odd thing &#8211; It was apparently hard coded into the editor in the backend, that stories need to have a &#8220;published date&#8221; between 1996 and 2011. As there really isn&#8217;t any documentation and the original developer has left the company, it&#8217;s hard to know why it was made so. While there probably was a reason, it&#8217;s lost by now.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> &lt;select name=&quot;year&quot; size=&quot;1&quot; style=&quot;width:55px;&quot; title=&quot;Year&quot;&gt;
 <span style="color: #000000; font-weight: bold;">&lt;?php</span>
   <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1996</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">2011</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;option value=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #009933; font-weight: bold;">%1\$d</span><span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #009933; font-weight: bold;">%2\$s</span>&gt;<span style="color: #009933; font-weight: bold;">%1\$d</span>&lt;/option&gt;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$year</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot; selected&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/select&gt;</pre></div></div>

<p>We fixed it by making the latest &#8220;published date&#8221; go between 1996 and current year plus one.</p>
<p>While it was an odd thing, I&#8217;m surely glad that we from time to time do some sort of maintenance of old code &#8211; even while it seems to work perfectly. It&#8217;s far from the only bad thing we found, and while most people worry mainly about new code, sometimes you should also remember the old stuff.</p>
]]></content:encoded>
			<wfw:commentRss>http://netfactory.dk/2010/02/09/build-in-time-bombs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Browser handling of broken includes in an Ajax world?</title>
		<link>http://netfactory.dk/2009/07/29/browser-handling-of-broken-includes-in-an-ajax-world/</link>
		<comments>http://netfactory.dk/2009/07/29/browser-handling-of-broken-includes-in-an-ajax-world/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 13:18:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Markup]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://netfactory.dk/?p=1703</guid>
		<description><![CDATA[In this mordern web 2.0 age, javascript includes are used more and more &#8211; and in some cases solutions often depend on included content from 3rd parties. While it is nice these 3rd parties may provide us with data (such as the latest tweets from twitter), it would be quite nice, if issues on their [...]]]></description>
			<content:encoded><![CDATA[<p>In this mordern web 2.0 age, javascript includes are used more and more &#8211; and in some cases solutions often depend on included content from 3rd parties. While it is nice these 3rd parties may provide us with data (such as the latest tweets from twitter), it would be quite nice, if issues on their server didn&#8217;t break the fancy page we&#8217;re building.</p>
<p>So the question is this: <strong>If you build a page and include javascript from foreign scripts, will error messages on their part break your site?</strong> We&#8217;ve made the assumption, that the Web2.0 page will degrade gracefully, so that the content/functionality of the javascript-includes is just extra frosting, not needed to use the page</p>
<p>We did <a  href="http://netfactory.dk/lab/markup/js/includes/">a simple little test</a>, and in the most common browsers, a server error (that is an errror signaled in the  <a  href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">http-header status code</a>), will just cause the browser to ignore the included content. If the header is a &#8220;200 Ok&#8221; header,  the content will break.</p>
<p>The answer, <strong>no  &#8211; assuming, that their servers provides a http-header, that signals error</strong>. If you have a few spare seconds, please <a  href="http://netfactory.dk/lab/markup/js/includes/">visit the test page</a>, and if your browser reports a javascript error, please leave you browser (make and model) and operating system in a comment below.</p>
]]></content:encoded>
			<wfw:commentRss>http://netfactory.dk/2009/07/29/browser-handling-of-broken-includes-in-an-ajax-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The art of the commit (in version management)</title>
		<link>http://netfactory.dk/2009/01/05/the-art-of-the-commit-in-version-management/</link>
		<comments>http://netfactory.dk/2009/01/05/the-art-of-the-commit-in-version-management/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 19:19:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[cvs]]></category>

		<guid isPermaLink="false">http://netfactory.dk/?p=315</guid>
		<description><![CDATA[Most developers (and certainly professional shops) working with software- or webdevelopment has understood the ideas behind sourcecode version management &#8211; no matter if they choose to use cvs, subversion, git or any of the other fine systems available. How developers use these systems, can provide an easy insight into who is the dummy, the average [...]]]></description>
			<content:encoded><![CDATA[<p>Most developers (and certainly professional shops) working with software- or webdevelopment has understood the ideas behind sourcecode version management &#8211; no matter if they choose to use <a  href="http://www.nongnu.org/cvs/">cvs</a>, <a  href="http://subversion.tigris.org/">subversion</a>, <a  href="http://git-scm.com/">git</a> or any of the other fine systems available. How developers use these systems, can provide an easy insight into who is the dummy, the average and the great developer.</p>
<h2>When to commit</h2>
<p>One of the first distinguishing signs is what they commit &#8211; is the version management system used as a backup tool or as a version tracking tool. Some seem to think, you should end the day by committing all your sourcecode (no matter which state it’s in). This is really bad sign. Others commit whenever a new file is finished and thought ready to use &#8211; which is slightly better. Others again commit once &#8211; just before a new release &#8211; and has the commit contain each and every change since last release.</p>
<p>In my world a commit should contain a complete new feature across all the files changed to make the new feature. The commit should preferably only address one change (a new functionality or a changed feature).</p>
<h2>The commit message</h2>
<p>Another way to spot bad habits is in the commit message. Is there a commit message at all? &#8211; if not, it’s a bad sign. Almost as bad are meaningless comments, which may come in all sort of varieties &#8211; “work in progress”, “bugfix”, “update”, “foobar”. I’m sure they make sense to the developer at the time of committing them, but hardly 6 months later, when browsing the logs and wondering why a certain change was made.</p>
<p>A less common bad commit habit is the “book style” &#8211; where the comment either contain a delta of the changed lines (literally or as a description) or the length of the comment is a small story explaining the reason for the change, why it was made the way it was and on and on.</p>
<p>I’d any day prefer seeing a reference to a bug/ feature tracking system (<a  href="http://bugzilla.org/">bugzilla</a>, <a  href="http://trac.edgewall.org/">trac</a> or anything like it), and a brief summary of the change in a 140 characters a less.</p>
]]></content:encoded>
			<wfw:commentRss>http://netfactory.dk/2009/01/05/the-art-of-the-commit-in-version-management/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Tips for developing WebApplications</title>
		<link>http://netfactory.dk/2008/11/28/tips-for-developing-webapplications/</link>
		<comments>http://netfactory.dk/2008/11/28/tips-for-developing-webapplications/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 22:06:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://netfactory.dk/?p=309</guid>
		<description><![CDATA[So it been awhile since I sort of promised some tips on developing web applications fast. This post contains my five generic tips, which may apply to you (but then again &#8211; your mileage may vary). I’ve tried to abstract the advice and not stick to PHP development here, though it’s by far the world [...]]]></description>
			<content:encoded><![CDATA[<p>So it been awhile since I sort of promised some tips on developing web applications fast. This post contains my five generic tips, which may apply to you (but then again &#8211; your mileage may vary). I’ve tried to abstract the advice and not stick to PHP development here, though it’s by far the world I know best.</p>
<h2>1. Spend time on the data model</h2>
<p>Too often a data model is driven by code, not careful thinking, and this often causes problems has the web application develops and expand over time. When developing a site, which needs data stored in a database (as most web applications tend to do), do try to spend some time on the data model &#8211; which tables do you need, what fields should the tables have, are the naming logical and consistent, what constraints and limitations does the data model offer.</p>
<p>It’s often far easier to refactor code and functionality than it is changing the database tables and fields, and it can be a tremendous help while maintaining an application if you clearly understands the data its working with.</p>
<h2>2. Get the basics working first and fast</h2>
<p>It often takes a while to get a complete web application finished. Help motivating yourself by getting the core working first and then add features and frosting once it’s working. By having a working skeleton, I usually find it much easier guess how much work needs to finish the various features than I do guessing the work needed to complete a section (ie. admin interface) on the application.</p>
<h2>3. Think performance and security from the beginning</h2>
<p>Remember to think of performance and security from the very beginning. Sometimes performance &#8211; or security &#8211; may cause you to layout the data model in a certain way or structure the application a certain way. While you may be able to add performance and security during refactoring, it’s often much harder than it is keeping both in mind from the very beginning.</p>
<h2>4. Don’t fix the future; focus on the current needs</h2>
<p>I don’t care about the next version. I really don’t want an infrastructure in place, which can help me build the future versions of the application. I want the features and infrastructure in place for the current version I’m working on &#8211; and frankly the features in the next version has a tendency to change before I’m ready to develop them.<br />
Too often future-proofing an application clutters the code and too often the clutter doesn’t ever come to any good use &#8211; it’s just noise once we get to the real future features of the application.</p>
<h2>5. Naming matters</h2>
<p>Do think of what names you use on functions, classes, variables and database tables through out the application &#8211; and choose something meaningful. A variable named $x doesn’t hint what it’s used for. Help yourself (and other looking at the code) by hinting the uses of various things by choosing meaningful names.</p>
]]></content:encoded>
			<wfw:commentRss>http://netfactory.dk/2008/11/28/tips-for-developing-webapplications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Your mileage may vary</title>
		<link>http://netfactory.dk/2008/11/09/your-mileage-may-vary/</link>
		<comments>http://netfactory.dk/2008/11/09/your-mileage-may-vary/#comments</comments>
		<pubDate>Sun, 09 Nov 2008 19:46:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://netfactory.dk/?p=307</guid>
		<description><![CDATA[It’s always fun to read articles with tips and tricks by other developers and see how they figure “best practices” are handled. Most developers do seem to thing they observations and practices are easily adopted by anyone, and should be accepted without any argumentation or reasoning behind the advice. One of the nice examples of [...]]]></description>
			<content:encoded><![CDATA[<p>It’s always fun to read articles with tips and tricks by other developers and see how they figure “best practices” are handled. Most developers do seem to thing they observations and practices are easily adopted by anyone, and should be accepted without any argumentation or reasoning behind the advice.</p>
<p>One of the nice examples of this, was a story called “<a  href="http://blog.midstride.com/2008/09/09/5-tips-to-develop-php-applications-fast/">5 tips and tools to develop php applications fast</a>”, and while it may apply to the web applications developed by the author, it’s one of those where I question who is supposed to be the audience. All 5 tips are often found in many textbooks and other stories on the net, and in my experience they are all wrong (more or less naturally).</p>
<p><strong>1) Use a MVC framework &#8211; it’s an industry accepted standard.</strong><br />
MVC as an idea may be accepted, but there are many ways of implementing the MVC &#8211; even with the various PHP frameworks. If you know the MVC pattern it may be an idea to look at the frameworks supporting it, but don’t get carried away.</p>
<ul>
<li>If all your old code is non-MVC code and you don’t have any plans to MVC-refactor it, it may cause you maintenance overhead to try a completely different style  on a single project/web application.</li>
<li>If you aren’t used to using a (MVC) framework you need to invest time in learning it.</li>
</ul>
<p>Do keep an eye on the overhead caused by the framework. If you web application has a heavy load and the framework causes 5-10% overhead, it may a bad idea.</p>
<p><strong>2) Ajax Frameworks<br />
</strong>Great idea.. but to utilize the power of an ajax framework, you need to learn how to use it. Also Ajax isn’t the holy grail of the internet. Sometimes it’s cleaver to use it, other times it isn’t. By using plain old HTML and reloading the page from time to time, it may be easier to debug the application.</p>
<p>Do also notice, that writing great/professional quality Javascript often requires just as great skills as writing professional PHP.</p>
<p><strong>3) IDEs<br />
</strong>An IDE &#8211; Integrated Development Environment &#8211; can be a great idea if you know your way around it, and use it regularly. An IDE is &#8211; like any other tool &#8211; something you need to invest time and resources into, if you want something back &#8211; and especially if we’re talking a beast like Eclipse-based tools.</p>
<p><strong>4) Database creation/management software<br />
</strong>Let me skip comments on database creating management tools. I’ve never really used them and don’t know if they’re a pain or a benefit. I have often seen though, that too easy access to the database, leads to sloppy database design (or at least something, that isn’t thought through).</p>
<p>So far it’s been my experience, that people who knows the command-line clients to databases, often has invested much more time in thinking their data models through and often spend a little more time considering the table layout, the field definitions, indexes and other important aspects, than those who use a nice graphical interface.</p>
<p><strong>5) Object Relational Mapping<br />
</strong>Object-Oriented programming isn’t a holy grail, and most people doing OO programming (in my experience) doesn’t genuinely do object-oriented programming &#8211; instead they use the OO-facilities in the language to slap functions together in a class.</p>
<p>There’s nothing wrong with procedural programming as such, and trying to force object-orientation into your code &#8211; and even abstracting it away through Object-relational mapping, has often lead to slow performance and odd database designs. If you know what you’re doing great, but there’s no free lunch, and trying to utilze ORM without having a pretty solid grip on what’s happening and why, rarely does anything good to your productivity.</p>
<p>I’m quite sure for some developers, using some sort of object-relational mapping might be a gain in programmer productivity, but do keep in mind, that if you’re developing a site with massive traffic, the programmer gains may easily be crushed in added server resource requirements &#8211; spending a few minutes extra optimizing and tuning applications, may in some cases save hours and hours of cpu cycles once the solution is deployed.</p>
<p>Getting back to the article, I’m sure the advise is well-meant and thought through by the author, but do always &#8211; as with all advise &#8211; think it through and see how may apply to your adoptation. In may daily development some of it is quite terrible (as I often work on a site with thousands if not millions of pageviews every week).</p>
<p>I’m wondering what my 5 tips would be for developing PHP applications fast would be. Check back in a few days, and there may be an answer &#8211; which may or may not &#8211; apply to you.</p>
]]></content:encoded>
			<wfw:commentRss>http://netfactory.dk/2008/11/09/your-mileage-may-vary/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: basic

Served from: netfactory.dk @ 2012-05-23 22:17:41 -->
