Colin's Journal

Colin's Journal: A place for thoughts about politics, software, and daily life.

December 3rd, 2016

Freedom of movement and the single market

So, the Brexit referendum was a disaster with a slim majority voting to leave the EU. While leaving will significantly weaken Britain, there still remains the option of staying in the single market and retaining freedom of movement.

Why is this important? Most descriptions I’ve seen of the benefits of the single market completely focus on the benefits to businesses. While it is certainly a matter of great concern to businesses, I think there is a strong argument for individuals to be concerned about membership.

Here are my top ten reasons why the average person benefits from freedom of movement and the single market:

  1. Go on holiday anywhere in Europe, bring back anything you want to buy.
  2. Retire to your favourite place in Europe.
  3. Work in Dublin, Berlin or anywhere else in the EU for a day, a week, a month or years with no restrictions.
  4. Have the freedom to live anywhere you want in the EU.
  5. Study anywhere in the EU on the same terms as local students – often for free!
  6. Whether an eBay entrepreneur or small business sell to customers all over Europe with no barriers.
  7. Buy the best from wherever it’s made, in Europe or any of the 50+ countries with free trade agreements.
  8. Make your business a success – employ the best workers from across the continent.
  9. Keep your costs low with no import duties from Europe and beyond.
  10. Be safe selling and buying in the EU knowing that everyone is protected by common EU laws enforced by the ECJ.

June 21st, 2016

Voting to Remain in the EU

Like most of the people I know, I’m voting to remain in the EU.  There are three main reasons for this:

Chateaux reflected in lake

Chateaux reflected in lake

  1. Britain is part of Europe physically – the London Central Line is over twice as long as the narrow stretch of water separating Britain from France.  The EU as an institution provides the framework for agreeing and enforcing the rules that let us live together as friendly neighbours.  We need something to allow us to collaborate, cooperate and look after our shared neighbourhood – the EU provides that.  If there are particular rules or aspects of the EU that we don’t like, being a member provides the means for us to change it for the better.
  2. I believe in freedom of movement.  Being able to visit, work and live anywhere in the other 27 member states is a great privilege that I do not want to lose – I want to live where I choose in the European neighbourhood.  I also want my fellow Europeans to have the right to visit, do business and live in the UK – it makes the UK a better place to live.
  3. An exit from the EU will adversely impact my family, my friends and colleagues.  There are no meaningful benefits to leaving – indeed we’ll have many additional challenges.  The only clear policy the Leave campaign have put forward is the restriction on freedom of movement, a policy I wholehearted disagree with.
I’m hopeful that as the referendum draws near, more and more people will realise the importance of voting to remain.  Voting to leave will diminish us as a nation and hurt many people individually.

January 23rd, 2016

Closures

I’ve found an increasing number of uses for closures in Go, to the point where they are one of my favourite features of the language.  Closures are created when an anonymous function is declared and it references variables in the surrounding function, for example:

func main() {
    a := 0
    b := func() {
        // a is shared between the main and anonymous function
        a++
    }
    b()
    // Value of a is 1
    fmt.Printf("Value of a is %v\n", a)
}

Functions are first class types in Go, so a function can return a function that uses the variables and arguments of it’s parent.  Such functions are a good alternative to producing a number of low value traditional struct{} types with a single method.

Closures also help in producing loosely coupled functions that serve as end points for a web service.  Dependency Injection is used to provide the services required by the end point in a clearer way than defining end points as methods on a struct that holds all of the potential dependencies.

Closures are also good for creating iterators / generators, which don’t come up that often, but are a good way to encapsulate the complexity of navigating a complex data structure.  By passing functions to functions that return functions, it’s possible to create simple micro-languages that make filtering and processing data records much easier to think about.

Finally closures enable in-line inversion of control in a very natural way.  I’ve found this particular useful for iterating over SQL queries, significantly reducing boilerplate code and improving consistency of error handling.

While I’m clearly a big fan of using Closures in Go, you do have to be careful about exactly which variables you are capturing in a closure.  For example:

func loop() {
    var funcs []func() int

    for i := 0; i < 5; i++ {
        funcs = append(funcs, func() int {
            return i
        })
    }

    for _, f := range funcs {
        fmt.Printf("Func value: %v\n", f())
    }
}

The closures being created in this loop all capture the same variable i that is shared between them.  As a result the output of the function is a series of 5s – the value of i at the end of the loop.  If we create a new variable on each iteration of the loop and capture the value there, we get the desired behaviour of printing out 0,1,2,3,4:

func loop() {
    var funcs []func() int

    for i := 0; i < 5; i++ {
        j := i
        funcs = append(funcs, func() int {
            return j
        })
    }

    for _, f := range funcs {
        fmt.Printf("Func value: %v\n", f())
    }
}

 

Copyright 2015 Colin Stewart

Email: colin at owlfish.com