Leave in your (commented out) debugging code?

Leaving in (commented out) debugging code is topic that will always be up for debate. That’s fine, there are many sides to it. But I have been finding myself quite thankful for cases where other developers have left in debugging code (commented out of course).

It just makes the debugging process a bit easier if you are unfamiliar with the code. it can be a really quick way to get the information you are after when troubleshooting. Most times, when you have such code in place it is precisely because it was difficult to troubleshoot that piece of code without it (sometimes a sign of bad code, but usually just a sign of complexity). Often what happens is that developers will create that debugging code if it isn’t there and essentially reinvent the wheel to troubleshoot anyway.

Just something to think about. One important stipulation is that the debugging code shouldn’t confuse you, and should be easily identifiable as debugging code. Also the value of such code will vary widely depending on your development platform and available debugging tools.

Sublime Text Open Search Results

There is a nifty sublime plugin called OpenSearchResult which provides a keyboard shortcut to open the file and even the specific line number match to a search result from Find in Files.

The plugin is available on Github: https://github.com/abrookins/OpenSearchResult

To install: 

  • Open Sublime Text
  • Open Command Palette (cmd+shift+p)
  • Package Control: Add repository
  • Add the GitHub URL
  • Open Command Palette (cmd+shift+p)
  • Package Control: Install Package (give it a minute)
  • Find OpenSearchResults and install it

Once installed, you can use it in vintage mode (g, o) or more likely use the shortcut keys ctrl+enter on either the path to the matching file or the specific line number and it will open that file at that line number.

PHP Get Key and Value

A cool little trick with foreach loops in PHP is you can get both the key and the value of associative array like so:

foreach ($array as $key => $value) {
    echo "$key=$value";

Very handy if you need to check the key of the value you are working with.

Should you use frameworks?

One of the best things about the CodeIgniter PHP framework is the wide range of classes and helpers available, everything you need to simplify working with URLs, forms, database connections, email, strings, XML, sessions and security among many, many others. 

But should you use such frameworks? I believe you should, and my reasoning is this:

“I’ll never write code that is as bug-free, secure and efficient as a community of developers in a framework.”

Many programmers fall into the trap that they think they can write code better than all those that have come before them …

Luckily these days most new programmers now learn a language and then a framework almost immediately helping to mitigate this syndrome and promote good code use.

It all comes down to how honest you are about your skills. Remember, for every few lines of code you write, you have more than likely introduced a new bug.

Combine anchor and img in CodeIgniter

CodeIgniter has a number of cool URL helper functions, two of them are anchor and img which generate the anchor and img HTML tags for you.

What’s even better though is you can combine these like so:

echo anchor('http://www.praj.com.au', img('http://content.praj.com.au/blog/favicon.gif'));

Which produces the combined image with a link anchor around it.

TextMate Tasks Bundle

I came across a pretty cool “Tasks Bundle” for Textmate the other day, which I’ve started using for development and work and really like.

Here’s a screenshot (it has a layout that is similar to what TaskPaper does):

Tasks Bundle

A few things you may want to change through the TextMate bundle editor (Bundles > Bundle Editor) are the key assigned to completing the task (I changed this to CTRL + X) and perhaps them theme colors to your liking. 

Find in files with grep

Of all the terminal commands, the one I find myself using the most (several times a day) as a developer is this:

$ grep -lr “<search text>” .

It performs a recursive search (-r) from the current location (.) looking for the search text provided and returning a listing of matching files (-l).

Basically it does a “find in files” from the command line. Very useful for quickly finding things, and super-fast (no need to wait for a GUI to load and sluggishly do the search).

Settings when developing in Moodle

Normally Moodle caches javascript, language strings and themes (CSS). This is usually a good thing, except when you are developing and need to be able to see changes immediately without purging caches. 

Here some settings to change when you are developing in Moodle to save time purging caches:

Javascript Caching (as mentioned previously):

Site Administration > Appearance > AJAX and Javascript
Cache Javascript (cachejs) 

Language Strings Caching:

Site Administration > Language > Language Settings
Cache all language strings (langstringcache)

Themes Caching (for CSS changes):

Site Administration > Appearance > Themes
Theme Designer Mode (themedesignermode)

You could also update the mdl_config table and change these values accordingly (matching name field on the name provided in brackets):

update mdl_config set value = 0 where name = 'cachejs';
update mdl_config set value = 0 where name = 'langstringcache';
update mdl_config set value = 1 where name = 'themedesignermode';


If you work with and develop web services then you can ’t really go past soapUI. It’s multiplatform (Java based) and has a range of functional testing features.

Netbeans for PHP Development

Turns out for serious PHP development, Netbeans is great (yes, even on the Mac):

  • The PHP integration is comprehensive, especially for things like syntax highlighting/code-folding/syntax checking, navigating code, and looking up documentation. 
  • There is good support for all the related file types you need to work with like HTML, CSS, XML, Javascript, SQL. 
  • It integrates nicely with Git (and supports several other version control systems). 
  • There are some nifty plugins (and a few you should turn off if you don’t use them).
  • So far it is the only IDE I’ve found with a decent PHP debugger integration using Xdebug. 
  • Most importantly it isn’t too clunky! Nothing worse than a slow development environment.

One thing that sucks is the dreary soul-crushing enterprise black-text-on-white-background theme. But that’s easily fixed with this Twilight Theme from NetTuts+. It’s a shame its not the default.

If you’re still not sold, check out the list of other major IDEs at NetTuts+.