Typecasting with double-not (!!) vs. (bool)

I was asked a strange question today.  “What’s return !! $row; do?” And I had never really been witness to the syntax of the double-not ‘!!’ because really, to me, it’s a bit strange and contradictory for the coding styles I’m used to.  So I looked it up a bit more to see if it was actually faster than proper type casting with (bool)$row in php.  Nobody had any real results. I ran a quick test and sure enough using !! is faster… for arrays.  Other than that, the time is so close it’s insignificant.

Here’s the quick ‘n dirty results:

Time testing (bool) vs. !! conversions – 1,000,000 interations

converted array with (bool) done in 1.06559991837 seconds.
converted array with !! done in 0.534655094147 seconds.

converted ” with (bool) done in 0.572640895844 seconds.
converted ” with !! done in 0.523654937744 seconds.

converted (int) with (bool) done in 0.49324798584 seconds.
converted (int) with !! done in 0.5086581707 seconds.

converted object with (bool) done in 0.564023017883 seconds.
converted object with !! done in 0.556074857712 seconds.

I had to do one million iterations just so the times would add up to something substantial.  Really, the difference is only faster if you happen to want to get a quick ‘true or false’ from an array.  The rest are so insignificant it’s not worth the confusion of a double-not.  Personally, I’d rather see an actual check of $row to see if it contains something useful before returning true or false just based on it being set.  But that’s just me.


Adding an Auto Increment Column After The Fact…

Yep, I pulled a ‘whoops’ today. I made a table, filled it with data, then realized I forgot my standard ‘id’.  My primary key, auto incrementing column that makes me feel good about myself.

Once I noticed it was gone, it was easy to add it back. Right? Right? Well, not so fast.  You can add the new column at the beginning of the table.  But as soon as you go to set it to a Primary, Auto increment, MySQL is going to cry because of all the zero values.  The primary key’s can’t be the same so it blows up.

Before setting it to be the primary key, you need to auto-fill it.  You can do it programmatically with any script of your choice, but I find it easy to do it with MySQL…

SET @pants := 0;
UPDATE `ratings` SET id = (SELECT @pants := @pants + 1);

And that’s it.  Time for a beer.

Eclipse Zend Framework

Using Environment Variables So You Can Commit Your .project File

Quick Update: this apparently only works with Zend Studio for Eclipse. Sorry for any confusion if you’re trying to figure out where the f$#@ those dialogs are.

All of my projects reside in an SVN repository and now they’re starting to get accessed by multiple users.  Typically with eclipse, I would just have a project that contained externally required libraries – such as the Zend Framework – but now the location of this is required to be more flexible.


Zend Framework 1.6, and more.

Zend released version 1.6 of their framework just a short while ago and I’ve been reviewing a lot of the changes.  As it turns out this framework is becoming quite large and diverse in what it can do.  Some of the newer features that interest me:

  • Saving sessions to a database table.
  • Dojo integration
  • Captcha and File upload form elements.

The saving sessions to a database table is conveniently easy, but I’m not too sure how well it will fare once I really get going.  It’s so simple that I’m not sure how well it’ll handle validating and securing sessions (based on Users IP, or web browser agent).  But we’ll see.

Dojo integration doesn’t really excite me that much. I’m a big fan of Prototype and Scriptaculous, and having another Javascript framework just sitting there seems like a waste of space to me – but again, it’s something I haven’t exactly dove into yet.  Maybe dojo rocks my socks and I just haven’t felt it yet.

And finally, the captcha and file uploaders may seem very trivial, but trust me – when you’re trying to build a site and those two elements were unavailable for use with Zend_Form — it was a big pain in the ass and effectively made Zend_Form useless when you needed those two elements.

Things are looking good, and the new source base for is getting there.  Of course every time I go to work on it I get distracted and then when I return to working on it a new version of ZF is out. Go figure!

Coding Java

Google I/O 2008

I had the pleasure of attending Google I/O in San Francisco this year.  I’m only getting to posting about it now because work has been far too insane for me to even stop and think about all the glorious things I heard about during the conference.

In fact, I still find it hard to come up with any one outstanding part of the conference.  It was all so awesome, and all so in depth.

If there is anything that I brought out of it, it’s a desire to learn more Java and figure out some ideas to deal with GWT and Android.  Those are two pretty hot topics in my mind right now.

I was also impressed with the Google Earth and Google Maps API integration.  That’s a pretty sweet package right there.  I love maps, and man making maps with Google is fun.

Hopefully I’ll be able to put together some cool things for work in the near future.  I’ve got one project requiring maps and travel data right now, so we’ll see what that brings.

I also have a desire to actually figure out a Rubiks Cube.  Thanks Google, it was a blast.  See you next year, I hope.


Subversion on the Mac

Why does subversion on the Mac have to suck so bad?

Sure there’s apps, SvnX, SCPlugin for Finder, and a few others that typically suck — and unfortunately I always end up using Eclipse and it’s Subversion plugin.

But really, the user friendliness of it all is making my stomach turn.