News for hackers. Stuff that matters.
Re:A DSL in 5 Languages: Ruby, Python, PHP, C#, Java by Nycto on Tuesday August 03, 2010 @05:55PM (#1572898)
For the PHP version: Why is the search method static? You are forcing whatever class you are using to be tightly coupled. Dependency injection can be done in PHP, too.

Better:

    $bt = Braintree_Transaction_Search::someFactory();
    $collection = $bt->search(array(
        $bt->orderId()->startsWith('a2d')
        $bt->customerWebsite()->endsWith('.com'),
        $bt->billingFirstName()->is('John'),
        $bt->status()->in(array(
            Braintree_Transaction::AUTHORIZED,
            Braintree_Transaction::SETTLED
        )),
        $bt->amount()->between('10.00', '20.00')
    ));
If you're really up to it, there is no reason you couldn't use an even more fluent interface in PHP...

    $collection = $bt->where()
        ->orderId()->startsWith('a2d')
        ->and()->customerWebsite()->endsWith('.com')
        ->and()->billingFirstName()->is('John')
        ->search();
Also, please make sure the search method returns an iterator, not an array. Just because PHP allows you to shoot yourself in the foot, doesn't mean you should.
Re:A DSL in 5 Languages: Ruby, Python, PHP, C#, Java by TeHCrAzY on Tuesday August 03, 2010 @07:09PM (#1573076)
Gosh, every example (even in languages I don't know) are much easier to grok than the PHP one :/