“Real Artists Ship”

Colin Johnson’s blog


Archive for February, 2013

Where should the responsibility for acting on flags lie?

Friday, February 22nd, 2013

Recently, I set an assessment for my students, which consisted of filling in the application logic behind a calculator GUI that I supplied. One of the difficult parts of this code is writing the functionality behind the decimal point button. The button needs to effect a mode-change so that clicking on the number buttons in the interface places those numbers after the decimal point rather than before it. The obvious way to do this is to set some kind of boolean flag and then to monitor this flag in the part of the program that deals with numerical input. So far, fairly easy.

The difficult part of this is dealing with turning the flag back to normal input. The end point of inputting a number consists of clicking on one of the binary operation buttons or clicking on the equals button. In both of these cases the current number-entry process comes to an end, and a new number entry is started. However, to implement this change, we have to put a piece of code into each of those button pushes. This would seem to contradict ideas of locality in programming; the code concerned with dealing with the decimal point becomes splayed across the code.

I wonder if some hypothetical computer language could provide some means of implementing this more locally to the original functionality. For example, would it make sense to list at the end of the code that set the flag all of those methods where it needed to be reset? Here is some pseudocode:

  public void decimal() {
    decimalFlag = true;
    afterMethods (add,subtract,multiply,divide,equals) {
      decimalFlag = false;
    }
  }

There is a different kind of locality problem now; a method such as add no longer contains everything that it does, as the ending of the method changes the flag, despite this not being written explicitly in the method. Perhaps with modern IDEs this isn’t a problem: we could have the IDE automatically display a link to lists of these after-method actions (that raises a more general question of how computer languages could be different in a world of sophisticated IDEs).

More generally, this raises an interesting issue about the semantics of methods. We are accustomed to methods having a kind of “wait until explicitly trigged” semantics; they are only triggered when a specific method call is carried out elsewhere in the program. An alternative is some kind of “wait until conditions are right” semantics, where the conditions for a method to be called are contained within the method itself. But, exploring that is a matter for another time.

Simples (1)

Monday, February 11th, 2013

Spam is getting very direct and simple these days:

"Click on this link please."

The Law of the Excluded Middle (1)

Wednesday, February 6th, 2013

Non-confidential and Confidential Papers Only

Demographics (1)

Wednesday, February 6th, 2013

This delightful headline speaks to a very narrow demographic:
"By the Power of Graysmill"

East Midlands (1)

Sunday, February 3rd, 2013

A little known fact is that Batman commutes to work from Loughborough each morning:

Bus Timetable: Loughborough - East Leake - Gotham - City

The Rule of Law (1)

Sunday, February 3rd, 2013

There was an interesting discussion on AskMetafilter a week or so ago about whether a parent had the right to fine a minor for swearing in the family home, especially when the money being taken away had been independently earned by the child.

One of the interesting arguments used by people in favour of the fine was “my house, my rules”; that the child lives in a house provided by the parents, and should therefore defer to that provider. An interesting hypothetical is to consider how this could be enforced in law.

Presumably, the basis for this in the “general position”, where there is no parental responsibility between the parties involved, is that the provider of the service can set arbitrary conditions on the providee, within the bounds of the law. If I want to let out a room in my house, it is reasonable for me to set a condition like no smoking, compulsory communal singing every morning, or the saluting of the house flag. If the lessor doesn’t like it, they are free to rent elsewhere.

But, this doesn’t apply in the family case. The child doesn’t have the ready right to move to an arbitrary other home; they are constrained to live within the family home. It would seem that the “my house, my rules” defence can’t apply here, as the necessary freedom of action doesn’t obtain.

This raises interesting questions about the rule of law within families. Do we, in general, believe that it does obtain? I think if asked the question, we might say that it does, but the reality is different. Clearly, the vast majority of us would believe that serious crimes within the family should be treated normally. But lesser issues less so—many jurisdictions, for example, allow a certain class of physical attacks on the child by the parent to be exempt from criminal status, which would exist if those attacks were carried out on a arbitrary individual. So far, we are still within the rule of law sensu strictu—there is an exception, agreed via a democratic and legally sound process, to the general argument that it is illegal to hit someone. But the ground is getting boggier. It get boggier still when we move onto crimes like theft. Is it theft for a parent to take away a child’s property? If I, through menace or surreptition, take some money from my neighbour, I am a thief; if a parent does the same to a child, is it still theft?

Parents in general treat the idea that their child has legal rights with a mixture of contempt and dismissive amusement. Perhaps we need to see a shift in this? Certainly, just a couple of generations ago, the idea that wives had recourse to law in matters such as assault and rape was treated with similar derision. I also worry about the greater implications here for the child’s learning about the rule of law; if the idea that they have no legal recourse is established in their mind through minor issues about property, will they apply the same reasoning when the issue is a serious one?

“Teach someone to fish…”

Friday, February 1st, 2013

Why is it almost an axiom of debate on public service provision that the gain in efficiency through outsourcing will outweigh the inevitable additional cost of the service provider’s profit, whilst it is also assumed that, however hard they try, public organisations will not be able to learn these efficiency gains?

Isn’t there a long-term advantage for public organisations to learn these more efficient means of practice, as that would, after the initial cost of doing so, pay off indefinitely, whilst paying an outside organisation to realise these gains is an ongoing cost.

There is a flavour of “give someone a fish, and they’ll have a meal; teach them to fish, and they’ll have meals for the rest of their life” about this.