Behaviour Driven Development (BDD) domain specific language
Posted: Fri Jul 18, 2008 6:51 am
Well, it's been a few months since I've been able to do anything in the world of PHPSpec (my BDD library for PHP) and it's about time I returned my attention there rather than leave a trail of unfinished work in my wake
!.
When I first decided to create the PHPSpec and PHPMock projects I started out with lots of ideas and a PHP oriented API. The API is in fact so PHP oriented that it's beginning to look overburdened which was, in my opinion, an acceptable cost. My question to all the Gurus on the forum is whether the path I'm on is ideal or not. Should I stick with PHP, or should I go completely insane and create a new Domain Specific Language which is then parsed to PHP, cached (until modified), and executed. Or is this Smarty all over again
. The DSL in this case is of the External variant not tied to the host programming language.
The question revolves around a few factors which should probably be clarified since they are drawn from the most desired features of BDD compared to TDD:
Note: In BDD parlance, a specification (spec) refers to a description of the behaviour of the unit being specified. A unit is typically a method called with sufficient parameters to illicit a specific effect.
1. Specs should be human readable
2. Specs should be nestable and inheritable
3. Specs should not be noisy
4. Specs should be as brief as possible
5. Specs should be self describing
The problem with PHP is that it's a noisy language. Where Ruby has a short, terse, readable syntax, PHP uses a lot of additional syntactic elements which require far more characters to be typed and which overall detract from readability and brevity. For example, in Ruby you could write:
it "should score 0 for gutter game" do
20.times { @bowling.hit(0) }
@bowling.score.should == 0
end
In PHP:
public function itShouldScore0ForGutterGame() {
for ($i=1; $i<=20; $i++) {
$this->bowling->hit(0);
}
$this->spec($this->bowling->score)->should->equal(0);
}
After using Ruby's syntax, PHP really does feel horribly bulky and bloated. Unfortunately I either stick with it and admit it's never going to match the specs I write in Ruby, or I introduce an extra specification language that matches or even exceeds Ruby, and let PHP parse it into something executable.
At the moment I'm considering at a minimum a prototype just prove that a) it's possible, and b) won't break my credit with the Performance Bank
.
Your thoughts are really welcome here.
When I first decided to create the PHPSpec and PHPMock projects I started out with lots of ideas and a PHP oriented API. The API is in fact so PHP oriented that it's beginning to look overburdened which was, in my opinion, an acceptable cost. My question to all the Gurus on the forum is whether the path I'm on is ideal or not. Should I stick with PHP, or should I go completely insane and create a new Domain Specific Language which is then parsed to PHP, cached (until modified), and executed. Or is this Smarty all over again
The question revolves around a few factors which should probably be clarified since they are drawn from the most desired features of BDD compared to TDD:
Note: In BDD parlance, a specification (spec) refers to a description of the behaviour of the unit being specified. A unit is typically a method called with sufficient parameters to illicit a specific effect.
1. Specs should be human readable
2. Specs should be nestable and inheritable
3. Specs should not be noisy
4. Specs should be as brief as possible
5. Specs should be self describing
The problem with PHP is that it's a noisy language. Where Ruby has a short, terse, readable syntax, PHP uses a lot of additional syntactic elements which require far more characters to be typed and which overall detract from readability and brevity. For example, in Ruby you could write:
it "should score 0 for gutter game" do
20.times { @bowling.hit(0) }
@bowling.score.should == 0
end
In PHP:
public function itShouldScore0ForGutterGame() {
for ($i=1; $i<=20; $i++) {
$this->bowling->hit(0);
}
$this->spec($this->bowling->score)->should->equal(0);
}
After using Ruby's syntax, PHP really does feel horribly bulky and bloated. Unfortunately I either stick with it and admit it's never going to match the specs I write in Ruby, or I introduce an extra specification language that matches or even exceeds Ruby, and let PHP parse it into something executable.
At the moment I'm considering at a minimum a prototype just prove that a) it's possible, and b) won't break my credit with the Performance Bank
Your thoughts are really welcome here.