talkingCode

Archive for March, 2009

My new game – Civil Liberties Trolling

posted by codders in rant

I know, I know. You prefer the posts about code. Go read JSR #170, #277, #283, #311, revise the two kinds of JMS and have a butchers at JPA. That’ll keep you occupied while I rant.

So. Cory writes to tell us of an exciting new police initiative (hot-linked here – could change to goatse at any moment):

Police Initiative

Yay. But does taking photos of CCTV cameras make you a terrorist? I’ve decided to find out. To play my new game, you will need:

Now all you have to do is snap pictures of the cameras you find and upload them to Flickr before the police confiscate your camera. Of course, you can delete the photos from your phone the second they’re uploaded. No point leaving them hanging around – at best you’ll look like a weirdo in the unlikely event that the police go rifling through your personal property.

Here’s my photo stream – where’s yours? (Remember to tag your photos ‘cctvfun’).

Aren’t you helping the terrorists?

Let’s get some perspective. You’re still more likely to die in your bath than you are to die in an explosion. If people photographing CCTV cameras represents a significant threat to everyone’s safety, we should make some kind of law against it. At least that way there would be some kind of review of whether or not such a restriction on our freedoms makes sense and is proportionate to the threat. We shouldn’t allow the police to make up their own laws – that way madness lies.

As long as it’s legal to do so (and possibly even after it stops being legal to do so), I would encourage everyone to join in my new game and help redress the balance of surveillance.

Abstract Type Members – Augmenting Scala classes

posted by codders in code, java, scala

So, Scala’s cool.

About a month ago, a colleague was whining about having to write Java and it was hard not to sympathise. He’s a Python man, and Java’s Kingdom Of Nouns can seem a little clumsy. Sometimes, you just want to map{}, and trying to do that in Java can leave you feeling dirty.

There are proposals for first class functions and closures in JavaNeal Gafter is your man there. They look fun n’all, but they are apparently a little way off. What I needed in order to silence my colleague was less irritating Java in production straight away. In order to satisfy the needs of m’colleague, m’self and m’company I would need a couple of things.

Pour lui

  • Concise variable declarations – none of this
    Map<String,List<Integer>> map = new HashMap<String, List<Integer>>()

    nonsense

  • Functions as first class values
  • Excellent library support

Pour moi

  • Strong, static typing
  • Eclipse integration
  • Monads. Everybody loves monads

For practicality’s sake

  • Maven integration
  • Interoperation with the existing Java code base

I had a look on Wikipedia for a suitable JVM language since that would ensure the easy interoperation and give us a decent set of libraries. It turns out Scala has everything we need. It’s mixed paradigm functional / object-oriented, it’s got a Hindley-Milner style type inference system, and it’s got a really active community. The eclipse/maven integration isn’t quite there yet, but it gets much better as you get closer to the bleeding edge.

Some Code

There have been too many cool things to mention really, but here’s the first one that seemed apt for a blog post. Scala has some nice XML support, but lacks some of the functions you might like on an XML Node like, for example, ‘getAttributeValue(attributeName)’. In Haskell, you could define a new typeclass and create an instance for Node. In Java / C++ you could delegate (if you like pain). In Ruby, you could mixin. The answer in Scala appears to be… an Abstract Type Member.

Disclaimer:
I don’t know what the right answer actually is, but this works and seems kinda cool

import scala.xml.NodeSeq
import scala.xml.Node

object XmlTest
{
  implicit def nodeToNodePlus(node: Node):NodePlus =
  {
    return new NodePlus { type T = Node; val init = node }
  }

  abstract class NodePlus
  {
    type T <: scala.xml.Node
    val init: T
    private var value: T = init

    def getAttributeValue(name: String): String =
    {
      return value.attribute(name).get.first.text
    }
  }

  def main(args: Array[String])
  {
    println("Hello")
    val xmlDoc = <hi><hello id="world"/></hi>
    val hello = (xmlDoc\"hello").first
    println(hello.getAttributeValue("id"))
  }
}

The mechanics of what's going on there are... err... pretty opaque to me. But to break that down a little:

  • An object is a singleton class, equivalent in most senses to a static class in Java.
  • An implicit is a function from A to B which the compiler will use whenever inference tells it that you need a B but have an A (yes, evil, but okay if used carefully).
  • type T is an Abstract Type Member. I think.
  • <: is a subclass restriction

... all of which allows me to introduce a new function to an existing class without access to that class's constructor. Handy.

That's probably garbage. No doubt I'll find out that's not the way to do it or that it won't do what I expect, but it seems to work. The take-away is that Scala is an easy transition from Java, is much prettier and cooler, and that I can't think of a good reason to write any more Java code.

... having slept on it...

Ah. You see. What I did there was... I got carried away. My NodePlus class is actually no better than a wrapper - I can't actually do any Node operations on it. The implicit mechanism makes it look like I can, but I can't. And the Abstract Type Member was a bit of a red herring. What the Abstract Type Member is doing is letting me parameterise my type which is, I guess, a kind of useful. Given that Scala types accept formal parameters, though, it's not completely clear how much win is involved.

I'll let you know if I find out how to do the thing I actually want to do.

Me, the IWF and child porn

posted by codders in rant

