I am ever obedient to my fans. I wrote this in an email to someone and he suggested I blog it:
Can we have a 'michael hates java' blog please?
On 8/24/06, Michael Stevens <mstevens@etla.org> wrote:
>
>On Thu, Aug 24, 2006 at 09:38:20AM +0100, Michael Stevens wrote:
>> On Thu, Aug 24, 2006 at 09:24:54AM +0100, XXX XXX wrote:
>> > Yes ... I always thought these things were addressing the symptoms not
>the
>> > cause of the problem.
>>
>> Well yes. (the solution is lisp!)
>
>And the problem is that it's too hard to define abstractions in
>java. This leads to repeated code. For example, if you define a field
>in an object, you might write:
>
> private String wibble;
>
> public void setWibble(String wibble) {
> this.wibble = wibble;
> }
>
> public String getWibble() {
> return wibble;
> }
>
>This is bad because it forms a repeated pattern you can't abstract
>away - you want a way to say "I want a field called wibble, with get
>and set methods".
>
>This can easily be abstracted in lisp as follows. When you define the
>class, you supply a list of field definitions (the equivalent of
>'private String wibble'). You might write:
>
> (wibble :accessor wibble)
>
>when defining the field. This will create a field ('slot' in lisp
>lingo) with a get and a set method. And we've needed one line of code
>rather than eight.
>
>If you wanted to do this in perl, you could use the Class::Accessor
>module. So rather than the Java example, you'd do:
>
>use base qw(Class::Accessor);
>Foo->mk_accessors(qw(wibble));
>
>Still longer than the lisp example, but significantly shorter than the
>java version.
>
>But the real genius of lisp is that you can define abstractions like
>this in lisp.
>
>So if you wanted to create a bunch of code based on a predictable
>pattern, you can simply define a macro for it and never have to type
>it again.
>
>Michael
>