according to Twitter subscribe to my twitter feed

    New year's resolution - be concise, but not terse

    I've just finished Strunk and White's classic The Elements of Style which I strongly recommend. It teaches you to review your writing before inflicting it on its readers. The book is under 100 pages which proves the authors understand concise use of the language. On top of that, it is an enjoyable little book to read. In the same way, the brevity of your coded language is important. Here's a great example from the Java api:

    Set<Colour> primaries = EnumSet.of(RED, BLUE, YELLOW);

    There is something beautiful about the perfectly-named method "of". Since Effective Java we all know to favour static factory methods over constructors. When dealing with generics it is even more important. Until constructor type inference arrives in Java, the constructor version would be comparatively cumbersome

    Set<Colour> primaries = new EnumSet<Colour>(RED, BLUE, YELLOW);

    In some future generation of the language, an operator overloading could provide more terse code. Maybe something like:

    EnumSet<Colour> primaries += {RED, BLUE, YELLOW};

    I'd argue that the of method is aesthetically more pleasing than the overloading. That's the difference between being concise and terse. Brief, clear and accurate, but not to the point of alienating those that have to read it.

    Labels: ,