I went to the Convention on Modern Liberty on Saturday, which was a pleasure to attend. It was great to be in the company of vaguely like-minded people who care deeply about the [alleged] slow but steady erosion of our civil liberties, and to hear some compelling arguments that the danger to our freedom is real (not just a figment of my fevered imagination).

One of the morning sessions in Cambridge was a discussion about censorship and the role of the IWF and, being fairly strongly anti-censorship, I chose to go to that session. Long story short, I may have gone on record defending my right to view images of child abuse. I don’t think I made my point as eloquently as I might have done, so I thought I’d summarise the issue here.

The Role of the IWF

I should start by saying that I think the IWF does “a good thing”. As an organisation, they’re run fairly openly and one of their many functions is to be the UK’s notice and take down body. If you have a problem with the UK internet and you want to get it sorted, they’re the people to contact. As such, they are a fairly innocuous alternative to regulation of the UK internet which, I believe, would be a pretty bad idea. Their primary function is not the blocking of child pornography / images of abuse for which they have become so (in)famous recently, and I was pleased that their representative there (Sarah Robertson) acknowledged that their blocking system is imperfect / ineffective. One of the things I objected to most strongly about the blocking system as a technologically-minded person was the idea that an organisation like the IWF imagined it was even possible to censor the internet. It turns out they don’t, which is a relief.

My Question

So, given that Sarah acknowledged that the system was flawed – that it served merely as a deterrent and to avoid people accidentally browsing to images of abuse – my question was why the system isn’t opt-in, or at the very least opt-out. If I want my connection filtered, I would be able to go to the IWF or, install some other filtering software. Sarah replied that the system is opt-in, which is true if you’re an ISP, but I happen not to be. I made the point that as an individual, I couldn’t opt out of having my internet connection censored (by what I cheekily described as an opaque organisation – I meant merely that I had no way of knowing what was on the block list). To an extent, it’s possible for users to vote with their feet and sign up with ISPs that don’t implement the IWF scheme, but these ISPs are being pressured in to joining the majority of providers in installing the software / hardware required.

Sarah’s Question

Why would I want to opt out of the system? The IWF blocking system stops me viewing images of abuse which I presumably wouldn’t want to anyway, and moreover, it stops me breaking the law. If I browse without the protection of the system I could accidentally navigate to an illegal image and open myself to prosecution under UK law. Fair point. And at the time I didn’t have an answer, but have since been thinking about it because it’s a really good question.

The Individual and the State

One of the reasons we had all gathered in London, Cambridge and across the UK, was to discuss what some feel is a radical change that is taking place in the relationship between “us” as citizens and “them” as the government. In theory, the state and its machinery exists at our behest and is there to serve us. Some of the attendees at the Convention were there because they felt that this is increasingly not the case. Why do police photograph protesters at peaceful demonstrations? Why can’t protestors photograph the police? (Why, indeed, can the press not photograph the police, making it difficult to publicise and document a demonstration?) The Home Office seem determined to reduce the risk of the population coming to harm at the expense of curtailing our civil liberties – ought we not to be given a say in the amount of risk that we’re prepared to accept? And it’s not entirely the Home Office’s fault. Society and the press tend to blame the government when “bad things” happen – the only way for them to avoid further blame is to reduce the incidence of bad things.

The real question

Why would I want to break the law? I guess that’s not even really the question. I don’t really want to break that law. I certainly don’t want to view images of child abuse, accidentally or otherwise. But I would very much like the option to break any law. The IWF conscientiously populates the blocking list with the locations of images deemed to be illegal to view and, as far as I’m aware, no “right thinking” person would want to see the images that have been blocked. What they’re doing, though, is implementing a system which allows the government to have content they define as illegal “removed” from the UK internet.

I sometimes disagree with the government

There. I said it. Sometimes I break copyright law. Sometimes I drive too fast. Sometimes I start composing blog posts while I’m stuck in traffic. If someone offered to install a chip in my brain that would make it impossible for me to break the law, controversially, I don’t think I’d take them up on the offer. “If you don’t like the law, you should try to have it changed”. True. I absolutely believe that. But as (I think) Shami Chakrabarti aptly put it on Saturday, whoever you vote for, the government tends to get elected.

I can’t change laws quite as quickly as they’re being introduced. It’s simply not practical for me to campaign against everything with which I disagree, and I don’t think there’s enough popular support today for me to make a difference even if I did. I’ll continue to support the work of NO2ID and the Open Rights Group, and I’ll continue to get as involved as I can with things like the Convention on Modern Liberty. For the time being, though, I’d like to keep my moral autonomy; to be able to choose which laws I obey and which I don’t, to have the option to do things that the government doesn’t necessarily want me to do.

I promise I’ll be good :)



P.S. Obviously the IWF blocking list is a bit of a moot issue for me. I can bypass the filtering in any number of ways if I choose to do so. Recommend you check out Tor and/or ssh -D if you’d like to be able to do the same.

Recent Posts
Recent Comments
About Us
jp: works like a charm! thanks!...
Blake: Check this out: http://bugs.adobe.com/jira/browse/SDK-28016...
Boydell: Wow. That was it. You are the only one that had it figured out, and I looked at many...
mark van schaik: thanks! was using a beta SDK version for a production app, which stopped working over...
Sebastian: Steve, I find most asynchronous programming to be incredibly painful. Haskell's appro...

This is the personal blog of a professional software engineer. This site and the views expressed on it are in no way endorsed by the RIAA.