Duncan Mac-Vicar P.


Archive for December, 2007

On Google’s Android mobile platform

with one comment

I have spent quite some time studying and testing Android, the new mobile platform from Google.

It is hard to understand people complaining about Java fragmentation because Google’s technical decisions like not using a standard virtual machine.

Just at the same time, I was trying to create an application for Blackberry. Oh yes, Blackberry uses the standard J2ME plus some proprietary APIs. But they of course did not think about Eclipse and instead offer a crappy self-made Windows IDE that nobody likes. There are hacks to use the blackberry APIs (a .jar file) inside Eclipse or Netbeans, but things are not easy if Research in Motion (Blackberry makers) offers the files inside a Windows .exe setup. I did not even try to install the Sun stuff. It was not clear what I needed to download. Which VM? which Eclipse plugin? Which emulator? Where are the docs.

Forget about that. Enter Android.

After downloading the files and extracting them to a directory, I installed the Eclipse plugin adding an remote update site to the configuration. Then I configured the plugin to look for the Android SDK in the directory where I extracted it.

Working with Eclipse is a pleasure. I always become depressed when working with Eclipse because it reminds me how crappy is the life of a C++ programmer when it comes to decent tools. Real time compilation and completion would make me happy in the C++ world.

The documentation is good. Not at the level of Trolltech’s Qt docs but enough. There are some examples in the site, and the amount of Android related projects on code.google.com hosting is impressive. This makes easy learning by looking different examples.

I like the design of the framework, based on concepts such as Activity, Intent, Content (modeled after URIs), etc. The user interface API looks like a normal toolkit, but the XML way of creating layouts is not intuitive. One simple google search and I found Droiddraw, a tool to draw screens and generate XML files from them.

The android sqlite API sucks. I figured out how to wrap a database to expose a content provider url based API, by looking other examples, and at the end I was copy pasting code. Where is DRY ?. However the content provider API is really nice and a clever way to expose data across applications.

Other APIs are really good. Location services, Google apps views, and the way you can use XML files as resources (layouts, strings, etc) is also interesting. Android generates a Java class called R, which you use to access the resources, this allows you to autocomplete the resources in Eclipse.

The emulator rocks, I press “run” in Eclipse and it works, and debugging support is also complete. The emulator is based on qemu. It support different skins and can simulate network speeds and latencies.

In conclusion, Android provides a easy to use framework that work out of the box on your Linux box. It integrates with Eclipse, and the amount of existing code for the platform is enough to start learning.

I will post again as soon as I discover more ;-)

Written by duncan

December 31st, 2007 at 9:08 am

Posted in uncategorized

Tagged with , , ,

RIAA mafia wants you to pay your music multiple times

without comments

A citizen of USA is being sued by the RIAA for ripping CDs in order to play them in the computer.

This opens a really stupid discussion. This is my point of view as a consumer.

The music industry still wants to run their old business model. They want to charge you for expensive CDs. I haven’t bought many CDs since long time. The reasons are simple: I don’t have a CD player, and I don’t listen CDs on the TV/DVD player because I want to make playlists out of many artists and styles and not just loop over 2 good songs and 10 bad ones. Then I want to go walking and bring that playlist with me. To the car, etc.

The usual understanding of CD license model is “private use”. That means I can play it 10.000 times or as much as I want. However, because the reason above, people don’t want CDs. And because the RIAA don’t sell CDs, and they are years late (and also incompetent) to get into the digital market business, the solution is to (as usual) exploit the legal system, and try to change it so the user will pay for every song for every medium. So if you want to listen a song in your car radio, you have to pay for it again.

What this comment mentions is interesting:

Uh oh, George Bush better watch out! The Beatles have never released iTunes tracks… yet, according to his interview here. He’s got them on his iPod. I wonder if the RIAA will go after him next?

There is nothing you can do. The RIAA already as been sued for acting like a mafia/criminal organization but the end of the digital rights war is far away, and everything that happens today will mostly only affect our children’s. We are already screwed up and will have to live with crap for some years.

Not buying RIAA (and friends) albums is an option. I have to admit that most of the music I like is still under RIAA control. You can find those using the RIAA radar.

I own a good bunch of CDs. But as they are not a good investment because I would need to pay for the music again now that I don’t listen to CD media I am not buying more CDs. I have to think (or rethink) my music strategy for the next years. Perhaps start looking in the top 100 RIAA-free albums? or just switch to realtime internet radio?

Written by duncan

December 30th, 2007 at 12:28 pm

Encapsulation and don’t repeat yourself

with 2 comments

Richard Moore comment on Access Anxiety explains why Encapsulation is a good thing. I think both are missing the point. Nobody doubts that encapsulation is a good thing, and Michael Feathers tries to present ruby way as a more “relaxed” thing.

The author was comparing the ‘ruby style’ of direct access to member variables with the getter/setter pattern common in Java code

So what is the ruby style really?

The annoying thing about java setters is that they are functions. So you either start with them (which is overkill for simple things) or don’t use them and then you are lost when you want to add things like Richard showed.

Ruby on the other hand, makes it easy, because you can’t expose member variables, but you can very easily create default accessors.

Michael Feathers example is wrong. Usually you start by actually offering a simple default accessor.

class GlazeObject
  attr_accessor :store, :formatter

  def initialize
    @store = DefaultStore.new
    @formatter = DefaultFormatter.new
  end
end

Now, if you need something more special, like Richard example:

public void setFormatter(Formatter formatter) {
        this.formatter = formatter;
        this.expensive = doCalculation(formatter);
    }

You can just remove attr_accessor :formatter and add to the class:

class GlazeObject
  def formatter
    return @formatter
  end

  def formatter=(f)
    @formatter = f;
     @expensive = doCalculation(f);
  end
end

What is the difference? In ruby, for client code consuming this class, you always see obj.formatter for both cases. In java you have to start from the beginning copy-pasting repetitive accessor code if you don’t want to start changing obj.formatter to obj.getFormatter() and obj.formater = something to obj.setFormatter(something).

C# has a similar feature, called properties.

public class Person
{
  private int _age; 
  public int age
  {
   get
   {
     return _age;
   }
   set
   {
     _age = value;
   }
  }
} 

No matter if we start with a public variable called age, we can move it to setters and getters (which are the providers of encapsulation without having to change the operation mode from variables to functions.

Written by duncan

December 21st, 2007 at 10:28 am

Posted in uncategorized

Tagged with , ,

fixing a moved git-svn checkout

with 2 comments

I had a git-svn checkout of coolo’s branch where we are porting yast2-qt to Qt 4.x. I also publish that git repo at git.icculus.org. Yesterday coolo moved the svn tree to trunk/qt4 and I did not want to do a git-svn clone from scratch because then I would need to start my published repo from scratch.

doener on #git helped me. I had no idea how this works, but it worked. So I blog it in case I need it again in the future. May be useful if you have the same problem:

git clone git://git.icculus.org/duncan/yast2-qt4
cd yast2-qt4
git-svn init http://svn.opensuse.org/svn/yast/trunk/qt4/
git svn fetch -r42760 svn
git branch tmp git-svn
git-filter-branch --parent-filter "echo -p $(git rev-parse master)" tmp
git reset --hard tmp
git update-ref refs/remotes/git-svn master
find -name .rev_db* | xargs rm
git svn rebase

Written by duncan

December 7th, 2007 at 8:21 am

Posted in uncategorized

Tagged with ,