<?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>Gregory Koberger :: the blog &#187; Programming</title>
	<atom:link href="http://www.blog.gkoberger.net/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blog.gkoberger.net</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 30 Jul 2010 00:56:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.2</generator>
		<item>
		<title>PCMP Lesson 1: Easy Isn&#8217;t Easy</title>
		<link>http://www.blog.gkoberger.net/2010/02/22/pcmp-lesson-1-easy-isnt-easy/</link>
		<comments>http://www.blog.gkoberger.net/2010/02/22/pcmp-lesson-1-easy-isnt-easy/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 07:01:39 +0000</pubDate>
		<dc:creator>Gregory</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Usability]]></category>

		<guid isPermaLink="false">http://www.blog.gkoberger.net/?p=120</guid>
		<description><![CDATA[Over the weekend, I created a small app called PleaseCallMyPhone.com.  It does just that- it calls your phone.  I made it as a remedy for lost phones, however it is simple enough that you could use it for other things.  It only took me a day to make, however I wanted to share a few [...]]]></description>
			<content:encoded><![CDATA[<p><em>Over the weekend, I created a small app called </em><em><a href="http://pleasecallmyphone.com" target="_blank">PleaseCallMyPhone.com</a>.  It does just that- it calls your phone.  I made it as a remedy for lost phones, however it is simple enough that you could use it for other things.  It only took me a day to make, however I wanted to share a few quick lessons I learned from making it.</em></p>
<p><em><span style="font-style: normal;">A few weeks ago, I was talking to <a href="http://ericwillis.com">Eric Willis</a> and he said something I really liked:</span></em></p>
<blockquote><p><em><span style="font-style: normal;">Everything that&#8217;s easy isn&#8217;t if you do a good job.</span></em></p></blockquote>
<p><em><span style="font-style: normal;">Take a look at Please Call My Phone.  I used <a href="http://twilio.com">Twilio</a> (my super-easy-to-use <a href="http://www.blog.gkoberger.net/2010/01/08/amature-evangelists/">obsession</a>), which did most of the heavy lifting.  In fact, I got a &#8220;prototype&#8221; working in about ten minutes.  So, then, why did it take me a whole day to get the finished product out the door?</span></em></p>
<p><em><span style="font-style: normal;">It&#8217;s the little things that take the time.  The <a href="http://en.wikipedia.org/wiki/Pareto_principle" target="_blank">Pareto principle</a> plays a big part in it- 20% of the work always does seem to take up at least 80% of the time.</span></em></p>
<p><em><span style="font-style: normal;">My original, ten minute version had just a text box that called a phone.  Every little tweak and change took time, though.  Each little addition (scheduling, the design, better error handling, link to my site and Twilio link, JavaScript enhancements, etc) added up quickly.</span></em></p>
<p>There are a lot of hidden time sinks, too.  Take a look at scheduling, for example- little things like handling time zones took a ton of time, and nobody will even notice.</p>
<p>People notice when something is done wrong, not when it is done right.</p>
<p><em><span style="font-style: normal;">So, remember- if what you&#8217;re doing is quick and easy, you&#8217;re probably not doing a good enough job.</span></em></p>
<p><em><a href="http://www.blog.gkoberger.net/2010/02/26/pcmp-lesson-2-you-cant-trust-people/" target="_self">Lesson #2</a></em><em> and Lesson #3 will be posted soon.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.gkoberger.net/2010/02/22/pcmp-lesson-1-easy-isnt-easy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hire Developers</title>
		<link>http://www.blog.gkoberger.net/2009/08/14/hire-developers/</link>
		<comments>http://www.blog.gkoberger.net/2009/08/14/hire-developers/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 07:00:33 +0000</pubDate>
		<dc:creator>Gregory</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.blog.gkoberger.net/?p=53</guid>
		<description><![CDATA[I&#8217;m biased.  As a developer, of course I am pro-developer.  However, I don&#8217;t see any reason why you shouldn&#8217;t hire a developer for as many positions as possible.  They don&#8217;t have to be the worlds greatest programmers, they just need a solid understanding of how to do things on their own. All companies have little [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m biased.  As a developer, of course I am pro-developer.  However, I don&#8217;t see any reason why you shouldn&#8217;t hire a developer for as many positions as possible.  They don&#8217;t have to be the worlds greatest programmers, they just need a solid understanding of how to do things on their own.</p>
<p>All companies have little (yet important) tasks for developers.  Gathering statistics, setting up ads, doing A/B tests.  And rather than taking one person X amount of time, it takes two people that same X amount of time.  These things are slightly too hard for non developers (HTML? Databases?), but a time-suck for developers working on bigger projects.</p>
<p>With any decent-sized company, everyone has little jobs for the developers.  These jobs pile up- the developers have to spend time doing these tasks, while everyone else loses time waiting for them.</p>
<p>So, why not hire a developer to do that sales, project management, analytics, or marketing in the first place?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.gkoberger.net/2009/08/14/hire-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: MVC By Nature?</title>
		<link>http://www.blog.gkoberger.net/2009/07/27/php-mvc-by-nature/</link>
		<comments>http://www.blog.gkoberger.net/2009/07/27/php-mvc-by-nature/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 07:00:47 +0000</pubDate>
		<dc:creator>Gregory</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.blog.gkoberger.net/?p=45</guid>
		<description><![CDATA[After spending hours upon hours fighting with frameworks, I got fed up.  They are certainly tempting, since they take care of the initial structuring of your program.  However, once you get past that- what do they bring to the table?  Are they really worth the inevitable aggravation? Some people will have thought about this thoroughly, [...]]]></description>
			<content:encoded><![CDATA[<p>After spending hours upon hours fighting with frameworks, I got fed up.  They are certainly tempting, since they take care of the initial structuring of your program.  However, once you get past that- what do they bring to the table?  Are they really worth the inevitable aggravation?</p>
<p>Some people will have thought about this thoroughly, and come to a different conclusion than me.  Others will have just a gut reaction to me saying that procedural programming still has a place in PHP.  Either way, a lot of people are going to disagree.</p>
<p>So, with that, here goes my argument that PHP is already MVC-ready.</p>
<p><strong>Views</strong></p>
<p>PHP is unique from many compiled, desktop-centric languages in that all presentation is done using a separate language (a markup language, but a language none the less).  Short of XML output and the like, all PHP needs to be <em>echo</em>&#8216;d and <em>print</em>&#8216;d out among longhand HTML.  Even in my earliest, blissfully-ignorant-to-MVC days, it was apparent that it made more sense to separate the HTML from the PHP.  (Of course, there is a subtle  yet distinct difference between separating the PHP from the HTML, and the logic from the presentation- but remember, I was still MVC-ignorant back then). A simple <em>include</em> does the job.  So, why do we need a framework to do this for us?</p>
<p>Of course, you could argue the <a href="http://www.prodevtips.com/2008/02/05/why-php-as-a-templating-language-sucks/" target="_blank">merits</a> or <a href="http://www.massassi.com/php/articles/template_engines/" target="_blank">disadvantages</a> of using a templating engine like Smarty, but the point is moot- none of the major PHP frameworks really have any templating features beyond what an include can do.</p>
<p><strong>Models</strong></p>
<p>Models are covered by objects- they take care of the data.  More often than not, the job of the model is to convert raw data (often from a database) into something the controller can work with.  Models take care of the tedious business logic, creating a bridge between the data and the code.  Writing out SQL statements in the controller quickly gets messy- models make it easy to keep the data all in sync, across the entire program.</p>
<p>One thing that has always bugged me is that in frameworks, you have to load a model before you can use it.  Why?  With PHP, you can <a href="http://us3.php.net/manual/en/language.oop5.autoload.php">automate</a> this- going through a framework just makes debugging even harder.  That&#8217;s not to say that extending a generic Model class can&#8217;t help your models- however, we don&#8217;t need a full <em>framework</em> for that.</p>
<p><strong>Controller</strong></p>
<p>With me so far?  Well, here is where I will probably lose you.</p>
<p>First, let&#8217;s make something clear. I can&#8217;t say enough good things about OOP- so I&#8217;m not even going to bother trying.  Barring &#8220;Hello World,&#8221; I can&#8217;t think of a single program that would not benefit from OOP.</p>
<p>However, here&#8217;s a quote from Rasmus Lerdorf (the creator of PHP):</p>
<blockquote><p><span>PHP has traditionally been a procedural language, and OOP features have crept in over the years to the point where PHP can be used as a decent OOP language.</span></p></blockquote>
<p>I never understood why we are so fond of using OOP for the controller portion of MVC.  I understand the arguments for it- however, given the bland, generic way frameworks currently utilize OOP in controllers, it seems it is used more for the sake of being object oriented than because it is the right tool for the job.</p>
<p>How about this for an alternative: One index.php file, that takes care of routing.  It can be more flexible, in my opinion, than the regex-based routing implementations in most frameworks.  Yes, I do agree that programming is easier when we can look at a URL and instantly know the class and method the code is in.  However, I also feel there&#8217;s merit in dropping the &#8220;automagic&#8221; that happens when a framework handles our routing. (And honestly, I&#8217;ve never worked on a framework based project that had a URL structure that mapped directly to the class-defined structure anyway.)</p>
<p>If we do it this way, we can move the structure from the classes to actual folders.  We can split the PHP up among a bunch of smaller, procedural files.  On top of that, if we commit to mirroring the URL structure, we don&#8217;t lose anything in the way of navigating code.</p>
<p><strong>Libraries and Helpers<br />
</strong></p>
<p>In the spirit of not reusing code, we can still make liberal use of libraries and helpers- basically, classes or functions that handle any code we may need to use more than once.  These would have to be <em>include</em>&#8216;d on a use-by-use basis, of course- but how hard is that?</p>
<p>In my opinion, the biggest problem with frameworks is they&#8217;re not very good at letting you do things your way.  For a team of inexperienced or lazy programmers?  This is great, as it makes sure everyone is on the same page and does things the &#8220;right&#8221; way.  However, more often than not, I find it annoying that I&#8217;m suck doing things the frameworks&#8217; way.</p>
<p>JavaScript framework/libraries have it right- you can use them as much as you want, but if for whatever reason you want to use straight JavaScript?  They stay out of your way.  Why can&#8217;t PHP do it this way?  We should worth with PHP libraries, not frameworks.</p>
<p><strong>The Benefits</strong></p>
<ul>
<li>Libraries no longer have to be framework-specific.  This opens us up to a lot more prewritten code that we can utilize.</li>
<li>Faster.  No matter how fast frameworks are, they&#8217;re still slower than straight PHP.</li>
<li>Easier to follow the code, if you don&#8217;t have to loop in and out of foreign code to debug it.  Using a frameworks loader will often break most PHP IDEs and debuggers.</li>
<li>Less things that can go wrong.  If something breaks with just PHP, it&#8217;s either PHP or you (and, more than likely, it&#8217;s you).  If you are using a framework, there is a third party that could also be at fault.</li>
</ul>
<p><strong>Conclusion</strong></p>
<p>Model-View-Controller architectures and Object Oriented programming are fundamental to making intelligent, easy to read applications in PHP.  When we start a program, we need to take the time to think about how we can structure the code in a comprehensible way.  However, we don&#8217;t necessarily need an MVC framework in order to keep our program separated into models, views and controllers.  PHP is already MVC-ready- so rather than focus on frameworks (which, <a href="http://www.blog.gkoberger.net/2009/07/13/some-codeigniter-gotchas/">in my opinion</a>, tend to be lacking), we should create our own well-thought-out architectures and use libraries for the code we want to outsource to open source.</p>
<p>Sure, it&#8217;s not as glamorous or trendy as an MVC PHP framework.  But at least <a href="http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html" target="_blank">one person</a> agrees with me.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 890px; width: 1px; height: 1px;">http://www.blog.gkoberger.net/2009/07/13/some-codeigniter-gotchas/</div>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.gkoberger.net/2009/07/27/php-mvc-by-nature/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Solution To E-Mail Validation</title>
		<link>http://www.blog.gkoberger.net/2009/07/22/a-solution-to-e-mail-validation/</link>
		<comments>http://www.blog.gkoberger.net/2009/07/22/a-solution-to-e-mail-validation/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 07:00:55 +0000</pubDate>
		<dc:creator>Gregory</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Usability]]></category>

		<guid isPermaLink="false">http://www.blog.gkoberger.net/?p=40</guid>
		<description><![CDATA[Whenever it comes time to validate an email address, I always end up going through the same exact process. I start with a simple regular expression- for example, this: (.+)@[\w]+\.[a-zA-Z]+ It works great for a majority of email addresses- however, it&#8217;s not perfect. It lets through a lot of invalid email addresses. For example, &#8220;.name@something.a&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever it comes time to validate an email address, I always end up going through the same exact process.</p>
<p>I start with a simple regular expression- for example, this:</p>
<pre class="brush: php">(.+)@[\w]+\.[a-zA-Z]+</pre>
<p>It works great for a majority of email addresses- however, it&#8217;s not perfect.  It lets through a lot of invalid email addresses. For example, &#8220;.name@something.a&#8221; is considered a valid email address by this regular expression.  So, let&#8217;s take a few steps to correct this:</p>
<pre class="brush: php">([-a-zA-Z0-9])([-.a-zA-Z0-9])*@[\w]+\.[a-zA-Z]{2,5}</pre>
<p>A bit better, right?  But what about valid email addresses, such as <em>john+smith@mail.something.com</em> and <em>$A12345@example.mobile</em>?  Same goes for the seemingly invalid email addresses such as <em>&#8220;Abc\@def&#8221;@example.com</em>.  But, alas, these <a href="http://tools.ietf.org/html/rfc3696#section-3">are all valid</a>.<br />
<span id="more-40"></span><br />
No, I&#8217;m not going to even attempt a regex that accommodates these.  Others <a href="http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx">have tried</a>.  However, it&#8217;s futile; email validation ends up either being too strict with what it rejects, or too liberal with what it lets through.  Or, in many cases- both.</p>
<p>But for the sake of argument, let&#8217;s assume we do create a regex that follows the RFC perfectly.  That still doesn&#8217;t stop people from getting through with something like <em>youre.bad@validation.com</em>.  Sure, we could even go as far as checking to make sure it&#8217;s a <a href="http://www.webdigi.co.uk/blog/2009/how-to-check-if-an-email-address-exists-without-sending-an-email/">real, actual email address</a>.  But even then, there is no stopping <em>johnsmith@gmail.com</em>- an email address that surely exists, however probably is not owned by the person filling out the form.</p>
<p>Depressing, huh?</p>
<p>Well, what about this one:</p>
<pre class="brush: php">(.+)@(.+)</pre>
<p>Here&#8217;s the secret.  This is not a programming problem- it&#8217;s a usability issue.  <strong>If the user benefits from giving you their real email address, they will.  If not, you should not be asking for an email address.</strong></p>
<p>It&#8217;s that simple, really.  Just make sure they at least attempted an email address (otherwise, they may mix up the fields), and throw in a good reason to hand it over- and you will never have a problem.</p>
<p><em>Thanks to <a href="http://twitter.com/foofy">Chancey Matthews</a> for reminding me checking for an @ symbol is good enough, and haacked.com for <a href="http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx">reading the RTC</a> so I didn&#8217;t have to.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.gkoberger.net/2009/07/22/a-solution-to-e-mail-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some CodeIgniter Gotcha&#8217;s</title>
		<link>http://www.blog.gkoberger.net/2009/07/13/some-codeigniter-gotchas/</link>
		<comments>http://www.blog.gkoberger.net/2009/07/13/some-codeigniter-gotchas/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 07:00:11 +0000</pubDate>
		<dc:creator>Gregory</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.blog.gkoberger.net/?p=17</guid>
		<description><![CDATA[Maybe I&#8217;m doing something wrong.  In fact, for the sake of programming, I hope I am.  But for the life of me, I can&#8217;t find a single benefit of frameworks that isn&#8217;t overshadowed by the negatives. Frameworks make it easy to start out- meaning that, when facing a new project, they seem like a good [...]]]></description>
			<content:encoded><![CDATA[<p>Maybe I&#8217;m doing something wrong.  In fact, for the sake of programming, I hope I am.  But for the life of me, I can&#8217;t find a single benefit of frameworks that isn&#8217;t overshadowed by the negatives.</p>
<p>Frameworks make it easy to start out- meaning that, when facing a new project, they seem like a good idea.  You don&#8217;t have to do all the boring stuff at first- and when you&#8217;re starting a new project, that&#8217;s a tempting proposition.</p>
<p>This topic deserves a much more thorough analysis (which many before me have done, and I&#8217;m sure I someday will), however after spending the weekend struggling with CodeIgniter, I figured I&#8217;d mention some CodeIgniter-specific problems I&#8217;ve come across.</p>
<p><span id="more-17"></span></p>
<p><strong>Debugging</strong></p>
<p>When I started programming, things took me a while.  I didn&#8217;t use frameworks- I did everything from scratch.  However, despite the time commitment,  I was making progress- it was time consuming, but it wasn&#8217;t frustrating.  It felt rewarding- plugging along in Notepad.exe, making slow but steady progress.  Then, things changed.  I started using frameworks- and things started to go downhill. Rather than investing my time in programming, I started spending more and more time debugging.  And debugging became harder- after all, frameworks tend to break native error reporting to a certain extent.</p>
<p>Here&#8217;s the code:</p>
<blockquote><p>$this-&gt;load-&gt;model(&#8216;whatever&#8217;);</p></blockquote>
<p>Here&#8217;s the problem- IDEs and even PHP itself has a hard time following that.  A lot of times, errors will show up as being in the Load or Model classes- not helpful, when you know the actual problem is in your code.</p>
<p>Like, this error:</p>
<blockquote><p>Filename: libraries/Model.php</p>
<p>Line Number: 70</p></blockquote>
<p>The error is in my code, not the file/line given.  Where is it?  Your guess is as good as mine- CodeIgniter isn&#8217;t telling.</p>
<p><strong>Conventions</strong></p>
<p>CodeIgniter almost seems to take pride in being illogical when it comes to conventions.  While PHP&#8217;s conventions may be laughable, but CodeIgniter&#8217;s are prohibitive.</p>
<p>For example, what&#8217;s the output of this code? (And, let&#8217;s assume these two lines are on separate pages- otherwise, the cookie wouldn&#8217;t yet be set.)</p>
<blockquote><p>set_cookie(&#8216;test&#8217;, &#8216;value&#8217;);</p>
<p>echo get_cookie(&#8216;test&#8217;);</p></blockquote>
<p>I know what you&#8217;re thinking- and you&#8217;re wrong.  It&#8217;s not &#8220;test.&#8221;  For whatever reason (which isn&#8217;t documented in the documentation), set_cookie() automatically appends the prefix from the config files, while get_cookie() does not.  So, you would have to do the following to get the expected results:</p>
<blockquote><p>set_cookie(&#8216;test&#8217;, &#8216;value&#8217;);</p>
<p>echo get_cookie(&#8216;prefix_test&#8217;);</p></blockquote>
<p>Great, huh?</p>
<p>Another example is callbacks.  Maybe this is a standard practice, who knows.  But I don&#8217;t like it.  In CodeIgniter, for validation, you can specify a rule.  So, something like this:</p>
<blockquote><p>$rules['email'] = &#8220;required|valid_email|unique_email&#8221;;</p></blockquote>
<p>The &#8220;unique_email&#8221; part is a custom function- and it has to be called unique_email_callback.  I have two problems with this.  One, it&#8217;s not easy to figure out unless you read the docs- code should be easy to follow.  And, secondly, why are these callback functions written as strings?  This is code- I shouldn&#8217;t be writing out function names as strings.  It makes it much harder to follow.</p>
<p><strong>Attaching Libraries/Models/etc To Everything</strong></p>
<p>Maybe the biggest problem is that if you load any sort of library, view, or model- it&#8217;s attached to every single object.  So, let&#8217;s say you have an object, with a property called &#8220;parent.&#8221;</p>
<p>So, this code works:</p>
<blockquote><p>echo $whatever-&gt;parent; // Prints out &#8217;3&#8242;</p></blockquote>
<p>Now, somewhere else on your page, in a completely different object, having nothing to do with $whatever, you do this:</p>
<blockquote><p>$this-&gt;load-&gt;model(&#8216;parent&#8217;);</p></blockquote>
<p>Your old code?  No longer works:</p>
<blockquote><p>echo $whatever-&gt;parent; // No longer &#8217;3&#8242;</p></blockquote>
<p>Does this make sense, to a certain extent?  Yes.  Logically, yes.  But, it&#8217;s confusing as hell- you can&#8217;t have, for example, a model with a &#8216;section&#8217; attribute and also have a &#8216;section&#8217; model.  This has caused things to break for me more often that anything else- a perfect example of how changing something in one part of the code can affect something completely unrelated.  Something that doesn&#8217;t happen with straight up PHP.</p>
<p><strong>And there&#8217;s more</strong></p>
<p>There&#8217;s more.  Lots more.  And maybe someday, I&#8217;ll document more of the problems I have with frameworks.  Or maybe I&#8217;ll try to do something about it, and finish <a href="http://technospect.com/gapi/docs/">my own framework</a> I started a while ago.  But either way- I hate spending a day programming, and ending feeling frustrated.  Frameworks are bad at getting out of your way (except you, jQuery- I love you).  Before frameworks, a days worth of programming may not have resulted in much, but it went at a steady pace and I knew X hours of programming would equal Y results.  Now, I can spend a whole day trying to get something stupid simple working, with no results.</p>
<p>And I promise- whatever I write for Wednesday, it&#8217;ll be more upbeat!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.gkoberger.net/2009/07/13/some-codeigniter-gotchas/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

