Category Archives: programming

Objects in Perl (part 2,352)

One of my issues with Perl has always been its implementation of OOP. Or, to be precise, the multitude of ways that a class can be declared (blessed hash, inside-out, Class::Std etc). I would argue that this is a case where TMTOWTDI is not advantageous. Enter Piers Cawley and his _Moose for Ruby Programmers_ talk at the London.pm Technical Meeting, 20th February 2009. MooseX::Declare is yet another way, but check this out…

    use MooseX::Declare;

    class BankAccount {
        has 'balance' => ( isa => 'Num', is => 'rw', default => 0 );

        method deposit (Num $amount) {
            $self->balance( $self->balance + $amount );
        }

        method withdraw (Num $amount) {
            my $current_balance = $self->balance();
            ( $current_balance >= $amount )
                || confess "Account overdrawn";
            $self->balance( $current_balance - $amount );
        }
    }

    class CheckingAccount extends BankAccount {
        has 'overdraft_account' => ( isa => 'BankAccount', is => 'rw' );

        before withdraw (Num $amount) {
            my $overdraft_amount = $amount - $self->balance();
            if ( $self->overdraft_account && $overdraft_amount > 0 ) {
                $self->overdraft_account->withdraw($overdraft_amount);
                $self->deposit($overdraft_amount);
            }
        }
    }

Firstly, yes, that is indeed Perl. Secondly, wow: it actually _looks_ like a class definition. And this was the big win for me, as anyone coming from a Java or PHP background will find it trivial to understand what’s going on here. The main point is that by using MooseX::Declare, you are moving towards a more declarative programming style describing _what_ the program should do rather than _how_ it should achieve it. So, no more unrolling `@_` 🙂

Links

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

The problem with complex error messages

Whilst I found myself agreeing with most of Jeff Atwood’s post The Problem With Logging, I strongly disagree with his third point:

If it’s worth saving to a logfile, it’s worth showing in the user interface. This is the paradox: if the information you’re logging is at all valuable, it deserves to be surfaced in the application itself, not buried in an anonymous logfile somewhere. Even if it’s just for administrators. Logfiles are all too often where useful data goes to die, alone, unloved and ignored.

This fails to take into consideration the two very distinct types of error messages that an application should have: administrator focused and user focused. Both of these error messages can be triggered by the same error condition. A problem occurs when you display administrator focused messages to the user: anyone that has come across largely meaningless error codes rather than a friendly human-readable language has experienced this less-than-valuable approach to logging.

useless error mesage

Good error messages are essential to any application, and so are adminstrator focused messages, but let’s remember these are two very distinct features and need to be separated as necessary.

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

Review: London Perl Workshop

Spent an interesting morning in the company of many Perl mongers at the London Perl Workshop. Although I don’t use Perl as my primary language any more, it was was interesting to learn about the current movements of its London-based community. The talks I attended were:

  • The Complete History of the Perle Mongers of Olde London Towne – Dave Cross
  • DBIx::Class for (advanced) beginners‎ – Leo Lapworth
  • closures for fun and maybe profit‎ – David Cantrell
  • Catalyst, DBIx::Class and PostgreSQL -‎ Matt Trout
  • ‎Introduction to Moose – Mike Whitaker

In particular, DBIx::Class caught my eye as a nice way of abstracting database details behind more friendly object methods. Although, as the list of contributors shows, this is a highly complex problem to solve and achieving a “one size fits all” solution may be unrealistic.

Matt Trout’s talk was a little disappointing. Although I admired his passion and enthusiasm, there was far too much crammed in the 40 minute talk. Just concentrating on one aspect of the development process would been more useful. However, saying that, he did enough to convince me that I need to revisit PostgreSQL at some point in the future.

My colleague Mike Whitaker talked about the “postmodern object system”, Moose. There was lots of questions by the end of the talk, which was a good sign that the introduction had achieved its aim.

Overall, a good experience and a reminder that the Perl community is very much alive and well.

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

Real World Lisp

Prompted by a question posed by one of my colleagues today, “has anyone ever used Lisp?”, I surprisingly found myself being the only person that had.

I played around with it many years ago after being inspired by Eric S. Raymond’s seminal article, “How to Become A Hacker” in which he explained that “getting” Lisp is equalivent to finding programming nirvana.

Whilst I didn’t quite reach those levels, I found that using Lisp was a great learning experience. Despite it being half a century old, it is still a relevant language today; the online Practical Common Lisp book contains examples of a spam filter, an ID3 tag parser and other real-world examples.

The following two links are for the curious who might wish to try it out:

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

London Perl Workshop – 29th November

The London Perl Workshop is a free one-day conference in central London, UK. It will be held on Saturday the 29th of November, 2008 at Westminster University’s New Cavendish Campus

I’ll be attending, and so will my friend and fellow Yahoo Mike Whitaker, who will be presenting some talks on Moose and Enlightened Perl.

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

Simplicity does not precede complexity, but follows it

Wise words taken from a list of programming epigrams from 1982:

Epigrams on Programming

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

Wise Words from Martin Fowler

I’ve become quite obsessive about unit testing recently, and in particular the PHPUnit testing framework. A big proponent of test-driven development is Martin Fowler, and I keep one of his quotes in a sticky note on my desktop as a little reminder:

Whenever you are tempted to type something into a print statement or a debugger expression, write it as a test instead.

The PHPUnit manual is really well written, and contains a great guide for writing your first tests.

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

New BBEdit Search and Replace Window

One of the new features of BBEdit 9 is the new Find/Replace Window, shown below:

BBEdit search and replace window

It’s been simplified a lot since the last version, but the really big change is that it is now a modeless window. This means that the Find/Replace window can be left open whilst still allowing interaction with document windows. Initially, this seemed like a good feature to me before I realised a side-effect of this change: there are no keyboard shortcuts for the Find/Replace options anymore. You can see the difference by looking at the old Find/Replace window:

BBEdit search and replace window

In this example, the Command key is being held down to illustrate which shortcuts are available; for example, Command-G toggles the Grep support.

Because of the Modeless window, these shortcuts have been lost in BBEdit 9. This makes the Find/Replace window slightly more cumbersome to use as turning on search options now requires the mouse. Furthermore, the very useful Start At Top option, has been removed completely.

Update: Thanks to Rich Siegel, CEO of Bare Bones Software, who has pointed me towards the release notes which document some brand-new Find shortcuts, thus rendering this blog post mostly pointless. Hurrah!

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

Singletons and global state

A very useful article from Google’s MiÅ¡ko Hevery about the problems with the Singleton design pattern. Essentially, Singleton’s rely on a global instance variable which could point to any number of other variables, thus creating a global state. This causes problems when you want to test your code.

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

Software Development, Visualized

code_swarm is a fantastic application that visualises software projects over a period of time by analysing their code repositories. It aims to show in a graphical manner the users working on a project, and the number of files committed. Some great example videos are available, including a video of the Apache webserver project.

code_swarm

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn