Thursday, December 23, 2010

Getting JSR 308 Type Annotations Compiler working under Maven

Carrying on with the JSR 308 Type Annotations compiler, the instructions are out of date for Maven too.
I finally got it working after a fashion. I think the plugin is irredeemably about of date without editing it and recompiling. Hopefully this will get done at some point in the future, but until then I got it working by making the following changes.
Firstly, the groupId has changed to types.checkers in the repository, so the dependencies should be:


<dependency>
<groupid>types.checkers</groupid>
<artifactid>checkers-quals</artifactid>
<version>1.1.1</version>
</dependency>
Next as the plugin is broken you need to put an explicit link to the jsr308-all.jar location (which isn't very maven-like, but works).


<build>
<plugins>
<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-compiler-plugin</artifactid>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.7.0\bin\javac.exe</executable>
<compilerargument>-Xbootclasspath/p:C:\Projects\units\checker-framework\checkers\binary\jsr308-all.jar</compilerargument>
<compilerarguments>
<processor>checkers.nullness.NullnessChecker</processor>
</compilerarguments>
</configuration>
</plugin>
</plugins>
</build>

JSR308 Type Annotations Compiler working in IntelliJ IDEA 10

I struggled to get IntelliJ IDEA 10 working with JSR-308 type annotations. The instructions at Jetbrains and at the JSR site were both out of date. I've reported the problem to Jetbrains (as a comment on that post) and to the JSR 308 team but while they work on it here is a workaround I've found.

By the way, if Java 8 is out, that will include type annotations and this post will be obselete.

The alternation proceeds in two stages - first modifying the compiler, and secondly enabling the annotations processor you are going to use.

Modifying the compiler

  1. Download the checkers framework as described in step 1 of the installation here.
  2. Unzip it. For the sake of this post I'll assume you are on Windows and you unzipped it to c:/checker-framework
  3. Install an OpenJDK 7 that you are willing to alter for type annotations. Download from here. I'll assume you install it to C:\Program Files\Java\jdk1.7.0
  4. In C:\Program Files\Java\jdk1.7.0\lib\ rename tools.jar to oldtools.jar (so you have it around in case you want to use it again).
  5. Copy C:\checker-framework\checkers\binary\jsr308-all.jar to C:\Program Files\Java\jdk1.7.0\lib\tools.jar

Enabling the Annotations Processor


In this case we are going to enable to nullness annotations processor, from the checkers framework. If you write your own, replace the jsr308-all.jar with your own processor.
  1. Open your IntelliJ project you want to use Annotations.
  2. Go to Project Structure, Project, and select the JDK 7 you just installed.
  3. Set language level to 8.
  4. Go to Libraries and add the jsr308-all.jar (from C:\checker-framework\checkers\binary)
  5. Go to Project Settings, Annotation Processors and tick Enable annotation processing
  6. Under Annotation Processors click Add, and add checkers.nullness.NullnessChecker
That should be it! Try compiling the following code, you should get "Error: (5, 31) incompatible types".



import checkers.nullness.quals.*;

public class GetStarted {
void sample() {
@NonNull Object ref = null;
}
}



It's all a bit complicated, but I'm sure Jetbrains will have it working in a much easier fashion soon - I thoroughly recommend IntelliJ IDEA.

Saturday, August 28, 2010

Samsung Galaxy S Android Programming with Windows 7 64 bit

I managed to get a program written on my computer running on my phone. Which might not sound much, but it was a lot more work than I thought, and I tried a lot of things that didn't work, so I thought I'd record what I did for the benefit of anyone else.

My Setup
My Steps

And now, here are the steps I followed. They might not all be necessary, but they worked.

Precursors
  1. Get the hello world app working in eclipse in the emulator as described in the link above, before going anywhere near the phone.
  2. Reboot. This was just because I gave up one evening, and started a few days later but had the side benefit of stopping the adb daemon.
  3. Get the machine to a clean state. While trying to get this to work, I had tried and failed with quite a lot of methods. These included installing other apps in the hopes of getting drivers, downloading random driver files off the internet and so on. Since I didn't trust the driver state of the computer, I restored to a system restore point when I hadn't done anything with the phone. So now we probably have no samsung drivers.
Now we are going to get the phone nicely connected to PC, pretending we are just a normal user, not worrying about being a developer.
  1. With the phone disconnected from the USB cable, under Settings, Applications, Development, turn OFF USB debugging.
  2. Under Settings, About Phone, USB Settings, change to "Ask on connection". This will give you some control.
Installing Kies to get drivers
  1. Now we want the proper Samsung drivers, and we are going to rely on Samsung Kies to do it. Download Samsung Kies from the Samsung website: http://www.samsungapps.com/about/onPc.as. Install it, and reboot if it requests. Now whenever your phone connects in whatever mode Kies will try and take over.
  2. Start up Kies manually. Connect your phone, and when it asks you choose mode choose Kies. Windows should install some drivers, then Kies should detect it and show it in the top left corner.
  3. Eject the phone from Kies, and unplug the cable.
  4. In the Kies tray menu, turn off Auto-start, and quit Kies.
Install as a USB drive to get drivers
  1. Now we want to make sure using the phone as a USB drive works.
  2. Plug the phone in. Kies shouldn't start. Choose "Mass storage" on the phone. Windows should install some more drivers. It won't show yet as a working drive.
  3. On the phone you have pull down the notification screen, which should say "USB connected".
  4. Click on this, and will give you the option to Mount as a drive. Select Mount.
  5. Check you can copy a file back and forth.
  6. Eject the USB drives from Windows and disconnect the phone.
Now you should have a nicely working phone like a normal user, and hopefully all the drivers installed you will need. If you can't get here, don't vene bother with the next steps, you've got to get the phone working first. Try uninstalling Kies and reinstalling, or uninstalling any 3rd party software for use with your phone.

Being a developer

Next we are going reveal our true identity as developers.
  1. IGNORE everything it says at http://developer.android.com/sdk/win-usb.html. Having the package provides drives for a few specific phones. Having it installed won't hurt - I've got it installed, but don't expect it to help. You've got a Samsung Galaxy S, and the package doesn't support this at all.
  2. On the phone, with it disconnected, under Settings, Applications, Development, turn ON USB debugging.
  3. Connect the phone. Windows says it is installing device driver software - a good sign. However, on my machine it then says Device driver software was not successfully installed - a bad sign! But DON'T PANIC.
  4. Go to Control Panel, Devices, Hardward and Sound. The phone should appear as SAMSUNG_Android with a list of all the things it can be. This is good. It appears Windows was lying.
  5. Now as it says on http://developer.android.com/guide/developing/device.html#setting-up you can check to see if it is connected with adb.
  6. Start a command prompt (run cmd.exe from the Start menu).
  7. Change to wherever you installed the Android SDK, and into the tools directory.
  8. Run "adb devices" at the command prompt. My machine said:
D:\Program Files\android-sdk-windows\tools>adb devices
* daemon not running. starting it now *
* daemon started successfully *
List of devices attached
900012345678 device

Hooray - we are all connected and working. Now just follow the instructions on: http://developer.android.com/guide/developing/eclipse-adt.html#RunningOnDevice - just use Run on the eclipse menu and your device should appear, and eclipse will install and run it on your phone. Result!

Sunday, February 21, 2010

What sort of questions should I ask on Aardvark?

In a curious caseof self-referral, I've now been asked the same question twice on Aardvark (www.vark.com). "What sort of questions should I ask on Aardvark?"
You should ask questions that need a person to answer, that you won't find just googling. For example, things specific to a particular area, or very time-specific (relevant here and now). A personal opinion or a very detailed query that maybe no-one has come up with before is another possibility.
I suspect I've been asked this question a lot is that Google has just taken over Aardvark, so it is in the news. So both journalists and curious new users are trying it out, not knowing what to ask, and so asking meta-questions. Aardvark themselves answer this question on their public FAQ but possibly they don't phrase it well enough to hit the top of the google results.
There is a good reason why I say don't answer questions you could google. Doing so would be a bit rude. The person answering the question will then google, find the answer and send it back to you - you've just made them do something you could have done yourself. If someone does this to you and you are frustrated, may I suggest www.lmgtfy.com - like this! It's a bit cheeky but in my opinion not too rude, and gets the message across in a gentle and humorous way.
I've found static web seaches don't work too well for time sensitive searches. For example "What is the highest mega-pixel digital camera?" or "What is the fastest computer?" relies on the page pointed to being updated. If you happen to hit an old article as top result you might not know the answer is out of date.
Aardvark is also good for opinions, but remember while checking out why you should listen to an opinion on the web is hard, checking the authority of an Aardvark answer is even harder!

Saturday, February 20, 2010

Partner dancing in Oxford

Today a friend emailed me. His friend was interested in learning to to dance in Oxford - or in his words "a beginner's class in Ball room (sic) or something." I've been asked this a few times before, as I used to be a dance teacher.
Now I'm only really a social partner dancer. I haven't entered a competition for ages, and for me dancing means leading a girl around the floor. So if you want to know about street dance, belly dancing or ballet then I'm not really qualified to answer. So here is my answer for him, slightly edited. I hope others find it useful.
Cheapest for ballroom is the Oxford University dance sport club (http://www.oudancesport.co.uk/). You don't have to be a member of the University, but most of the classes are in term time, though they do some out of term. There is also dance rhythms (http://www.dancerhythms.com/) who also teach good lessons. Ballroom isn't the easiest to learn in my opinion. Neither are very sociable - dancesport tends to have loads of girls over so don't go without a partner if you are a girl, and Dance Rhythms tends to be an older crowd who come as couples. Again, I don't think I'd want to turn up without a partner.
Easiest partner dance in my opinion to learn is Modern Jive AKA Ceroc, Leroc, MoJive ... There are two local companies: Ceroc Oxford (http://www.cerocoxford.com/) and Jive Plus (http://www.jiveplus.com/), and both of them give good lessons. Both are a really sociable night out, with a DJ afterward, so I think more fun than traditional ballroom lessons. Music a real mix from 40's to current chart stuff.
Salsa - there are loads in Oxford. Again the University society is cheaper and takes non-students: http://www.oxfordsalsasociety.co.uk/. I've also been to http://www.salsaoxford.com/ and they were pretty good too. Salsa is probably a bit harder than jive, but again usually pretty sociable. Music is always very Latin (unsurprisingly).
A bit more challenging but probably my favourite dance is swing/lindy hop. Two groups I'd recommend for a sociable night out:
http://www.oxfordlindyhoppers.co.uk/ and http://www.oxfordswingdance.co.uk/. Especially good if you already like big band/swing/jazz music, but fun whatever, it dancing got me into the music rather than the oter way round.
A newish one on the scene is West Coast Swing. Sexy Dancing style to RnB/chart type music. A lot of fun, and fairly easy, I guess a similar level to Salsa. Friday's in Bicester, which is only about 10 mins drive from Oxford http://www.danceswinguk.com/page3.html
So in summary in terms of difficulty: modern jive easier than salsa, which is about the same as west coast swing, which are both easier than Lindy Hop, which is probably about the same as ballroom. NB, this is difficulty to start to learn, not difficulty to master,

Wednesday, February 17, 2010

What do I think of the Robin Hood tax?

A good friend of mine asked "Nick, as the only banker I know, what do you think of the Robin Hood Tax? Does it make practical sense, or is it only supported by greenies like me who have no actual concept of how the system works?"
Well, I guess I have to start any response by saying I'm a very lowly employee at a very big bank. It is easy to find out which one, but I don't speak on behalf of them, or the banking industry as a whole. I'm writing as an individual. I don't want any media reports saying, "investment banker speaks out against Robin Hood tax"!
I've just been to the Robin Hood tax website, and as explained there the proposal seems to be:
  • 0.05% tax on all bank transactions that do not involve an individual
  • 50% of the revenue goes to domestic causes
  • 50% goes to international eg poverty, climate change etc.
Apparently this will raise £250 billion a year, which assuming a US billion (rather than traditional UK billion) is £250,000,000,000.
The first thing to say is the use is irrelevant. The way the tax system works is a government raises money, and then chooses what to spend it on. So saying this will raise the money for climate change, or reducing poverty, or anything else specific is silly. You could say it will raise money to pay for benefits, or pay for the military, or pay for ministers cars. The money is just money.
So there are three separate issues here:
  1. Should the UK government spend £250 billion more?
  2. Should it raise this money in tax or reduce spending elsewhere, or some combination?
  3. Is the right tax to introduce this tax on financial transactions?
I don't have much to say on 1 or 2. Clearly there are many good things in the world to spend money on, and the government cannot spend on them all. Just because something is very good does not mean it should be paid for out of taxation. Some things cannot be funded, and some things are best supported by charities or the private sector rather than government. Which things these are is a matter for political debate and people differ on these - there isn't a correct answer.
So back to 3. I just went to look at the 2009 budget and apparently the total UK income from all sources will be £496 billion (Budget 2009 page 12). This means that this tax will allegedly raise the same amount as one half of all uk taxation this year - or more than income tax and national insurance put together. On a related note, Barclays just announced their profits for the year, and they were a record amount - 11.6 billion.
The reason I quote these sums is that money does not come from nowhere. It doesn't magically appear out of thin air. If you tax me buying a chocolate bar, the tax either comes as extra money I spend, or money the shop does not receive. This money would have to come from the banks, as it is inter-bank transactions. If Barclays made 11.6 billion in profit, then all of their profit, and all the profit of other 23 banks of equal size would all go into paying this tax. This seems an impossible result. So I think amount of money quoted as being raised is completely unbelievable.
Now I will assume that the promoters of the tax have done their calculations right for the volume of world financial transactions. If this amount of money cannot be raised, then all that can happen is volume of financial transactions is reduced. Now, you might argue this is a good thing - but everyone should be aware that this will be the primary result, reducing the volume of world financial transactions, not raising the huge amounts of money quoted.
0.05% does not sound like much, but it is a lot. We might trade an instrument called an "Interest Rate Swap" and be aiming to make five basis points on a good trade, and making this much is difficult. Five basis points is five hundredths on one percent. So while 0.05% of a deal might not sound much, this would be our entire profit on the deal. The result would be we would make almost no deals, because it would be almost impossible to make enough to pay the tax.
Would it hurt the world economy if we stopped making deals? Well, it would certainly hurt the British economy. When Barclays announced it was paying £2.7 billion in bonuses, those bonuses are taxed at 50% by income tax, and a bit more for national insurance. So over half of it is already going in tax. The rest of it presumably is either spent, in case it provides jobs, or is invested, in which case it funds companies by being invested in their shares, which provides money to build more shops or factories, which in turn provides jobs.
Secondly you have to ask what was the point of the interest rate swap. Typically we might make such a trade because of supply and demand issues for money. Pension funds might want to invest some money for thirty years, so it covers their liabilities, whereas companies might only want to borrow money for 10 years because that is how long they think it will take them to pay back for a new factory they are building. If no-one wants to borrow money for thirty years the pension fund has to accept a low rate of interest. If no-one wants to lend money for 10 years the company has to pay a high rate of interest. By a bank swapping between these products it matches supply to demand, and means the pension fund gets a better rate of return, and the company pays a lower interest rate, which is good for everyone.
Also notice that if the tax came into effect, if this transaction was done, the bank would have to pass the tax on to the pension fund or the company.
So what is my conclusion?
Firstly, I don't think I am wise enough to comment on this question as to what the government should spend our money on, or whether they should raise money through taxes or reduce spending.
Secondly, numbers being talked about for the amount of revenue raised are ridiculous, and just will not happen.
Thirdly the primary effect of this tax will not be to raise the amounts of money talked about, it will be a huge reduction in the volume of financial transactions. This may or may not be a good result, but no-one proposing the tax is talking about this.
So I think the intended consequences of the tax will not happen, and the unintended consequences could be huge and harmful, and clearly have not been thought about properly by the people proposing it.