Archive | Programming

Tags: , ,

How to tell if you’re a bad programmer

Posted on 21 October 2011 by Demian Turner

A great read: Bad Programmers

Comments (2)

Tags: ,

PHPstorm version 2 is out

Posted on 15 February 2011 by Demian Turner

download PHPstorm 2.0 – very cute installer image ūüėČ

Volumes PhpStorm 2 0 2

Comments (0)

PHP frameworks vs iPhone dev

Posted on 21 January 2011 by Demian Turner

iphone dev

php framework

Comments (1)

Tags: , ,

Importing Delicious tags into MarsEdit

Posted on 09 January 2011 by Demian Turner


For some time I’ve been wanting to move my blogging efforts over a desktop app, to be able to control multiple blogs from one place, and to search through and¬†manage the content more easily.

The 2 main contenders that I could find for the Mac platform were Ecto and MarsEdit.  The latter seems to be considerably more actively maintained, has a slicker interface and was available for download on the Mac AppStore so I went with that.

The main¬†feature I was missing in MarsEdit was the fairly comprehensive tag handling offered by WordPress. ¬†The fact you can type only a few letters of the tag you need and it auto-completes is something you can’t do without once you get used to it. ¬†The Delicious website and similar desktop tools all offer this functionality.

The first challenge was to get my data out of Delicious, not the links/bookmarks that are offered as their only export option but the actual tags. ¬†Not surprisingly there’s a WP plugin for that, enter¬†EG-Delicious Tags.

Once your tags are copied over to your WP installation you can access the data as a serialized array from the WP database, it’s in the options table under the key¬†_transient_egdel_tags.

Then the data needs to be integrated with MarsEdit. ¬†The app’s author, Daniel Jalkut, kindly explained which plist file within the app needs to be updated to enable the search auto-completion feature.

A simple PHP script was sufficient to deserialize the data and wrap it in XML tags:

$data = <<<DATA
a:773:{s:7:”_blogit”; …
$struct = (unserialize($data));
$keys = array_keys($struct);
$out = ”;
$out .=”\n”;
foreach ($keys as $tag) { $out .=”<string>$tag</string>\n”;}
print $out;

Add the XML to the relevant key and save out the¬†DataSources.plist file and you’re done.

Comments (1)


How to write good code

Posted on 07 January 2011 by Demian Turner

How to write good code

How to write good code


Comments (3)

Tags: ,

Mashable Interview

Posted on 03 December 2010 by Demian Turner

I was fortunate enough to be interviewed on Mashable by Jolie O’Dell recently, cited as a “PHP expert” ūüôā

Here’s a full transcript of the original email interview, some responses make more sense in context:

Am running a bit behind but here are my answers for your interview, please let me know your feedback and if this gets published:

–What advice would you give to a developer just starting to learn PHP?

– keep on top of best practices including a healthy approach to security
– read the code of seasoned devs, there’s always a better/cleaner way to do things
– ensure your code is human readable, if you can’t understand it 6 months later, how will it be for other devs
– always try and simplify your interfaces, it’s much more difficult to write simpler code but consistent refactoring will save you a lot of time and headaches when it comes to maintenance
– don’t reinvent any wheels, you will always have more than enough to program, use reputable libraries whenever you can avoid writing the code yourself
– read up on some of the great programmers (eg: and find out how they stayed passionate about the art of programming so many years later

–In your opinion, what’s PHP’s biggest strength? Biggest limitation?

I think it’s easier to start off with its biggest limitation first: so many people criticise PHP that you’d be tempted to think it’s a rubbish language; that couldn’t be further from the truth. The biggest limitation is _aspects_ of PHP are easier to learn than comparable aspects in other languages, so PHP attracts a lot of “developers” who don’t have a clue, write horrendous code, show their ignorance in forums and generally dangerously decrease the signal to noise ratio for the rest of us.

When I first started with PHP in 2000 I remember discovering of project by a German developer that struck me as very well designed yet according to the critics this should have been impossible:
– it was done in one of the earliest versions of PHP4 (4.0.0, released in 22 May 2000, yet still displayed all the sophistication of someone who understood software engineering
– the language itself supposed had all sorts of limitations and defects that meant using it for OOP was technically impossible: wrong

See for yourself, still not updated since 2000 and still probably better than most PHP that gets written today:

The point is a simple one: if you’re a developer who has the discipline to learn about software development, PHP can be an excellent tool.

The strengths of the language are simple and obvious:
– it stays close to its C roots while removing some of the unnecessary pain points like memory management, pointers and the compile cycle
– the OOP implementation is simple, elegant and easier to read than its peers
– the Java mantra of “complexity at any cost” is nowhere to be found, concise method names are used throughout
– libraries and extensions exist for pretty much every technology on the planet
– hacking activity and community participation most likely the highest of any programming language

There are however a few difficult situations that are directly linked and result from the above positive list:
– there is too much choice when it comes to selecting a library or framework to work with, and the information available is often biased and unreliable (posted by teenagers) so a lot of time can be wasted searching for quality
– the core development team is somewhat hysterical and not professional at times which has resulted in backwards compatibility being broken often, and in unacceptable ways, and our current namespace implementation
– there currently isn’t any decent IDE for PHP, not something comparable to what’s available for Java. This became increasingly obvious when I got into Objective C and Mac development, Xcode really sets the standard. A new candidate that seems promising and is non-free is PHPstorm, so far I’ve found it a relief to use compared to Netbeans. Eclipse, on the Mac at least, I don’t think is even in the race.

–For more intermediate or advanced PHP devs, what are some tips that have helped you along the way?

One of the key problems with PHP is the absence of any authoritative standard library, something which is literally taken for granted in Java, Python, Ruby, Perl and others. PEAR could have been it, but Zend chose to fork for political reasons, now we have the Zend Framework which is not really a framework but more like a library, and it still has some serious quality consistency issues. It seems ZF will likely become the dominant PHP library, but work still needs to be done by the community to refactor the “frameworky” libraries, ie, those that have dependencies on Zend_Config, Zend_Registry, etc. Documentation for many of the ZF libraries is flaky and incomplete, often the comments contain the clues you need to get things working.

In terms of tips, I’d make the following suggestions for devs who are keen to move out of beginner status:
– don’t be afraid of using an interactive debugger, available in decent IDEs like PHPstorm and also Netbeans and Eclipse if you have the patience, this is the best way to understand what the code is doing. If you’re using print_r($foo) you’re a beginner.
– don’t be afraid of unit tests, not only will you have an easier time maintaining your codebase, but often unit tests are the best form of documentation for a codebase, and will allow new devs to get up to speed fast
– use some of the available static analysis and IDE tools to help you refactor your code, good code is not subjective!

–What’s the best app or most clever hack you’ve seen that uses PHP? (Links, please!)

Facebook? Although from the code leaked a few years ago, the quality was primitive.

Comments (3)

Tags: ,

The World of Programming

Posted on 06 October 2010 by Demian Turner

Nice infographic (via SmashingMagazine)


Comments (2)

Tags: ,

Random thoughts on scripting languages

Posted on 06 October 2010 by Demian Turner

Interesting presentation [pdf] from Brian Kernighan

scripting languages

Comments (0)


Updating your dev environment after a Snow Leopard upgrade

Posted on 01 July 2010 by Demian Turner

I’ve avoided upgrading to Snow Leopard for ages for a number of reasons:

  • didn’t want to spend ages re-setting up all my ports, I’ve heard SL creates a havoc
  • wanted to maintain java apps that stop working in SL, like Zend 5.5 (it may be old but still has the best debugger around)
  • wasn’t crazy about tinkering with my Cocoa dev environment

Finally I was forced to upgrade, in a panic in fact, as it’s the only way to build iOS apps for iPhone and iPad for version 4 or later. ¬†And since the iOS 4 update broke a lot of our 3.1.3 apps, I had to get fixes out asap.

So what’s involved? ¬†Well on the database side, forget about downloading the dmg for MySQL, it’s poorly setup. ¬†And forget about globally upgrading your ports, the various approaches suggested here and here simply don’t work.

Unfortunately you have to take the advice on the official Macports page and uninstall everything, then selectively re-install the ports you want. ¬†The suggestion labelled “Automatically reinstall ports” refers to a script that collapses almost instantly when it fails to find Tcl libs which certainly don’t exist in my bog standard ports setup.

So one thing you need to keep in mind is to reinstall your ports with the +universal option which specifies 32 and 64 bit architectures will be accommodated.

For a basic PHP+Apache install this page has some good suggestions but is not up to date. ¬†And you need to go here for advice on installing MySQL, which obviously needs to be done before you install PHP. ¬†I’ve summarise the steps required here:

Apache 2

Install apache as follows:

sudo port install apache2 +universal

Then run the following, as advised, to get it to startup automatically after reboots:

sudo port load apache2

Just installing apache installed 16 ports including all the deps.  For tweaks the config the file is here:


MySQL 5.1

To get the ball rolling with MySQL, the following:

sudo port install mysql5 +universal

Then you need to issue you a

sudo port install mysql5-server +universal

which just takes a few secs and the server is setup.

To start the server on reboot do

sudo port load mysql5-server

and if you wanted to setup a new db from scratch you could issue

sudo -u _mysql mysql_install_db5

If you want to change any of the configuration the file is here:


PHP 5.3

Now that you have your Apache and MySQL installed, it’s time to install PHP and link to them:

sudo port install php5 +apache2 +universal

To enable PHP in Apache, run

cd /opt/local/apache2/modules
/opt/local/apache2/bin/apxs -a -e -n "php5"

then add the PHP modules you want after:

sudo port install php5-mysql

Then, to get MySQL working with PHP you need to edit /opt/local/etc/php5/php.ini and set

mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket to /tmp/mysqld.sock

And that should do the trick!

edit /opt/local/etc/php5/php.ini and set
mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket
to /opt/local/var/run/mysql5/mysqld.sock

Comments (2)

Tags: , ,

Learning PHP, MySQL, and JavaScript

Posted on 02 June 2010 by Demian Turner

Learning PHP, MySQL, and JavaScriptO’Reilly asked me to be a technical reviewer for this book by Robin Nixon, I forgot to mention that it was published several months ago.

If you’re a newb I recommend giving it a read, you can pick up a copy on Amazon.

Comments (2)



Demian Turner's currently-reading book recommendations, reviews, favorite quotes, book clubs, book trivia, book lists



PHPkitchen recommends you also check out the following sites :

Accounting for Small Businesses

FreeAgent sign-up