May282008
As I recently moved to Ubuntu 8.04 (plus CompizFusion + AWN which is rocking my world), I am now back to the good old days where bash was there to save my life. So basically I needed to SVN rename (also known as move) all my thtml views to ctp, recursively. Since this is a short tip, I’ll get down to the details. Just cd to your /views path in CakePHP, and issue:
for file in `find . -name "*.thtml"` ; do svn mv $file `echo $file | sed s/\.thtml/\.ctp/` ; done
After that you can safely commit. Enjoy!
Mar082008
It’s been some time now that I’ve taken upon coding on an application that someone else’s built. Now that’s not unusual, I have done so on many other projects. What makes this endevour quite unlike many others is that it has made me realize how often we can find bad code. Sorry, scratch that, I mean really bad code.
It’s not bad code as a result of ignorance, but worst, because of bad habit. Actually, scratch that too. I would say malice. Take this PHP class:
class SomeClass {
function someFunction($parameter = null) {
// If the parameter is 1
if ($parameter == 1) {
// Launch a passing parameter
return $this->__launchA($parameter);
} else {
// Give back error
$this->error = 'Not good';
}
// Launch the default function sending parameter
$value = $this->__launchDefault($parameter);
// If value returned is ok, give it back
if ($value > 2) {
return $value;
}
// If not valid, return false
return false;
}
function __launchA($parameter = null) {
// Take action based on $parameter
switch($parameter) {
// If it's 2
case 2:
return 2;
default:
return $this->__launchDefault($parameter);
}
}
// ...
}
Because of some NDA agreement that I have signed, I’m actually mocking what I have to deal with every day. But trust me, it’s much worst than this. Get the picture? A huge chain of private methods, calling each other, and a comment ratio *way* about what is acceptable (what good is it if on a comment you are actually explaining what a very simple if statement is doing?). Now, you may be asking yourself, why do I call this (crappy) code malice? Because it is meant to generate mode source code lines. Therefore: more money to charge to the client.
I have seen this over and over lately, on a very big project I’m working on. And the truth is, as a member of an outsourcing software developing firm, I’ve come to realize that us (freelance developers) should be accountable for such bad code. The one who produced this kind of crappy code should be made accountable for the amount of hours it takes to refactor their code, and make it actually usable.
Oct292007
UPDATE: the first beta version has been released, and renamed to Bindable Behavior. Check it out at its bakery tutorial Bindable Behavior: control your model bindings.
It’s been some time since I’ve done any work on expects, and while enjoying the incredible set of cool features CakePHP 1.2 pre-beta is giving us all, I decided it was time to let expects meet 1.2. My new baby is called ExpectsBehavior. As its 1.1 predecessor, its main goal is to provide a wrapper for CakePHP’s unbindModel function, to let the developer specify what bindings (model relationships) he’s expecting right before a find. At the same time, I needed some new features to be added, some of them courtesy of the previous brain work Felix did on his very cool Containable behavior.
Continue Reading »