Author Archives: Anthony

Mobile GMail and the N900

I’ve had my new N900 for just over a month now, and it seems to be working very well. There are a few little annoyances though.

The N900 has a full web browser with most of the features you use on a desktop; it even has flash, so I can watch youtube without a phone-specific app. This is really useful, but a couple of sites spoil it slightly by detecting the user agent of the browser (MicroB, based on firefox) and redirecting it to a mobile version of their page. I’d rather use the standard version of these sites in most cases.

The main site that does this is GMail. It automatically redirects mobile phones to their mobile UI (which is here). There is a way to fix this without changing your user agent, just go to this page instead:

https://mail.google.com/mail/?ui=2

This takes you to the standard version of GMail no matter what your user agent is. However, if you’re not logged in it will take you back to the mobile login page, which takes you to the mobile site again when you log in. To fix this, use the following link – it takes you to a login page which redirects you to the standard GMail without checking the user agent.

https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3D2

I hope this helps someone.

Thanks go to the people on the Maemo forums for finding this workaround (here’s the thread: http://talk.maemo.org/showthread.php?t=55888)

Views on the Digital Economy Bill

I recently took part in the Open Rights Group’s campaign against disconnection from the internet (which is a major part of the Digital Economy Bill). Today I received the last email back from the candidates I wrote to. My original letters to Martin Horwood (Liberal Democrats) and Mark Coote (Conservatives) are here and here (the letters are identical, only the names at the top differ).

The Liberal Democrat candidate replied first, early on Monday morning. The Conservative candidate replied later, on Tuesday evening. (This may not be very relevant, I just added it for the sake of openness).

The replies are as follows. First the Liberal Democrat candidate:

Dear Anthony,

Thank you for contacting Martin about the Digital Economy Act. The Liberal Democrats voted against the bill, and were not supported by the Conservatives, who abstained on the vote, scuppering any chance of effective opposition to the bill.

We have been highly critical about the so called “wash-up” process which has enabled this Bill to pass with limited Parliamentary scrutiny before the General Election. The “wash-up” of the Digital Economy Bill was essentially a carve up between the Labour and Conservative parties that ignored Liberal Democrat arguments to consult more widely before introducing a measure to introduce web-blocking for copyright infringement. Liberal Democrats voted against the Bill at 3rd Reading in the House of Commons and against the Labour and Conservatives web-blocking amendment in both the Lords and the Commons.

Liberal Democrats remain to be convinced about the necessity for technical measures, which could include disconnection from the internet. Liberal Democrats were successful in getting the Government to agree to a period of at least a year in which no technical measures can be considered and then to undertake a process of rigorous analysis and consultation into the need for any such measures. We also believe that the music, film and other content industries must work more urgently to develop easy and affordable ways for people to legally access their products.

The recent Liberal Democrat conference in March voted to establish a party working group to look into further detail about the issues raised by the Bill.

Nick Clegg has vowed to repeal the Act if the Liberal Democrats are involved in the next government and give the issues proper time and consultation. “We did our best to prevent the Digital Economy Bill being rushed through at the last moment. It badly needed more debate and amendment, and we are extremely worried that it will now lead to completely innocent people having their internet connections cut off,” said Clegg. “It was far too heavily weighted in favour of the big corporations and those who are worried about too much information becoming available. It badly needs to be repealed, and the issues revisited.”

If Martin is re-elected as your MP he will join his Liberal Democrat colleagues in fighting to repeal this Act and allow due consideration for the issues. He would also be interested in attending Eric Joyce’s meeting on this issue in the new parliament.

If you have any further questions, please let me know.

Best wishes,

Victoria White

Martin Horwood’s campaign for Cheltenham

So the Liberal Democrats are against disconnection from the internet, instead preferring that content providers provide better ways of accessing their products. In my opinion, this is the way to go. Internet Service Providers (ISPs) should not have to police copyright infringement, as the Digital Economy Bill requires them to (Also, they are not equipped to deal with it, because of things like protocol encryption).

The Conservative candidate’s response is as follows:

Dear Anthony

Thank you for getting in touch about the Digital Economy Act. I certainly share your anger about how the Government rushed through such an important piece of legislation in the dying days of the last Parliament. There was absolutely no reason why they couldn’t have introduced the Bill earlier into the House of Commons, where MPs would then have been able to debate it at length. It just shows the contempt in which they hold both Parliament and the industries affected by this Act.

There can be no doubt that the legislation raised serious questions both for consumers and rights holders. That’s why we took steps to improve and strengthen the legislation in Parliament. Conservatives in the Lords sought to ensure the Bill contained a clear appeals process and robust standards of evidence where allegations of piracy are made. In the Commons, we required the Government to remove inadequate proposals for dealing with orphan works and abandon plans to establish worrying powers to amend copyright law by secondary legislation.

As you know my Party did support many of the measures in this Act. For instance a single age rating system for video games was needed to help parents understand what sort of games are appropriate for their children, and Channel 4 needed an updated remit. Most significantly, something needed to be done to try to reduce online piracy which was estimated to have cost the UK 39,000 jobs in 2008 alone.

We believe that the Act sets up a proportionate and measured response to this problem and that it contains sufficient safeguards through an appeals process and Parliamentary scrutiny for consumers to be protected. It is important to note that only the most serious and consistent offenders will face the threat of disconnection and this will only be done after they have received numerous letters and gone through an appeals process. So although I understand the strength of feeling on this proposal I do not want to rule out temporary disconnection. I will listen to the debates in Parliament and closely follow the drawing up of the codes that will govern this process to make sure that the interests of legitimate users are upheld.

In terms of website blocking I believe that in some circumstances such measures may well be needed. It cannot be right that websites are set up purely to make money by facilitating online piracy. Again though, these proposals will be consulted on and debated in Parliament so I look forward to taking part in that process.

I am also keen to ensure that the copyright system reflects the realities of the modern world. We have repeatedly urged the Government to introduce a ‘format shifting’ exception to decriminalise music listeners who convert legally-owned CDs to other digital formats. This was one of many recommendations in the 2006 Gowers Review which the Labour Government failed to implement.

Ultimately, the UK needs a robust copyright system that provides the right balance of freedom for users and incentives for creators. With the rise of online piracy the Government has clearly failed to maintain that balance, and I believe we have now reached the stage where clear and considered legislation is required.

Although I understand that we may not agree on this issue I am very happy to consider all aspects of this important debate. As such I would be more than happy to attend any meeting on this subject should I be elected on 6th May.

Kind regards

Mark Coote

Prospective Parliamentary Candidate for Cheltenham

So the conservatives are in favour of disconnection from the internet, citing job losses. They do not have any response to my statement on businesses providing wifi hotspots, which could easily become very rare if people used them to download copyrighted material. (Note that although the Liberal Democrats did not mention this either, they were against disconnection anyway).

Also, I am unsure if the figure they give for job losses is entirely accurate. The only source I can find stating it is the Sun, and even there it is only mentioned in the title. Something these sort of statistics often do not take account of is that illegal downloads do not necessarily equate to missed sales – people could easily download something for free that they would never consider buying.

On the subject of web blocking, things look the same again. The Liberal Democrats are against it, and the Conservatives are in favour of it.
From a purely technical perspective, web blocking is impossible. It can be easily bypassed by using a proxy in another country (e.g. http://proxy.org/)
From a philosophical perspective, web blocking sounds like a bad idea. Cutting down people’s ability to communicate via the web is an imposition on free speech.

Suffice to say, I know who I would be voting for in this election had my postal vote application not been late.

Language X

Recently I’ve been thinking of what my ideal language would be like. I really like Java, but there are lots of little annoyances that you find in everyday usage. Something I’ve heard a few people complain about its verboseness, an example of this is that every method and member must be declared public or private, lest you accidentally leave it package private and have bad encapsulation. To combat this and other problems, here is a preliminary design for Language X:

Java-like syntax
Basically, method calls, operators, and other things from Java would work with Language X. Hopefully to the point that it would be completely source compatible and you could compile Java programs with X.
The only exception I will make here is that method and variable identifiers *must* start with a lower case letter, and type names *must* start with an upper case letter. This is a common style in Java and makes things much easier to read, however some code doesn’t keep to these conventions and it gets very annoying very quickly. Therefore, case is enforced for the first character.

Native code compilation
Nothing much to say here, basically it would compile to native code instead of some bytecode language like Java or C# do. The fact that it is not interpreted would hopefully make it much faster.

Access specifiers
In my opinion, Java access specifiers are done wrong. This is not because the levels are badly organised (package being more restrictive than protected can be nice in certain circumstances) but because the defaults are not sensible. In Language X:

  • Member variables would be private by default
  • Methods would be public by default (this includes getters and setters for properties)
  • Package would have its own keyword “package” (although this could cause slight problems with the grammar if “package” is also used for declaring which package something is in)
  • Protected would not include the package access level, and package and protected could be combined if desired.
  • Classes would be at the package level by default (I’m not completely sure on this one, public might be a better default)

Properties
A way of defining properties, to make getters and setters obsolete. To take a nonsensical example, defining properties would go something like:

class X
{
    // automatic getter and setter
    property String firstName get set;
    property String surname get set;
    // custom getter
    property String fullName get { return firstName + " " + surname; };
    int seconds; // just a member variable
    // custom setter
    property int hours
    get { return seconds / 3600; }
    set { seconds = value * 3600; };
}

Note that in fullName and hours, the backing variable is not used. The compiler should be able to detect this and automatically eliminate this if possible (however this could bring binary compatibility concerns).
Using these properties would be as follows:

X x = new X();
x.firstName = "Anthony";
x.surname = "Bryant";
x.hours = 3;
System.out.println("Full name: " + x.fullName + ", " + x.hours + " hours");

Default Arguments
Default arguments would exist in this language, and be done properly (unlike in C++). The reason languages like C++ do them badly is that you can only leave off the last argument(s), not arguments in the middle of the list. To correct this, default arguments would be given a name that must be specified by the caller if the default is to be overridden:

class X
{
    int foo(int x, int @y=5, int @z=7) { return x+y+z; }
}

which could be called as follows:

int a = x.foo(1, @z=9); // override only z, not y
x.foo(6, @y=a); // pass a variable into y, leave z as its default
x.foo(2010, @z=(12*(1+4)), @y=9*a);  // specify y and z in a different order

This could even allow the compiler to let default arguments to be specified anywhere in the parameter list, although it may be easier to read if they are only allowed at the end.

Tuples
Tuples would be supported in X, they would be simple data structures that are passed by value like primitive data types. This would allow you to easily return two values from a method without defining a new object to store them, or just swap two variables very easily. A method return type could be as follows:

class X
{
    (String, int) foo()
    {
        return ("a", 12);
    }
}

And it could be used like this:

X x = new X();
// creates a new tuple 'a' and assigns the result of foo() to it
(String, int) a = foo();
// creates two new variables, text and num, and assigns the result of foo() to them
(String, int) (text, num) = foo();
// swapping variables
int x = 12; int y = -1; int z = 5;
// creates a tuple containing y and x, and assigns it to another tuple containing x and y
(x,y) = (y,x);
// moves the values between x, y, and z
(x,y,z) = (z,x,y);

Closures
[Update 24/03/2010: This will need a rethink to work properly with generics. Partial application support would still be nice, but function type signatures may have to be changed.]
Closures in Language X would be haskell-like, and support partial application and currying. The best way to explain is by example:

{String -> int -> void} a = void closure(String text, int num)
{
 System.out.println(text + " " + num);
}

This can now be called as follows:

// calls the whole function at a time, returns void
a("text", 12);
// calls the function on only the first argument, producing another closure
{int -> void} b = a("text");

The internal structure of this sub-closure would be something like:

{int -> void} b = void closure(int num)
{
    a("text", num);
}

Within which it would store final references to ‘a’ and the string “text” that was passed into a when it was generated.
The way closures are defined also means it is possible to pass closures into other closures:

{int -> int -> {int -> String} -> String} a =
void closure(int start, int end, {int -> String} function)
{
    String s = "";
    for (int i = start; i < end; i++)
    {
        s += function(i) + (i == end - 1 ? "" : " ");
    }
    return s;
}

Also, methods can be assigned to closures, as a type of function pointer. This allows you to do:

class X
{
    void foo(String s) { System.out.println(s); }
    void bar({String -> void} f, String s) { f(s); }
    void baz()
    {
        bar(foo);
        {String -> void} func = foo;
        bar(func);
    }
}

An addition to this that could be useful under certain conditions would be the ability to cast a function which takes n arguments into a function which takes n+k arguments and does not use the last k. This would have to be an explicit cast, as it is a very obscure feature. However, it could be very useful if you want to use a function as an event listener but do not care about some of the parameters.

Immutability
Language X would also have compile-time support for immutability. This is one of the features I really like about C++, although making everything const-correct is very difficult to do, and the const keyword is too long to put in front of every immutable object. Therefore, references to immutable objects would be marked as such in the type declaration by a ‘#’ symbol. Method definitions could be marked by the ‘immutable’ keyword, meaning that this method can be called on immutable references to objects. Entire classes could also be marked with the ‘immutable’ keyword, signifying that all methods of this class are immutable. With regards to properties, getters would always be immutable methods, while setters would always be non-immutable. Immutability would work something like the following (properties are not used so that the point of immutability can be illustrated):

class X
{
    int x = 0;
    immutable int getX() { return x; }
    void setX(int x) { this.x = x; }
    // Compiler error: cannot alter a variable from an immutable method
    // immutable void alterX() { x++; }
}

This type of class would be used as follows:

X x = new X();
x.setX(4); 
#X immX = x; // casts x to immutable implicitly
immX.getX(); // returns 4
x.setX(2);
immX.getX(); // returns 2, as x still points to the same object as immX
// This would be a compile time error, you cannot call
// non-immutable methods on immutable references to an object:
// immX.setX(1);

This would seem to be fine, however what happens when someone wants to do some caching? Maybe a function call takes a long time, but once the result has been retrieved it won’t ever change. This is the type of edge case where const casting comes into C++, however this allows library users to hack a piece of code they are using and cause problems.
Instead, I propose a ‘mutable’ keyword: when a member variable is marked as mutable, it can be altered by immutable methods. This does of course allow a library writer to store a reference to ‘this’ in a mutable variable, however setting this edge case aside, the user of a library will not be able to mess around with const-correctness without changing the library. The mutable keyword would be used as follows:

class X
{
    mutable double resultCache = -1;
    immutable double longCalculation()
    {
        if (resultCache > 0)
        {
            return resultCache;
        }
        double result = /* some calculation which takes a long time */;
        // store the result in the cache, which is mutable and therefore allowed
        resultCache = result;
        return result;
    }
}

This class could be used as follows:

#X x = new X(); 
x.longCalculation(); // takes a while, first time being run
x.longCalculation(); // returns almost instantly, cached result

Conceptually, this is much nicer than in the alternative in that it allows the programmer more freedom, and immutable objects do not have to be completely pure in order to be treated as immutable.

Script files
Script files basically do exactly what you would expect. Instead of writing:

class X
{
    static void main(String[] args)
    {
        // do some stuff
    }
}

You could write:

// do some stuff

This would just give you exactly the same encapsulating definition as in the first example, but you can leave off all of the cruft before and after the code you want to write.
The only real limitations here are that (a) The command line arguments are already specified as being called args; (b) The class name is already specified as being the basename of the file that the code was defined in; and (c) the script is assumed to be in the default package. Also, it would have a different file extension from normal code files.

Binary Compatibility
This is a very important point. C++, because it is compiled to native code, can give library writers many limitations. These include not being able to add more virtual functions or change the order of virtual functions. These should hopefully be possible to solve by (a) sorting the methods of a class before writing the virtual function table, and (b) adding a ‘since’ construct. The since construct would be a way of marking new methods and member variables; methods with a higher since definition would get added later on in the virtual function table. Here is an example:

class X
{
    void foo() {}
    void foo(int x) { System.out.println("x=" + x); }
    since(1.8.14) void bar(int x) { foo(x*2); }
}

Users who have the old version of X, which only includes foo() and foo(int), will obviously only be able to call those functions. Users who have version 1.8.14 or later will be able to call bar(int) as well, however users who have version 1.8.14 or later and are running software that only assumes they have the old version will still be able to call foo() and foo(int).
This may not seem surprising, but in C++ binary compatibility can be a nightmare because this is impossible. If sorting functions into a better order and playing around with the virtual function table slightly can solve this, then it should be done to make library writers lives much easier.

Native Interface
The native interface would be much simpler than, for example, JNI. Every method that can be called from native code must be marked in the actual code with a “native” keyword and an associated linker name. Similarly, a function that has a native implementation must have the same specifier. An example of a native interface could then be:

class X
{
    native("X_foo") int foo(String s);
    native("X_getRandomNumber") int getRandomNumber() { return 4; }
}

And this could be used in native C code by doing something like:

xlang_int X_foo(xlang_object s)
{
    // a call back up to the String class
    // by the naming convention, this would call s.getChars()
    xlang_char *chars = String_getChars(s);
    printf("%s", chars);
    return X_getRandomNumber();
}

And that is a basic definition of some features I would like to see in a new language. If I come up with anything else I’ll probably update this post. I may try to implement it if I ever get around to it, but don’t expect anything any time soon. Thanks for reading!

zsh prompt

I’ve just spent an inordinate amount of time writing a zsh prompt:

export PROMPT='%{%(!.$fg[red].$fg[yellow])%}${(r:1:)${(%):-%~}}$([
[ ${(r:1:)${(%):-%~}} != "/" && ${#${(%):-%~}} -gt 1 ]] && echo /)
$([[ ${#${(@s:/:)${(%):-%~/a}[2,-1]}} -gt 3 ]] && echo ${(j:/:)${(
@r:1:)${(s:/:)${(%):-%~}[2,-1]}[(ws:/:)1,(ws:/:)-3]}}/)$([[ ${#${(
@s:/:)${(%):-%~/a}[2,-1]}} -gt 2 ]] && echo ${(@j:/:)${(s:/:)${(%)
:-%~}[2,-1]}[-2,-1]})$([[ ${#${(@s:/:)${(%):-%~/a}[2,-1]}} -eq 2 ]
] && echo ${${(s:/:)${(%):-%~}}[-1]})%{%(!.$fg[yellow].$fg[red])%}
%(?..%B(%?%)%b)%{$fg[default]%}$ '
export RPROMPT="[%{$fg[yellow]%}%*%{$fg[default]%} on %{$fg[yellow
]%}%D%{$fg[default]%}]"
(Remove the line breaks)

Basically, if you put this code in your .zshrc you get a prompt like this (although with better colours):

~/Anthony/Work$ cd imperial/261\ Lab\ 2                                  [18:31:58 on 10-01-30]
~/A/W/imperial/261 Lab 2$ perl -e 'exit 63'                              [18:32:09 on 10-01-30]
~/A/W/imperial/261 Lab 2(63)$                                            [18:33:10 on 10-01-30]

On the left is the current working directory, the exit code of the last command (if not 0), and a $
On the right is the time and date.

The path on the left side abbreviates all but the last two path elements to a single letter (and a lot of esoteric code was required to get this working).

Note: to do this, you need a few extra lines in your .zshrc to set things up:

autoload colors zsh/terminfo
colors
setopt prompt_subst

Have fun editing your prompt line!

autoload colors zsh/terminfo
colors
setopt autoload colors zsh/terminfo
colors
setopt prompt_subst

Desert Bus

I’ve been watching Desert Bus for Hope for the last day or so. It’s a charity marathon to raise money for Child’s Play, which gives games to children’s hospitals. But the main thing is that it’s run by the great sketch comedians at LoadingReadyRun.com. Basically they’re playing the most boring game in existence – Desert Bus – for as long as the donations keep coming in.

So far they’ve raised over $25000, and they beat what they raised in their first year within 24 hours of starting. Because of the amount they’ve raised so far, they’ll be going for at least 110 hours altogether. You* can prolong their suffering by visiting desertbus.org and donating.

Now I’m going to go and get some sleep before getting up and watching more of their live feeds. Maybe I’ll even get around to finishing some of my coursework before it’s due in on Monday.

* Chances are you don’t exist, as I haven’t really told anyone the address of this blog yet.

Update: They finished after 5 and 2/3 days, and raised over $137,000

The first post

Well this is the second time I’ve installed and configured this blog. I forgot to copy the MySQL database across when I switched my laptop-server from kubuntu to arch linux. There shouldn’t be any reason for it to disappear again though.

I think I’ve got everything working again now, and it should be easy enough to rewrite the one real blog post I had on here originally. I’ve even got the about page done already. Now, however, it is time for sleep; followed by lectures in 8 hours time.