Yearly Archives: 2016

ACCU Meetup: Quicker Sorting, Dietmar Kühl

Meetup - Quicker SortingI was lucky to get an invite to this month’s ACCU London meet-up on the topic of sorting. Dietmar Kuhl hosted the presentation at the plush Bloomberg offices on Finsbury Circus. The talk brought together a sample of approaches to speeding up QuickSort:

  • insertion sort
  • sentinel partitioning
  • hand-rolled sorting for small collections

Overall, these changes (and others) made an impressive improvements, such that the combined algorithm rivalled std::sort for sorting std::vectors of integer. However, the algorithm wasn’t as competitive for other important element types such as std::string.

Dietmar intended the talk to be accessible to all, rather than an in-depth presentation using advanced C++ techniques. I think it was a good example of how you can iterate and bring in multiple techniques to optimise an algorithm for a specific use case.

Leave a comment

Filed under C++, Meetup, Programming

How to define an interface with overloaded methods in F#

In F#, it’s possible to write both object-oriented and/or functional programs.  This means that a task that would be straight-forward in C++, defining an abstract interface containing overloaded methods, is also possible in F#.  However, you have to get the syntax exactly right, otherwise you get obscure compiler errors which could mis-lead you into thinking it isn’t possible after all.  For example, to use overloads, you must define multi-parameter methods using tuples.

type IBlog =
  abstract Write : DateTime * string * string -> IBlog
  abstract Write : string -> IBlog

type MusingStudio =
  interface IBlog with
    member this.Write (entryDate : DateTime, subject : string, body : string) =
      // publish blog entry
      (this :> IBlog)

    member this.Write (subject : string) =
      // automatically generate body and publish (!)
      (this :> IBlog)

Note the syntax of the abstract method declarations carefully.  As per this helpful post on StackOverflow, putting brackets around the tuple changes the signature and leads to confusing compiler errors:

type IBlog =
  abstract Write : (DateTime * string * string) -> IBlog // don't do this!
  abstract Write : string -> IBlog

Whilst it’s possible to implement the interface above and call into it, the syntax to do so involves additional brackets and is unnecessarily clunky.  The syntax at the top of this article is preferable:

let blog = WordPress( "MusingStudio") :> IBlog// create blog
blog
.Write( "How to overload in F#" )
.Write( DateTime.Now, "Book Review: Make Me, Lee Child", "Is this the best Jack Reacher so far?")

Leave a comment

Filed under F#, Programming

Book Review: Thing Explainer, Randall Munroe

IMG_4595Randall Munroe’s  excellent Thing Explainer is on the shelves at Foyles.   I bought this for some fun holiday reading and it’s very good value (£5 in the UK for the hardback edition).

ThingExplainerThe author is probably more widely read as the illustrator of xkcd.

Leave a comment

Filed under Book Review

ACCU: Overload 127 (June 2015)

Overload127CoverCatching up on back issues of ACCU’s Overload magazine from June 2015, a couple of articles are worth mentioning for future reference:

  • Terse Exception Messages by Chris Oldwood.  Here,  Chris relates his experience of unnecessarily long debugging sessions due to limited error information in exception messages.  Often, this is due to laziness on the part of the programmer, sometimes because they expect to refactor a block of code soon and will come back to “do the error handling later” – then the refactoring never happens.  I see this as a false economy – even during unit testing, having proper error messages in exceptions can speed up your own debugging.
  • Get Debugging Better by Jonathan Wakely.  Here, Jonathan lists a few tips for using GDB effectively, aimed at programmers like me who typically use an IDE.

Leave a comment

Filed under Programming

Book Review: Time Out of Joint, Philip K. Dick

Time Out Of JointThis book is part of the SciFi MasterWorks series, so I had high expectations, especially as it was written by the lauded Philip K Dick. However, this book is different to others that I’ve read by him – it starts very slowly, seemingly in a normal family in a sleepy American town. Only much later does the plot encompass a more science fiction element, and a more sinister reason behind the daily puzzle that Ragle Gumm must complete is revealed.

The edition of the book that I bought has a very helpful afterword that explains how the author was trying to break away from the pulp science fiction stories into non-sci-fi novels. They bill “Time Out Of Joint” as the first of a cross-over book between the two genres. He specifically intended it to break away from the sci-fi treadmill that he was on, because he knew his current publisher would reject it in its original form!

This book is interesting for what it says about the author’s own history, but I wouldn’t recommend it for the story alone.

Three Stars

Leave a comment

Filed under Book Review