I recently read “Clean Code” by Robert Martin an excellent book on writing clear, easy to maintain and well factored code. In it Robert Martin raises the point that methods should do what their names say, shouldn’t have ‘flag arguments’, and should do only one thing. This implies that overloaded methods are out.
Tagged with PHP
Earlier today I tagged and packaged up the 1.2 release of DebugKit. DebugKit 1.2 features a number of improvements and features over 1.1 which include:
Last night I updated this site to run on the latest 1.3 build. While I know I should have done it earlier, I simply haven’t had the time. And since I went through it, I figured I could document it and share what the upgrade process is like for a small site, that doesn’t see a ton of maintenance action like this one.
Shells are one of the more difficult objects to properly unit test. Since they normally run in a CLI context instead of a web context they provide some interesting challenges. The biggest hurdles are separating the Shell from the CLI environment, and simulating the correct arguments and parameters.
Previously, I wrote about using two versions of PHP with macports . In it I covered installing PHP4 and PHP5. Since then PHP5.3 has been released as a stable release. However, I needed to maintain my PHP5.2 installation as I have a number of client projects that are on servers using PHP5.2. So to reduce version insanity I wanted to keep 5.2.
If you’ve been following the ongoing development of the 1.3 branch over at code.cakephp.org:http://code.cakephp.org. You may have noticed that bake has had a significant overhaul, and a number of features and enhancements have been built in.
So originally when I built this site, I was in the “requestAction is bad” camp. So much so that I created a convoluted Component to assist in the creation of the sideboxes featured on this site. A sample of that code is as follows:Show Plain Text
I spend a lot of time in various IRC channels answering questions and helping out, and one recurring theme that pops up again and again is people not knowing what to do when things go wrong. Whether it be a simple error or a logical mixup, people often lack the tools or processes to figure things out. So I thought I would share how I approach errors and problems.
In the ongoing struggle against code bloat and creative ways to do things, I’ve been playing with throwing exceptions from model methods. While not earth shattering stuff, I’ve found it to have a few advantages over returning
false. First, you can end up with less
Re-factoring code is a part of any programmers life or should be. Very few people write beautifully clean and well factored code from the start, and I am certainly not one of them. Most times my code starts out a sprawling tangle that takes an additional pass or two to look like something I would consider clean. I find that when programming and designing I start with a rough idea or sketch of what I want to accomplish.
When PHP got a real object oriented system in 5.0, it also got a neat feature taken from Java land. Reflection allows you to introspect & reverse engineer functions, classes, and extensions. In addition you can use reflection to extraction of documentation from classes and functions. In PHP Reflection is done using a number of Reflection classes.
Today marks the 1.1 release of DebugKit. After using it for the past few weeks and not finding any new issues or getting and new tickets. A few new features snuck into the release, courtesy of Andy Dawson.
Generating code coverage for test cases is a handy feature, it gives you a quick and easy way to determine how much of your code is running during your tests. It doesn’t ensure that the tests are good or that you have enough assertions, but code that doesn’t run definitely has not been tested. Before code coverage was created it was very difficult to determine how much code was being run.
So I’ve been working away on DebugKit the last few weeks. And I think its at a level where I can suggest other people give it a whirl. Its not at a stable release point. But if you are feeling adventurous and don’t mind using beta code give it a try. There are a few notable features have been added, so in no particular order here they are.
vCards are a nice added touch for an application that acts as a Address book, or contact management. vCards are easily used by most mail clients, and are a plain text standard making them nice and easy to implement. While hCard and other microformats are gaining popularity, the widespread support still doesn’t exist. Leaving vCard as the primary format to transfer contact information out of a web application