Category Archives: software

Coffeescript constructor options with defaults

Coffeescript has a nice way of destructuring assignment in a class constructor, e.g.

class Person
  constructor: (options) ->
    {@name, @age, @height} = options

This is elegant and efficient and has the additional benefit of explicitly communicating anticipated class attributes, cf:

class Person
  constructor: (options={}) ->
    for key, val of options
      @[key] = val

which allows any old thing to be added to your object (although admittedly this is sometimes desirable).

Coffeescript also has a neat way of setting default values for functions, e.g.

fill = (container, liquid = "coffee") ->
  "Filling the #{container} with #{liquid}..."

But this pattern doesnt seem to transfer to destructuring class assignment.  I can’t for instance use any of these approaches:

class Person
  constructor: (options) ->
    {@name = "Ken", @age, @height} = options # (yields an "UNEXPECTED=" error) or
    {@name: "Ken", @age, @height} = options # (yields a "Ken" CANNOT BE ASSIGNED error)
    {@name ?= "Ken", @age, @height} = options # (yields an "UNEXPECTED COMPOUND ASSIGN" error)
    {@name? "Ken", @age, @height} = options # (yields an "UNEXPECTED LOGIC" error)
    {@name || "Ken", @age, @height} = options # (yields an "UNEXPECTED LOGIC" error)

It turns out that the best way (IMO) is:

class Person
  constructor: (options={}) ->
    {@age, @height} = options;
    @name = options.name ? "Ken"

Note that the default value for options is included, so as not to force a parameter on the constructor.  As always, stack overflow provides a deeper picture.

Netbeans file type integration tutorial comments

Netbeans 7.1rc1 has been released. When I went through the file type tutorial (which has been updated for 7.1) I found a couple of minor niggles which needed more than a couple of lines in a comment to express, hence this post.  In Summary, it’s a good tutorial, but there a few rough edges that could be ironed out:

  • A design bug in the properties window section,
  • Missing the visual library api dependency,
  • Excessive overiding the default action on file context menu,

and it would really benefit from some extensions, particularly:

  • implementing a navigation window instead of a node tree under the file node,
  • real-time synchronisation across all views.

Continue reading Netbeans file type integration tutorial comments

Eclipse + Ubuntu + Groovy pain

A couple of days ago the v2 Groovy Eclipse plugin was released, but sadly I’m still not able to use it on my Ubuntu desktop because of a fairly convoluted set of configuration problems.

The first is that the linux download of eclipse doesnt work very well in the latest version of Ubuntu (Karmic Koala). A work around is described here with further links to Ubuntu’s issuelist. But actually the work around is only a partial fix because Eclipse sometimes starts a copy of itself and, when it does, it ignores the work around. This affects me as I’m currently trying to develop plugins.

One alternative approach that has worked for me so far is to use the version of eclipse that’s in the Ubuntu repositories. However, this version wasn’t taken from the final release of the eclipse codebase and the groovy plugin install, which patches the JDT (Java Development Toolkit) just wont install in this version.

So to use the groovy plugin it looks as though I’ll have to wait for Eclipse 3.5.2 (which is due on February 29th).

ArgKit: An argumentation toolkit

ArgKit websiteLast week I released an open source project: ArgKit. It’s the synthesis of some work that I’ve been doing in the last couple of years and I’m very pleased with it. I’ve released early (ish) on this one, so there is more work to come in the same vein, time and attention allowing. One thing that ArgKit’s website misses is some background on “what is argumentation?” so I thought I’d just blog something about Dungine – the only tool in the toolkit at the moment, based on an email I sent to a friend recently (thanks for the question Steve).

Continue reading ArgKit: An argumentation toolkit

The importance of being willing to ask stupid questions

Last week I spent a day interviewing candidates for a programmer position. One of the candidates discussed things that he looked for in an organisation. Two things in particular struck me: He wanted to work in an organisation that, if he was making good progress, didn’t slow him down and that, if he asked a stupid question, didn’t call him stupid. The first question revealed the candidates lack of experience (not a problem in this case btw) but the second one is very important to a career in software engineering.

Continue reading The importance of being willing to ask stupid questions

You lied to me when you said this was a program

A Dutch colleague introduced me to plasmasturm.org a while ago – an excellent software engineering resource. I hadnt noticed it before* but today I was most tickled by a quote he has on his code page:

A friend of mine in a compiler writing class produced a compiler with one error message ‘you lied to me when you told me this was a program’

see plasmasturm.org/code.

* Maybe I did notice it before and didnt get it. Since I first looked at that site I’ve done some work with the RACC, JACC and JavaCC compiler compilers (of the two Java compiler compilers, I prefer JavaCC).

WordPress theme

I fell in love with this styleshout web template and decided to hack it into a WordPress theme. Someone else had done it before, but their license was a little too restrictive for my liking. It took a few hours but was well worth it. It’s not widget friendly yet, but it will do for now.

This was almost my first encounter with PHP and definately my first encounter with the WordPress codebase but the task turned out to be fairly straightforward. The files in the WordPress themes were intuitively named and the code was easy to read. The only problem I had was tracing the location of some of the core functions that are used in the theme, but this is quite normal for this sort of application I feel.