Beautiful Concurrency – Simon Peyton-Jones

This is a famous paper on concurrency and the benefits of functional programming. It’s obviously no coincidence that I’ve heard of the author in connection with F#.

For me, a beautiful program is one that is so simple and elegant that it obviously has no mistakes, rather than merely having no obvious mistakes

Simon claims that Haskell is the most beautiful language he knows, then introduces it via an example with side-effects, knowing that the result is quite ghastly to a newbie! He points out that

Being explicit about side effects reveals a good deal of useful information. Consider two functions:
f :: Int -> Int
g :: Int -> IO Int
From looking only at their types we can see that f is a pure function: it has no side effects. In contrast, g has side effects, and this is apparent in its type. Each time g is performed it may give a different result.

I got lost in the middle of the Santa example, but I get the sentiment behind the design:

Since there are no programmer-visible locks, the questions of which locks to take, and in which order, simply do not arise. In particular, blocking (retry) and choice (orElse), which are fundamentally non-modular when expressed using locks, are fully modular in STM.

Leave a comment

Filed under Programming

Lessons from Super-Traders

Interesting retrospective from Traders Magazine, telling the stories of nine hot-shot traders that featured in a book 20 years ago and where they are now.

1 Comment

Filed under Finance

How to set up a Raspberry Pi

I’ve got hold of a Raspberry Pi from a mate and am going to have to fun setting it up and learning some Python to write simple programmes on it.  Hopefully, some time down the line I’ll hook up some basic sensors to it and maybe even make my own Scalextric Lap Counter.

  1. Pick an SD card, I found this page useful and chose a 16GB Class 10 SDHC card made by SanDisk.  I was also chuffed to find my trusty Sony Vaio has a slot for SD cards, so I don’t need an external card reader.
  2. Download the disk image.  
  3. Do not just unzip it onto a fresh SD card and assume you’re good to go.  Instead,  unzip it to extract the .img file then download win32diskimager to do the copying onto the SD card.

Meanwhile, this tutorial on Python was useful.

Leave a comment

Filed under Uncategorized

Benefits of functional programming

A couple of linked articles with a strong story on the benefits of choosing F# over C# for reducing the bug count and reducing the size of the codebase.

Simon Tyler Cousins compares two similar projects with F# clearly superior to C# in every category for those projects.

Don Syme opines that a key benefit of F# is that nulls are all but eliminated in the code and references the manifesto for Not Only O-O:

We are uncovering better ways of developing software by doing it and helping others do it. Through this work we have come to value:

Functions and Types over classes
Purity over mutability
Composition over inheritance
Higher-order functions over method dispatch
Options over nulls

That is, while there is value in the items on the right (except for nulls), we value the items on the left more.

Leave a comment

Filed under Programming

GCC 4.8 released

GCC 4.8 has been released. This version uses C++ in its implementation (previously it was C only).

Leave a comment

Filed under C++

How to use smart pointers in C++

Good question about how to use c++ smart pointers posted on Stack Overflow. I haven’t used std::weak_ptr, but the idea of using it to return an “observing” pointer that you can later check for expiry and obtain a std::shared_ptr sounds like a better approach that returning a raw pointer.

Leave a comment

Filed under C++

Book Review: The Proteus Operation, James P Hogan

The Proteus OperationThe book has all the bases covered – history (much is set during World War II), science fiction (time travel) and action (crack troops storming the secret bases of their enemies). I think the plot was excellent, but something was lacking – I found the story telling stodgy in places (particularly at the beginning) and the characters were bland.
ThreeAndAHalfStars

Leave a comment

Filed under Book Review

Book Review: Accused, Mark Gimenez

20130418-195930.jpgReally enjoyed this, it kept me guessing until the last page, with plenty of suspense and excitement. The author interspersed some funny passages too, particularly between the lawyer and his young daughters. This was the first book I’d read by Gimenez, but I will be back for more.

FiveStars

2 Comments

Filed under Book Review

WordPress App mangles my code!

I’ve noticed that whenever I use the WordPress App on my iPhone or iPad to edit a technical post that includes some code, the snippet I’ve carefully slaved over gets mangled. In particular, anything that uses templates in C++ (or generics in F#) will be affected, for example

vector<int> myData;

becomes

vector; myData;

The only answer at the moment is to be disciplined and restrict myself to editing code-based posts in the Web editor, which doesn’t destroy my content.

1 Comment

Filed under C++, Technology

How to recover a dead iPhone

I got out my my iPhone this evening and it was dead.  No response from it, not even when I plugged it in to the mains (which has worked before when the battery ran out of charge).  Attaching to a PC via USB did not revive it either.  Very mysterious, given that it was working just fine on the way home from work.

Fortunately, this post had the answer – hold down the Power button and Home (square) button until the Apple logo appears.  And you have to believe – no point counting to ten and giving up, really believe and the iPhone will come back to life.  Worked for me (after 14 seconds).  This article has even more tips in case the first doesn’t work.

Some might say that any hardware that relies on the user to google an obscure combination of buttons to turn on their phone has a screw loose – but I’m just happy to have my phone back.

Leave a comment

Filed under Technology