<?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>Designoplasty Web Design and Development Blog &#187; Coding</title>
	<atom:link href="http://designoplasty.com/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://designoplasty.com</link>
	<description>HTML, Javascript, PHP, and Me</description>
	<lastBuildDate>Fri, 14 May 2010 01:22:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>HTML: What Tags to use for Key-Value Pairs?</title>
		<link>http://designoplasty.com/2010/04/12/html-what-tags-to-use-for-key-value-pairs/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=html-what-tags-to-use-for-key-value-pairs</link>
		<comments>http://designoplasty.com/2010/04/12/html-what-tags-to-use-for-key-value-pairs/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 23:45:15 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://designoplasty.com/?p=1214</guid>
		<description><![CDATA[When you have a key-value list what HTML tags should you use? I&#8217;ve been thinking a lot about this and I&#8217;ll say it flat out: the answer is tables. Here are some of the common tags used to contain key-value pair lists and why using tables is better.

Tags That Don&#8217;t Work Very Well

Dictionary Lists

You could [...]]]></description>
			<content:encoded><![CDATA[<p>When you have a key-value list what HTML tags should you use? I&#8217;ve been thinking a lot about this and I&#8217;ll say it flat out: the answer is tables. Here are some of the common tags used to contain key-value pair lists and why using tables is better.</p>

<h3>Tags That Don&#8217;t Work Very Well</h3>

<h4>Dictionary Lists</h4>

<p>You could use a dictionary list like so:</p>

<pre><code>&lt;dl&gt;
    &lt;dt&gt;Color&lt;/dt&gt;
    &lt;dd&gt;Red&lt;/dd&gt;
    &lt;dt&gt;Shape&lt;/dt&gt;
    &lt;dd&gt;Square&lt;/dd&gt;
&lt;/dl&gt;</code></pre>

<p>Semantically, this kind of works out. It has key and value tags, dt and dd. But the problem comes with formatting. What if you want to put a border around a key value pair? Well, you can&#8217;t. One solution is to wrap each key-value pair in its own dl tag, but that seems like a lot of work and then you lose out on the whole list wrapper, so you have to wrap the whole thing in a div or something depending on your formatting requirements. </p>

<p>This is not to say that dictionary lists are bad, they are perfect for things that closely resemble actual dictionary lists, but they are not a very good general key-value pair container because of limited formatting options.</p>

<h4>Unordered Lists</h4>

<p>Unordered lists are very flexible and can wisely be used for all kinds of lists. The other day I saw them used as a container for key-value pairs like this:</p>

<pre><code>&lt;ul&gt;
    &lt;li&gt;Color &lt;span class="Value"&gt;Red&lt;/span&gt;&lt;/li&gt;
    &lt;li&gt;Shape &lt;span class="Value"&gt;Square&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>

<p>In many cases this will work fine. It has the benefit over a dictionary list that both the key and value are contained within one element. It has the downside that the Value span has to be formatted to undo any formatting you&#8217;ve given the li (the key). This could be altered by adding a Key span, but at that point you may as well just use a bunch of divs. This doesn&#8217;t give you very good CSS free presentation and completely loses the semantics of the data. The point of HTML is that if there&#8217;s no style things still end up looking fairly decent and that at the very least, the HTML can accurately represent the data relationships.</p>

<h3>The Winner</h3>

<h4>Tables</h4>

<p>We&#8217;ve been so conditioned against tables and rightly so. People have abused tables in the past to format their pages to the point where you can&#8217;t tell what&#8217;s going on. But remember the rule, &#8220;Tables should be used for tabular data.&#8221; A list of key-value pairs is an excellent example of tabular data, but I think people don&#8217;t think to use tables at first because the tabular data in this case only has two columns. People start to think of tables for things with three or more columns. Here&#8217;s the markup.</p>

<pre><code>&lt;table&gt;
    &lt;tr&gt;
        &lt;th&gt;Color&lt;/th&gt;
        &lt;td&gt;Red&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;th&gt;Shape&lt;/th&gt;
        &lt;td&gt;Square&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;</code></pre>

<p>This fixes all the problems. Each key value pair is enclosed in a tr element. The key is enclosed in a th and the value is enclosed in a td. The default formatting is going to be perfect.</p>

<p>Furthermore, tables offer so much more extensibility. If you need a header row, break out the thead and tbody elements. If you need a summary row at the bottom, add another tbody element. It&#8217;s ultimately extendable with no classes.</p>

<p>Of course, that doesn&#8217;t mean it&#8217;s the solution for everything. If what you have is a dictionary list, then of course the dictionary list tags are going to work better. But for general key-value pairs, and the ways we generally think of formatting key-value pairs this is way better.</p>

<p>It might be time to get back in touch with tables if you&#8217;ve stopped thinking about them. Once you drop the idea of tables being used for page formatting and adopt the idea of using them just for small blocks of data you can really start to see how great they are.</p>

<p>The CSS for tables is a little more complex, so take some time to start understanding that. I&#8217;ll give you a hint, though. Do yourself a favor and use the border-collapse property. It takes a lot of the fuss and mess out of formatting tables:</p>

<pre><code>table
{
    border-collapse: collapse;
}</code></pre>

<h4>Difficult Situations</h4>

<p>I just thought I should mention here that I have run into one situation that isn&#8217;t covered very well by any existing HTML elements and in its nature is just difficult. This is the case where you have individual key-value pairs that you want &#8220;arranged&#8221; in an some custom manner. For instance you want the key on top with a border on the bottom and the value beneath that. Then you want those elements to be lined up horizontally:</p>

<pre>Color     Shape
--------  --------
Red       Square</pre>

<p>Using more radical CSS dictionary lists can be made to perform this way although it&#8217;s probably better handled by turning the table suggestion above on its side and using a table with two rows, a header row and a data row depending on how you want it formatted.</p>

<pre><code>&lt;table&gt;
    &lt;thead&gt;
        &lt;tr&gt;
            &lt;th&gt;Color&lt;/th&gt;
            &lt;th&gt;Shape&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;Red&lt;/td&gt;
            &lt;td&gt;Square&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;</code></pre>

<p>That&#8217;s more HTML than absolutely necessary, the thead and tbody can be left out, but it still feel like a lot of HTML for something semantically simple. But at this point it&#8217;s going to take either a lot of HTML (tables) or a lot of CSS (dictionary lists) to make this particular scenario work. If you want it to work without CSS, you really have no choice but tables.</p>

<p>The issue with this concept is that it doesn&#8217;t allow for very long values or very many key-value pairs horizontally and the whole scenario is only appropriate when you know in advance the range and quantity of values to expect.</p>


]]></content:encoded>
			<wfw:commentRss>http://designoplasty.com/2010/04/12/html-what-tags-to-use-for-key-value-pairs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Themes: Object Oriented PHP Code is Very Important</title>
		<link>http://designoplasty.com/2010/02/15/wordpress-themes-php-code-is-very-important/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=wordpress-themes-php-code-is-very-important</link>
		<comments>http://designoplasty.com/2010/02/15/wordpress-themes-php-code-is-very-important/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 17:41:46 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Object Oriented]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Themes]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://designoplasty.com/?p=1180</guid>
		<description><![CDATA[I'm doing a heavy rewrite of my main WordPress theme that all of my other themes are based on. As someone who has spent a lot of time writing code, one of the things that has been bugging me about WordPress themes is all the duplication of HTML.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m doing a heavy rewrite of my main WordPress theme that all of my other themes are based on. As someone who has spent a lot of time writing code, one of the things that has been bugging me about WordPress themes is all the duplication of HTML.</p>

<p>For instance, if all your pages have a format involving a header element, a body element, and a footer element, then you have to duplicate that HTML in single.php, page.php, 404.php, etc. Then if you ever change it you have to edit every one of those files just to make the same changes over and over again. You&#8217;re probably going to forget to do it in some files and you&#8217;re going to do it wrong in others.</p>

<p>Wouldn&#8217;t it be great if you could just call a function that would establish this pattern for you in all files? Then if you needed to change it, you would only have to change it in one place and all your site&#8217;s pages would be effected. But what if you need to tweak the template slightly for different pages? This is exactly why object oriented design is important.</p>

<p>So you have a base class that draws the usual page structure and then provide override-able and abstract methods so that a new class can be created if you need to customize. It works perfectly because it gives you maximum code reuse and there&#8217;s no duplication.</p>

<p>However, it does make the theme very code heavy. There&#8217;s not a ton of code, but enough that would intimidate most people. Plus, if you don&#8217;t have a lot of experience with object oriented design getting the extensibility right is going to be a bit difficult.</p>

<p>But that&#8217;s kind of my point for this post. It&#8217;s not necessarily that you need to do this, because obviously themes can be made without it. But it&#8217;s the fact that object oriented design is important to web applications and even blogs too. If you do a lot of PHP coding but aren&#8217;t yet familiar with the concepts behind object oriented programming, then learning more about that will really be a benefit to you.</p>
]]></content:encoded>
			<wfw:commentRss>http://designoplasty.com/2010/02/15/wordpress-themes-php-code-is-very-important/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tip: Always Comment overflow: hidden; CSS Rules</title>
		<link>http://designoplasty.com/2010/02/09/tip-always-comment-overflow-hidden-css-rules/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=tip-always-comment-overflow-hidden-css-rules</link>
		<comments>http://designoplasty.com/2010/02/09/tip-always-comment-overflow-hidden-css-rules/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 08:05:45 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Floating Elements]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://designoplasty.com/?p=1169</guid>
		<description><![CDATA[CSS comments aren&#8217;t always helpful, they tend to muddle the code and once you get good at naming classes and ids your CSS should tell a pretty clear story. But one thing that should always be clearly commented is the use of overflow: hidden;

This rule is used mostly for a couple of reasons, and almost [...]]]></description>
			<content:encoded><![CDATA[<p>CSS comments aren&#8217;t always helpful, they tend to muddle the code and once you get good at naming classes and ids your CSS should tell a pretty clear story. But one thing that should always be clearly commented is the use of <code>overflow: hidden;</code></p>

<p>This rule is used mostly for a couple of reasons, and almost never to actually hide overflowing content. The first is to make sure that and element containing floating elements will clear itself. The other is to make sure that an element next to a float doesn&#8217;t wrap under that float.</p>

<p>If in your CSS file you clearly comment every time you use overflow: hidden you will be able to read your CSS much faster when you come back to it later. You will also almost certainly find all the unnecessary <code>overflow: hidden;</code> rules you have and it will help you get a much better overall understanding of your layout philosophy.</p>
]]></content:encoded>
			<wfw:commentRss>http://designoplasty.com/2010/02/09/tip-always-comment-overflow-hidden-css-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the WordPress apply_filters Function for Dynamic Content</title>
		<link>http://designoplasty.com/2010/01/26/using-the-wordpress-apply_filters-function-for-dynamic-content/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-the-wordpress-apply_filters-function-for-dynamic-content</link>
		<comments>http://designoplasty.com/2010/01/26/using-the-wordpress-apply_filters-function-for-dynamic-content/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 04:52:30 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Filters]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Themes]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://designoplasty.com/?p=1159</guid>
		<description><![CDATA[In a WordPress plugin you can filter many values including the title and content of a post using:

add_filter('the_content', 'MyPluginClass::FilterTheContent');

This is pretty handy, but sometimes when you&#8217;re writing a WordPress theme you want to allow plugins to add content, not just filter the usual content. Using apply_filters makes this pretty easy because you can call apply [...]]]></description>
			<content:encoded><![CDATA[<p>In a WordPress plugin you can filter many values including the title and content of a post using:</p>

<pre><code>add_filter('the_content', 'MyPluginClass::FilterTheContent');</code></pre>

<p>This is pretty handy, but sometimes when you&#8217;re writing a WordPress theme you want to allow plugins to add content, not just filter the usual content. Using <code>apply_filters</code> makes this pretty easy because you can call apply filters with custom &#8220;tags&#8221; and it will just work. For instance in your theme you can put:</p>

<pre><code>&lt;?php

    $theMessage = apply_filters('CustomThemeMessage', '' /* default value: empty string */);

    if (!empty($theMessage))
    {
        echo '&lt;div class="Message"&gt;', $theMessage, '&lt;/div&gt;';
    }

?&gt;</code></pre>

<p>If nobody ever filters on the tag &#8216;CustomThemeMessage&#8217; it&#8217;s fine, your theme won&#8217;t break or anything. But plugins that know this tag is available can use it:</p>

<pre><code>add_filter('CustomThemeMessage', 'MyPluginClass::FilterTheContent');</code></pre>

<p>When you&#8217;re developing themes and plugins in tandem, this is incredibly useful and robust. It&#8217;s also not as risky as filtering a tag like &#8216;the_content&#8217; where a mistake can really mess up your site. It will also be more performant when you only need the custom content on one or a few of the pages on your site.</p>]]></content:encoded>
			<wfw:commentRss>http://designoplasty.com/2010/01/26/using-the-wordpress-apply_filters-function-for-dynamic-content/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress and PHP have Poor Support for Dates and Time Zones</title>
		<link>http://designoplasty.com/2010/01/16/wordpress-and-php-have-poor-support-for-dates-and-time-zones/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=wordpress-and-php-have-poor-support-for-dates-and-time-zones</link>
		<comments>http://designoplasty.com/2010/01/16/wordpress-and-php-have-poor-support-for-dates-and-time-zones/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 09:00:00 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Object Oriented]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://designoplasty.com/?p=1140</guid>
		<description><![CDATA[Today I spent way too much time figuring out how to convert dates and times to different time zones. PHP can barely do it, and WordPress really doesn&#8217;t do anything to make it easier. I would love it if someone would just create a simple function like this:

$string = format_gmt_time_for_time_zone(
    'l, F [...]]]></description>
			<content:encoded><![CDATA[<p>Today I spent way too much time figuring out how to convert dates and times to different time zones. PHP can barely do it, and WordPress really doesn&#8217;t do anything to make it easier. I would love it if someone would just create a simple function like this:</p>

<pre><code>$string = format_gmt_time_for_time_zone(
    'l, F jS g:ia', 
    $myGMTTimestamp,
    'America/Los Angeles');</code></pre>

<p>or even better, using and object oriented approach:</p>

<pre><code>$string = $date->Format(
    'l, F jS g:ia', 
    'America/Los Angeles');</code></pre>

<p>It&#8217;s important because it&#8217;s kind of a &#8220;best practice&#8221; to store dates in the database in GMT (or really UTC) format and then translate them as necessary. Then I want someone in New York to see times in their time zone and also someone in Seattle. It would also help if WordPress had a per user time zone.</p>

<p>I know that PHP 6 is doing some enhanced date stuff, so hopefully that will include this simple functionality. But right now, both WordPress and PHP don&#8217;t seem to imaging a case where someone wants to print out a time for a timezone they&#8217;re not in.</p>

<p>What I ended up doing was this:</p>

<pre><code>$oldTimeZone = date_default_timezone_get();

date_default_timezone_set($requestedTimeZone));
        
$convertedString = date($formatString, $gmtTimestamp);
        
date_default_timezone_set($oldTimeZone);
        
return $convertedString;</code></pre>

<p>It works, but it&#8217;s fairly clunky. From my experience at Microsoft I know sometimes when there&#8217;s a whole category of things that needs improving, it can be hard to find someone to take that on. What has to happen is a person needs to say, &#8220;I&#8217;m going to take on times and dates and make the API better.&#8221; But either people aren&#8217;t interesting or people are too afraid to suggest such a drastic move. Furthermore, the people who wrote the original code will often be offended that someone would suggest it could be better. They will point to something like my code above an say that&#8217;s good enough. It isn&#8217;t.</p>

<p>I&#8217;m actually considering getting involved with WordPress on this, however, I am honestly scared that they will not be into it. I&#8217;d also like to add the per user time zone, but I sense something like that would be controversial.</p>]]></content:encoded>
			<wfw:commentRss>http://designoplasty.com/2010/01/16/wordpress-and-php-have-poor-support-for-dates-and-time-zones/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Swift Mailer: Awesome PHP Mailer</title>
		<link>http://designoplasty.com/2010/01/02/swift-mailer-awesome-php-mailer/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=swift-mailer-awesome-php-mailer</link>
		<comments>http://designoplasty.com/2010/01/02/swift-mailer-awesome-php-mailer/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 06:44:57 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://designoplasty.com/?p=1133</guid>
		<description><![CDATA[

Tonight was the first time that I needed to write some code for a business that would send email to customers, or at least email that needed to be reliable and feature rich. I looked at the documentation for the PHP mail function and after a lot of reading realized it was not going to [...]]]></description>
			<content:encoded><![CDATA[<img src="http://photos.smugmug.com/photos/756037510_FDz8e-O.png" class="floatright" style="width: 181px; height: 68px;" alt="Swift Mailer PHP emailer" />

<p>Tonight was the first time that I needed to write some code for a business that would send email to customers, or at least email that needed to be reliable and feature rich. I looked at the documentation for the PHP mail function and after a lot of reading realized it was not going to work. If I wanted to use HTML, that involved a lot of uncertainty, if I wanted to use UTF-8, that involved a lot of uncertainty. There were a lot of unknowns but one thing that was quickly becoming a known was that I was not going to fix this problem.</p>

<p>I knew I could send simple text emails with a URL to details if I had to, but before I did that, I wondered if someone else had solved my problem since what I wanted was reasonable and obvious. To my great surprise a few people had. It came down to two tools, <a href="http://swiftmailer.org/">Swift Mailer</a> and <a href="http://phpmailer.worxware.com/">PHP Mailer</a>.</p>

<p>After doing some Google searches and research, it became clear that <a href="http://swiftmailer.org/">Swift Mailer</a> was probably going to be better for me. And the reasons why are big lessons for PHP Mailer. <a href="http://swiftmailer.org/">Swift Mailer</a> had a nice simple website, they had one product, and they had a download link on the front page. Right off the bat, it was looking simple. On the other hand PHP Mailer has four products which I would have to investigate to find out which one was right for me. Their home page is a mess that for some reason seems to focus on ads for other people&#8217;s products along with tons of text about who knows what. It would take me hours just to parse the homepage.</p>

<p>But, what took it over the edge was that <a href="http://swiftmailer.org/">Swift Mailer</a> has a beautiful object oriented design to their API and they talk about that being a goal, they have full easy to understand documentation, installation is a breeze, as it should be, all while offering an incredibly feature rich product. Swift Mailer wins by a mile.</p>

<p>Was it as easy as it looked? Well, in about an hour I had built a WordPress plugin that would include <a href="http://swiftmailer.org/">Swift Mailer</a>&#8217;s functionality in my blog on demand. I had added code to another plugin to enable Swift Mailer at the right time and send an email from one Gmail account to another using Gmail&#8217;s smtp server with a secure connection over SSL.</p>

<p>One hour.</p>

<p>I literally copied the code over and changed the important bits. I had one issue where Gmail didn&#8217;t like the port the Swift Mailer docs used for SSL, but the Gmail docs listed the alternative port and things worked perfectly.</p>

<p>Furthermore, there are tons of features of <a href="http://swiftmailer.org/">Swift Mailer</a> that will actually inspire me to do more with email.</p>

<p>Kudos to the <a href="http://swiftmailer.org/">Swift Mailer</a> team, you&#8217;ve really created a great product and you are a poster project for open source. Thank you!</p>
]]></content:encoded>
			<wfw:commentRss>http://designoplasty.com/2010/01/02/swift-mailer-awesome-php-mailer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTAccess RewriteRule, When it Changes the URL in the Address Bar</title>
		<link>http://designoplasty.com/2009/12/24/htaccess-rewriterule-when-it-changes-the-url-in-the-address-bar/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=htaccess-rewriterule-when-it-changes-the-url-in-the-address-bar</link>
		<comments>http://designoplasty.com/2009/12/24/htaccess-rewriterule-when-it-changes-the-url-in-the-address-bar/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 02:04:57 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[HTAccess]]></category>
		<category><![CDATA[RewriteRule]]></category>
		<category><![CDATA[Web Servers]]></category>

		<guid isPermaLink="false">http://designoplasty.com/?p=1118</guid>
		<description><![CDATA[I have been trying to figure this out for ages. When will RewriteRule change the URL in the browser address bar? Today I read thought the whole Apache mod_rewrite documentation page and I still didn&#8217;t know the answer. But after a ton of searching I finally figured it out, and hope to explain it to [...]]]></description>
			<content:encoded><![CDATA[<p>I have been trying to figure this out for ages. When will RewriteRule change the URL in the browser address bar? Today I read thought the whole <a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html">Apache mod_rewrite documentation page</a> and I still didn&#8217;t know the answer. But after a ton of searching I finally figured it out, and hope to explain it to you the way I wish someone would have explained it to me from the beginning. </p>

<p>To start off, I think part of the reason this isn&#8217;t explained in a more upfront manner is because the writers of the documentation don&#8217;t really think it&#8217;s a valid question. Yes, if you&#8217;re where I was this morning that sounds ridiculous, and it is, but now I can understand their point of view.</p>

<p>The first rule of RewriteRule is:</p>

<blockquote>RewriteRule never &#8220;changes&#8221; the URL in the user&#8217;s browser window.</blockquote>

<p>Right now you&#8217;re probably saying no way, you&#8217;ve seen it happen, so you know it must be happening somehow. The end result is happening, you are correct, but it&#8217;s not happening the way you might think. RewriteRule does not say to the browser, &#8220;Please change the URL in the address bar to this.&#8221; Instead, sometimes RewriteRule says, &#8220;Oh, the page you&#8217;re looking for doesn&#8217;t exist, try this one instead.&#8221; This is called a redirection.</p>

<h3>Rewrite versus Redirection</h3>

<p>This is a very important distinction to most of us, but it is sort of glossed over in the Apache documentation because its writers forgot how revolutionarily important it is.</p>

<p>A rewrite is when Apache says, &#8220;OK, I am going to handle your request, and internally I am going to change the URL to this other URL. You are never going to see that other URL, but that is the URL that is going to be processed. You will continue to see whatever it is you typed in your browser&#8217;s address bar.&#8221;</p>

<p>A redirection is when Apache says, &#8220;Oh, I recognize that I can&#8217;t help you with this request, I suggest you ask for this URL instead.&#8221; After it says this, it&#8217;s done with you, the request is completely finished, and it has forgotten you ever existed. Your browser, however, receives this information and says, &#8220;Well if they suggest a different URL, I guess I&#8217;ll do my user a favor and request that URL next. Oh, and so my user knows what&#8217;s going on I&#8217;ll change the URL in the address bar.&#8221; Next your browser makes a whole separate request with the new URL. The brand new request is received by the web server and processed. The web server has no knowledge that these two requests are in any way related, and the web server certainly isn&#8217;t the one who changed the URL in the address bar of your browser.</p>

<p>This is a big deal! It&#8217;s totally lost on the writers of the Apache documentation. Because now you know you can effectively do the two things you want to do: change the URL internally or change the URL externally (or both, but in two steps.)</p>

<h3>The Code</h3>

<p>So what&#8217;s the difference between a rewrite and a redirect? One letter: R.</p>

<h4>Rewrite</h4>

<pre><code>RewriteRule ^/cars/acura /cars/honda</code></pre>

<p>Users who request the URL /cars/acura will still see /cars/acura in their address bar but they&#8217;ll see the content as if they had requested /cars/honda. (This is just an example and would lead to duplicate content warnings in Google because two different pages would have the same content.)</p>

<p>A better example:</p>

<pre><code>RewriteRule ^/cars/(.*) /cars.php?make=$1 [QSA]</code></pre>

<p>This will internally rewrite requests to /cars/acura to /cars.php?make=acura so you can pretty up your URL structure. It will handle those requests at the same time. The QSA stands for &#8220;Query String Append&#8221; and means that if the URL came in with additional query string info that will also be appended, not lost.</p>

<h4>Redirect</h4>

<pre><code>RewriteRule ^/cars/acura /cars/honda [R]</code></pre>

<p>This is the exact same example as the first example above except for the [R]. The R says, do a redirect which means once Apache is done processing the RewriteRule directives, it will stop processing the request and send the redirect message back to the browser as we discussed at the beginning of this post. This means the browser will most likely change the URL in the address bar and make a new request. There will be two web server requests, which are totally unrelated as far as the web server is concerned.</p>

<p>I should say, for the record, that normally the above code would be written as:</p>

<pre><code>RewriteRule ^/cars/acura /cars/honda [R=301,L]</code></pre>

<p>By default R returns code 302, meaning &#8220;moved temporarily&#8221; which isn&#8217;t often what people like you and me want. We want 301, meaning &#8220;moved permanentaly&#8221; which will also direct search engines to update their URL. The L means if a URL has matched this directive, do the redirect immediately and don&#8217;t process any more directives. Most of the time we don&#8217;t have complex sets of directives that all need to be processed, so just get out early to improve performance.</p>

<h3>More on Redirects</h3>

<p>I won&#8217;t go into detail here, but there are more things than just [R] that will force a redirect, for instance if you&#8217;ve given a substitution URL on another domain. Read the docs for more of those types of situations.</p>

<h3>Conclusion</h3>

<p>Hopefully this has been as helpful to you as finally figuring this out has been to me. It feels so good to finally have a good grasp on this topic.</p>


]]></content:encoded>
			<wfw:commentRss>http://designoplasty.com/2009/12/24/htaccess-rewriterule-when-it-changes-the-url-in-the-address-bar/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Making the body Element Take Up At Least 100 Percent of the html Height</title>
		<link>http://designoplasty.com/2009/12/24/making-the-body-element-take-up-at-least-100-percent-of-the-html-height/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=making-the-body-element-take-up-at-least-100-percent-of-the-html-height</link>
		<comments>http://designoplasty.com/2009/12/24/making-the-body-element-take-up-at-least-100-percent-of-the-html-height/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 09:27:32 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://designoplasty.com/?p=1107</guid>
		<description><![CDATA[Here was my problem, I had some divs absolutely positioned at the top and bottom of the body element and I needed the div at the bottom to be at the bottom of the window even if the body wasn&#8217;t tall enough to reach the bottom of the window. Here&#8217;s the solution:

*
{
    [...]]]></description>
			<content:encoded><![CDATA[<p>Here was my problem, I had some divs absolutely positioned at the top and bottom of the <code>body</code> element and I needed the div at the bottom to be at the bottom of the window even if the body wasn&#8217;t tall enough to reach the bottom of the window. Here&#8217;s the solution:</p>

<pre><code>*
{
    margin: 0px;    /* I include this just because I always do it and for this */
    padding: 0px;   /* example it will ensure the bottom is truly the bottom. */
}

html
{
    height: 100%;
}

body
{
    min-height: 100%;
}</code></pre>

<p>I&#8217;m not entirely sure why the <code>html</code> element has to have a height of 100%, but it does. What&#8217;s interesting is if you apply a background to the html element it will fill the whole viewport, maybe the extra space is considered padding or something.</p>

<p>Some other examples on the web for other things will show the <code>body</code> having a height of 100% instead of min-height. This will put any absolutely position elements on the bottom at the bottom of the viewport instead of the bottom of the <code>body</code>.</p>]]></content:encoded>
			<wfw:commentRss>http://designoplasty.com/2009/12/24/making-the-body-element-take-up-at-least-100-percent-of-the-html-height/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using PHP Class Methods as WordPress Action Hook Callbacks</title>
		<link>http://designoplasty.com/2009/11/20/using-php-class-methods-as-wordpress-action-hook-callbacks/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-php-class-methods-as-wordpress-action-hook-callbacks</link>
		<comments>http://designoplasty.com/2009/11/20/using-php-class-methods-as-wordpress-action-hook-callbacks/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 08:46:04 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://designoplasty.com/?p=1058</guid>
		<description><![CDATA[Using object oriented code is a must for me. Object oriented code is more than just organization of the code, it&#8217;s organization of one&#8217;s thinking. I wanted to talk about using static class methods as handlers for WordPress actions. This is important to me because often my plugins are implemented as a class.

add_action('init', 'MyPlugin::Init');

class MyPlugin
{
 [...]]]></description>
			<content:encoded><![CDATA[<p>Using object oriented code is a must for me. Object oriented code is more than just organization of the code, it&#8217;s organization of one&#8217;s thinking. I wanted to talk about using static class methods as handlers for WordPress actions. This is important to me because often my plugins are implemented as a class.</p>

<pre><code>add_action('init', 'MyPlugin::Init');

class MyPlugin
{
    public static function Init()
    {
        // Put Some Code Here
    }
}</code></pre>

<p>Pretty easy. What I really like about this is that the class name acts as a namespace, so I can use the simple function name <code>Init</code> instead of naming my function something annoying like <code>myplugin_init</code>.</p>

<p>I use this pattern all the time to initialize an instance of the class so that it can be used elsewhere, such as in a theme:</p>

<pre><code>add_action('init', 'MyPlugin::Init');

class MyPlugin
{
    private $userName = null;

    public static function Init()
    {
        global $myPlugin;

        $myPlugin = new MyPlugin();

        // The following line would probably go into a 
        // constructor method and get the real current
        // user name.

        $myPlugin->userName = 'bob';
    }

    pubic function GetUserName()
    {
        return $this->userName;
    }
}</code></pre>

<p>Then any other non-plugin code, like a theme for instance, can detect the presence of the plugin and use it.</p>

<pre><code>global $myPlugin;

if (isset($myPlugin))
{
    echo 'MyPlugin is installed, ', $myPlugin->GetUserName();
}</code></pre>

<p>Happy Coding!</p>]]></content:encoded>
			<wfw:commentRss>http://designoplasty.com/2009/11/20/using-php-class-methods-as-wordpress-action-hook-callbacks/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP, Classes, Camel Case, and Underlines</title>
		<link>http://designoplasty.com/2009/11/18/php-classes-camel-case-and-underlines/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=php-classes-camel-case-and-underlines</link>
		<comments>http://designoplasty.com/2009/11/18/php-classes-camel-case-and-underlines/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 23:40:30 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Camel Case]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming Languanges]]></category>

		<guid isPermaLink="false">http://designoplasty.com/?p=1051</guid>
		<description><![CDATA[When I first started PHP programming, I wrote code like the PHP inventors wrote code, using lowercase characters and underlines, like:

$my_favorite_variable = 5;

function add_numbers($first_number, $second_number)
{
    return $first_number + $second_number;
}

$answer = add_numbers($my_favorite_variable, 1);

But this became tiresome. The thing is, the underscore character is harder to type and using all lowercase really makes the [...]]]></description>
			<content:encoded><![CDATA[<p>When I first started PHP programming, I wrote code like the PHP inventors wrote code, using lowercase characters and underlines, like:</p>

<pre><code>$my_favorite_variable = 5;

function add_numbers($first_number, $second_number)
{
    return $first_number + $second_number;
}

$answer = add_numbers($my_favorite_variable, 1);</code></pre>

<p>But this became tiresome. The thing is, the underscore character is harder to type and using all lowercase really makes the code blur together at a glance. Also, it&#8217;s harder to tell the difference between variables and function names. After writing code at Microsoft for many years, I know that camel case is the way to go. Even Apple uses camel case. Modern C programming uses camel case. The PHP inventors made a mistake when using all those underscores.<p>

<p>Using camel case and adding in classes, the code becomes so much cleaner:</p>

<pre><code>$myFavoriteVariable = 5;

class Calculator
{
    public static function Add($firstNumber, $secondNumber)
    {
        return $firstNumber + $secondNumber;
    }
}

$answer = Calculator::Add($myFavoriteVariable, 1);</code></pre>

<p>Doesn&#8217;t that look better? We&#8217;re at this point in history where we&#8217;ve pretty much figured out that for all languages camel case it the easiest to read. Start variables with lowercase, classes and methods with uppercase and it looks so nice.</p>

<p>Having said that, every time I start to work on something I haven&#8217;t touched in a while there&#8217;s a flurry of code refactoring, but it feels so good to get that done. And it&#8217;s so much easier to read.</p>
]]></content:encoded>
			<wfw:commentRss>http://designoplasty.com/2009/11/18/php-classes-camel-case-and-underlines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Function do_action &#8211; Very Useful</title>
		<link>http://designoplasty.com/2009/10/21/wordpress-function-do_action-very-useful/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=wordpress-function-do_action-very-useful</link>
		<comments>http://designoplasty.com/2009/10/21/wordpress-function-do_action-very-useful/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 06:01:54 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Themes]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://designoplasty.com/?p=1001</guid>
		<description><![CDATA[Today, well, really the last few days have been incredibly productive and incredibly hectic. I finished up some complex code for a customer and ever since then I&#8217;ve had so many epiphanies that I&#8217;ve practically been typing constantly ever since. I will say that I really like when I am inspired like this, but I [...]]]></description>
			<content:encoded><![CDATA[<p>Today, well, really the last few days have been incredibly productive and incredibly hectic. I finished up some complex code for a customer and ever since then I&#8217;ve had so many epiphanies that I&#8217;ve practically been typing constantly ever since. I will say that I really like when I am inspired like this, but I will also say that I kind of don&#8217;t like it. I&#8217;ve had a list of really good ideas forcing their way out and it&#8217;s very hard to keep up with them. This is kind of how software development works, though. You take some time to ponder ideas or let ideas rest and then one day it all comes together into lots of actionable items you want to do all at once.</p>

<p>One of the many things I&#8217;ve found useful over the past couple of days has been the WordPress function <code>do_action</code>. I have a base theme that I repurpose for all of my websites. I really try to keep it flexible enough to do just about anything. Sometimes that can be difficult, but <code>do_action</code> really helps. You can  place <code>do_action</code> calls throughout your theme files in handy places and then customize your theme outside of your standard theme files using the <code>add_action</code> function. If you don&#8217;t customize, everything works fine, but if you do, you can do it in a different file so you don&#8217;t have to modify the core theme files.</p>

<p>Obviously, this paradigm is used throughout WordPress in many different ways, and I have been a &#8220;consumer&#8221; of it many times. But it wasn&#8217;t until recently that I realized how much this could help me with my many different themes and save so much time. Or at least it will, after this exhausting week is over!</p>]]></content:encoded>
			<wfw:commentRss>http://designoplasty.com/2009/10/21/wordpress-function-do_action-very-useful/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery.post Recursion, or not&#8230;</title>
		<link>http://designoplasty.com/2009/09/18/jquery-post-recursion-or-not/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=jquery-post-recursion-or-not</link>
		<comments>http://designoplasty.com/2009/09/18/jquery-post-recursion-or-not/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 08:45:01 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://designoplasty.com/?p=980</guid>
		<description><![CDATA[Today I spent some time making some data import code work better.

At the start of the process I had a PHP function that I would call to import some data. The problem is, that process would take longer than 30 seconds after which it would time out. A while ago, I changed the function to [...]]]></description>
			<content:encoded><![CDATA[<p>Today I spent some time making some data import code work better.</p>

<p>At the start of the process I had a PHP function that I would call to import some data. The problem is, that process would take longer than 30 seconds after which it would time out. A while ago, I changed the function to stop itself after 20 seconds. The result was an administrative web page where you had to hit an &#8220;update&#8221; button multiple times, waiting for 20 seconds each time.</p>

<p>My dream of dreams was to have this function work via AJAX instead and just update one record, return with status indicating how much work was left and then do another. I did this with the JQuery.post method. This is using the WordPress admin AJAX functionality.</p>

<pre><code>cancelProcess = false;

function ImportOneRecord()
{

    jQuery.post(
        '/wp-admin/admin-ajax.php', 
        {
            'action': 'ImportOneRecord'
        },
        function (data)
        {
            if (data.succeeded 
                &#038;&#038; (data.recordsLeftToImport > 0) 
                &#038;&#038; !cancelProcess)
            {
                // Update Status
                jQuery('#statusBox').html(data.status);

                // Do It Again
                ImportOneRecord();
            }
        },
        'json');

}</code></pre>

<p>My initial concern was one of stack overflows, but then I realized that the asynchronous nature of AJAX takes care of that. When this function runs, it doesn&#8217;t block. It sends the AJAX request that lives out in the ether and when that request receives a response, it runs my event handler. When that event handler runs it doesn&#8217;t block either, meaning it can be released. But when it did run, it created another AJAX request that also lives in the ether. Nothing is hanging onto it.</p>

<p>This function made it through thousands of records and I&#8217;m not sure how big the JavaScript stack is, but it didn&#8217;t overflow. I think it&#8217;s because like I thought, that&#8217;s not an issue here. There is no stack build up. This is just a very very complex loop&hellip; I think.<?p>]]></content:encoded>
			<wfw:commentRss>http://designoplasty.com/2009/09/18/jquery-post-recursion-or-not/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Plugins and AJAX</title>
		<link>http://designoplasty.com/2009/09/14/wordpress-plugins-and-ajax/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=wordpress-plugins-and-ajax</link>
		<comments>http://designoplasty.com/2009/09/14/wordpress-plugins-and-ajax/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 04:36:55 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://designoplasty.com/?p=967</guid>
		<description><![CDATA[The last couple of days I&#8217;ve been doing a ton of AJAX programming on some WordPress plugins. Wordpress actually does have one very handy AJAX feature that makes using AJAX just a little easier. I also use jQuery because it&#8217;s really nice for a lot of things including AJAX work.

AJAX is a great technology, and [...]]]></description>
			<content:encoded><![CDATA[<p>The last couple of days I&#8217;ve been doing a ton of AJAX programming on some WordPress plugins. Wordpress actually does have <a href="http://codex.wordpress.org/AJAX_in_Plugins">one very handy AJAX feature</a> that makes using AJAX just a little easier. I also use jQuery because it&#8217;s really nice for a lot of things including AJAX work.</p>

<p>AJAX is a great technology, and while I know what I&#8217;m doing, sometimes even I am amazed at how difficult it is. You&#8217;ve got HTML, Javascript, PHP, and usually database tables to get right. If any one of those isn&#8217;t working it won&#8217;t work.</p>

<p>If you don&#8217;t already have good debugging skills, I wouldn&#8217;t even try it. I very much try to integrate my debugging in with my development to save time. For instance, I have a function that checks to make sure a database call went OK. If not it sends an ajax response with the query and the error string. My calls to AJAX are always prepared to receive and display that error. Even my CSS for the page even handles displaying the returned error string in the most clear way possible. This is code I can use again and again in all my plugins, and if I didn&#8217;t reuse it I would never get anything done..</p>

<p>Now that I&#8217;m getting it down, it&#8217;s so nice. I love AJAX. But the more I work on the web the more I see we need a replacement for JavaScript. I mean most of the language is fine, but it needs to be a real language with the standard object oriented features implemented in the standard way: class, public, private, protected, property getters and setters, etc. The prototype keyword needs to be completely removed from the language. JavaScript and PHP need to align such that AJAX is a natural part of both languages. It&#8217;s possible, but the web is a funny thing and its technologies have a heck of a time moving forward.</p>
]]></content:encoded>
			<wfw:commentRss>http://designoplasty.com/2009/09/14/wordpress-plugins-and-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Counters</title>
		<link>http://designoplasty.com/2009/09/05/mysql-counters/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=mysql-counters</link>
		<comments>http://designoplasty.com/2009/09/05/mysql-counters/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 03:24:22 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://designoplasty.com/?p=940</guid>
		<description><![CDATA[Today I went to Panera (free wi-fi) to get some work done away from the distraction of my dachshund. I&#8217;m changing a lot of my PHP code to use classes, and needed to focus. After enjoying some soup on a bread bowl (it must be fall) I started working.

I didn&#8217;t get far. I realized what [...]]]></description>
			<content:encoded><![CDATA[<p>Today I went to Panera (free wi-fi) to get some work done away from the distraction of my dachshund. I&#8217;m changing a lot of my PHP code to use classes, and needed to focus. After enjoying some soup on a bread bowl (it must be fall) I started working.</p>

<p>I didn&#8217;t get far. I realized what I needed was a thread-safe counter. Simply a function that spits out numbers one after the other, and absolutely positively guarantees it will not give out the same number more than once. I know how to do this many different ways using many different languages, but I wasn&#8217;t sure of the best way to do it using WordPress, PHP, and MySQL.</p>

<p>MySQL does have auto increment where if you add a row to a table it will make give a field a value that&#8217;s incremented. This is atomic, but I didn&#8217;t need a new row in a table, I just needed the number.</p>

<p>I figured I could store the number in a text file and have PHP use file write protections to do the locking I needed to make it atomic, but the performance would not be that great for such a simple task.</p>

<p>I thought I could create a simple table with the number in a row, and use MySQL table locking to accomplish this. For a while, I had settled on that plan, but something made me think there must be a better way.</p>

<p>I went about researching the MySQL update statement. It turns out that doing this is atomic.</p>

<pre><code>UPDATE plugin_counters
    SET counter_value = counter_value + 1 
    WHERE counter_name = 'invoice_id';</code></pre>

<p>But the problem is how to get that value before this happens again. Apparently you can just add one more expression to the WHERE clause.</p>

<pre><code>UPDATE plugin_counters
    SET counter_value = counter_value + 1 
    WHERE counter_name = 'invoice_id'
        AND @value := counter_value;</code></pre>

<p>This expression will always return true and will place the original value of counter_value into the MySQL variable @value.</p>

<p>I spent a good deal of time trying to verify that this is absolutely positively atomic and it seems to be. Even naysayers were accepting this to be atomic while pointing out that longer updates would not be atomic if the database crashed in the middle of the update. So to me, this means they&#8217;re saying as long as the database doesn&#8217;t crash, it&#8217;s atomic, which is good enough for me.</p>

]]></content:encoded>
			<wfw:commentRss>http://designoplasty.com/2009/09/05/mysql-counters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ECMAScript is Junk, JavaScript Sucks</title>
		<link>http://designoplasty.com/2009/08/25/ecmascript-is-junk-javascript-sucks/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=ecmascript-is-junk-javascript-sucks</link>
		<comments>http://designoplasty.com/2009/08/25/ecmascript-is-junk-javascript-sucks/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 01:48:20 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://designoplasty.com/?p=901</guid>
		<description><![CDATA[

I just watched this video to see what was coming up in ECMAScript 5. What this video taught me is the JavaScript is junk and that design by committee always leads to bad solutions.

When looking at some of the ridiculous code examples in this video, I just couldn&#8217;t believe it. It is so difficult just [...]]]></description>
			<content:encoded><![CDATA[<object width="640" height="505" class="centerblock frame"><param name="movie" value="http://www.youtube.com/v/Kq4FpMe6cRs&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Kq4FpMe6cRs&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object>

<p>I just watched this video to see what was coming up in ECMAScript 5. What this video taught me is the JavaScript is junk and that design by committee always leads to bad solutions.</p>

<p>When looking at some of the ridiculous code examples in this video, I just couldn&#8217;t believe it. It is so difficult just to create an object with private typed variables. They aren&#8217;t doing anything to fix that, in fact they might be making it worse. Yes, they have technically made it possible, but they have practically made it impossible. Is it so bad to want to type:</p>

<pre><code>object Point
{
    Int32 x;
    Int32 y;

    Point(Int32 x, Int32 y)
    {
        this.x = x;
        this.y = y;
    }
}</code></pre>

<p>That is essentially JavaScript. Maybe it only works in &#8220;strict mode&#8221; I don&#8217;t care. But what they are doing makes the code for that look like complete garbage. All the things they&#8217;re whining about have already been solved, and years ago. Just use what already works! Stop reinventing the wheel as a square and telling me I just need to be on a really steep hill to use it.</p>

<p>I&#8217;m so tired of these crappy web programming languages and at this point I wish someone would just port C to be a scripting language. I have no idea how I would even begin such a process, but the problems with JavaScript are so bad for any good programmers, that I think someone needs to do something.</p>
]]></content:encoded>
			<wfw:commentRss>http://designoplasty.com/2009/08/25/ecmascript-is-junk-javascript-sucks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
