August 2013

Friday, August 16, 2013

The future of PHP (and JavaScript)

As a developer, I’m always reevaluating what tools I use to do my work. This can be what language I’m using, but also what frameworks, libraries or editors I’m using. #

I’ve been doing pretty much nothing but PHP for close to a decade and I love it. I know it’s cool to dis PHP and talk about how awful it is, but honestly I think it’s a great tool for what it’s designed for. Recently I’ve been learning Node.js. Partly because it’s fun, but also because I see JavaScript as the biggest threat to PHP. #

Now don’t get me wrong, I don’t think JavaScript is going to kill PHP (nothing ever dies) and I don’t think Node.js will eclipse PHP in popularity anywhere in the near future. But the trend I see is that new applications are being built primarily in client side JavaScript and the back end is little more then an API. That API can be built in PHP, Ruby, Python, whatever. It’s only logical to determine that if this trend continues, we’ll end up with a lot of skilled JavaScript developers who don’t want to write their APIs in a different language. That’s where Node.js comes in. #

Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. #

If you look up PHP on Google Trends it doesn’t look pretty. It’s “web search interest” has steadily decreased since 2004 (the earliest data you get in Google Trends). However I think this is a red herring. PHP is such an elephpant in the room (har har) that it’s not enough to be a PHP developer these days, you have to specialize. We have WordPress, Yii, CodeIgniter, Symfony, Drupal and about a million other frameworks and applications that are built in PHP, each have become ecosystems of their own. #

WordPress which now powers 18.9% of the web has shown a steady increase on Google Trends. Then if you compare some of the popular PHP Frameworks the jury is still out on a clear victor. #

Remember that chart of PHP on Google Trends? Well take a look at JavaScript on Google Trends. The line is pretty much parallel with PHP and I don’t think anyone is suggesting that JavaScript is dying. JavaScript is showing a downward slope because people are no longer searching for JavaScript, they are searching for jQuery and Backbone.js. #

I feel very secure in my career as a PHP developer and I don’t think I’ll be porting Date Check Pro to Node.js anytime soon. Have fun doing what you do. If you’re a PHP developer try out a new framework or even give Node.js a try. It certainly won’t hurt to become better at JavaScript. #

Wednesday, August 7, 2013

Triggering Safari Reader

I do most of my blog reading on my iPhone so it’s really important for me that my blog looks good on the iPhone. #

One feature that I really like is the “Reader” feature that shows up in the address bar on both mobile and desktop Safari. #

One issue with it though is that there is no documentation (that I can find) about how to markup your site so it consistently triggers the reader. #

I noticed that on some of my shorter posts it didn’t work and in reality, it’s not that big of a deal because my site is responsive, but it still bugged me. #

After digging through blog posts, comments and forums I came across this comment that showed that one word of content in an html5 article tag with a height of 350px triggered the reader. #

So I started doing some testing of my own. What I found is that in desktop safari I was able to wrap my content in an article tag and set min-height to 350px and short content would trigger the reader. If I shrunk the width of the browser to a phone width and refreshed the page it did not trigger. If I increased the min-height to 450px then it worked, but when I published the site live and tested on my phone it did not work. I had to increase min-height to 600px in order for my iPhone to show the reader on a short blog post. #

This is a pain in the ass, especially since the reader isn’t respecting the constraints of the article tag. It also pulls in the “Feedback” section in the footer of each blog post. Not the end of the world but still annoying. #

I’m guessing part of the reason it’s kept a secret is that Apple doesn’t want sites messing with it and hiding the post content and showing ads instead (or something along those lines). People were certainly getting upset when this feature was released. #

Saturday, August 3, 2013 #

Friday, August 2, 2013

Improving My Code

I’ll be honest with you. I had kinda stagnated over the last couple years when it came to improving my skills as a developer. When I first started developing professionally I went from not knowing much PHP to being well regarded as a developer in a few years. #

Part of my improvement came from building one content management system after another for the first 3.5 years. Lots of iteration and certainly a few big mistakes. #

But then I hit my stride. I was writing good code and there was no real external pressure to improve. Things are different now. #

I don’t have any external pressure in the form of people telling me I have to get better. It’s more like the external pressure of supporting code I wrote 2 years ago and finding all the areas that really need to be improved. #

One thing that really illustrated to me that I was not developing code as well as I could be was the video Architecture the Lost Years by Robert Martin and then reading his book Clean Code. #

My app was built on Kohana 3.1 which is a nice framework but was not really built on a test-driven development methodology. There are a lot of static methods. Take a look at this database example and see what’s typical. #

I was thinking that the solution would be to build an API on Symfony and then rewrite the site to just be a front-end calling API methods. This may still be the final solution, but I think first I need to reorganize and clean up the existing site. There are certainly ways (as illustrated in the Robert Martin video) to write well-tested code that is outside of your framework and you use the framework as a delivery mechanism. Once I do this, I could theoretically take the code I’d written and move it from Kohana into Symfony if that makes sense and I won’t have to reinvent the wheel. #

We do a lot of complex SQL queries so it’s about time to get off the ORM so I can fine tune and optimize my queries and database tables. #

I’m learning to stop myself and ask “Is what I’m proposing actually the best idea?” and "What other things could I do to solve this problem?". If I force myself to come up with a few possible solutions I’ll probably find that my first solution was not optimal. #

Published by Andrew Shell on and last updated .