Simon Wistow (deflatermouse) wrote,
Simon Wistow

Young, dumb, don't see a problem

I've been occasionally reading the O'Reilly Beautiful Code blog which accompanies the book of the same name. I have to admit I haven't agreed with all of it - some of it reads similarly to occasional posts I see scattered around the Interweb by Pattern Language zealots who haven't quite grasped that what they're doing is only because their chosen language is broken. It's not wrong per se it's just that, well, can a best-practices work around ever be considered beautiful.

Either way, I was pointed at this post this morning about The Cardinality of a Fluent Interface. Again, I wasn't entirely sure I agreed but I was sufficently intrigued to start hacking around.

My first attempt yielded something surprisingly elegant (despite using a couple of mildly egregious hacks such as abusing an overload of the concatenation operator) which allowed you to do things like
A slight bit of hackery later and it could also do
Making it do
Required changing the object from the oddly satisfying bless scalar to a more complicated blessed hash and the internals got a lot uglier. I was initially skeptical that I could make it do both nine.point.five.five - which is arguably the correct english way to say it - and nine.point.fifty.five - which is semantically also correct (albeit clumsy and ugly) and useful for currency - but then I suddenly had a flash of inspiration and hacked in the two line change.

Currently it's labouring under the name Acme::Numbers and not on CPAN but feel free to have a look and suggest new test case.

  • Pretend Best Friend

    The latest buzz on the hyper insular echo-chamber-nets is Fake Following. Shiny! Fresh! A ground breaking new paradigm leveraging social synergies…

  • So don't mistake it, just try and fake it

    I think it's one of the issues that confuses some users of sites - can the people who run the site read their private data. Now most sites will store…

  • 90s Music Monday

    From the " in-jokes department" - a bit of mid 90s Australian rawk which was #1 on the Triple J Hottest 100. Triple J being one of the best…

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.