Dec 12 2007

Personal content, for just your friends.

Published by Laurie Tagged as:, , , , ,

Have you ever wanted to share something personal with just a few, or even just one close friend. Its really not easy. I’m not talking about an idea, something you can just ring up and tell them. I’m thinking of videos (though the idea extends to photos, or music, or any thing like that). Because its not easy, I think a lot of you end up not doing it, and thats a shame.

I spent today working on this problem. My dance partner and I had someone record us at a competition at the weekend. I want to share the videos with her, but not with the whole world. After all, what if someone in Australia sees it and doesn’t like our dancing! I didn’t want to burn a copy of the CD and give it to her. Mainly because I just had a foot operation, and so can’t get out of bed. That aside though, some sort of internet sharing is just so much more elegant, and being a computer geek, i want elegance when doing this sort of thing.

So video sharing, of course, means YouTube. Does YouTube allow me to share a video with just one person? It turns out it does, but falls very short on my elegance desires. I won’t bore you with all the details, but by the time I had set the video up to not be publicly viewable, and informed YouTube who, other than myself, should be able to view the video, I had formed a somewhat less than favorable view of the administration interface that YouTube provides.

I think this is really quite a big deal. The easier something is to do, the more I am willing to do it. Facebook makes tagging people in a photo really easy, so I tag photos in Facebook. My photo-library software though, just isn’t as good, its not bad, its just not *as* good, so I don’t tag photos in it. If I could easily send a video message to a group of people, and be sure only they get it, then I probably would.

The thing thats really important to me here is the idea of how confident I feel doing this. The more I trust the people I am sending my content to, and the more I trust the security of the system, the more open I will be, and the better the quality of the communication will be. I find I do trust YouTube (for now), but the lack of simplicity in their interface leads me to believe they either do not want, or do not care about user to user communication. I did use them today for my videos, but it did not leave me with the warm fuzzy feeling that they care about me. Nor did it leave me wanting to try sending videos to other friends.

One response so far

Jul 30 2007

Rapid Prototyping for Java using JRuby: A Presentation

Published by site admin Tagged as:, ,

On Thursday 30th of August I will be presenting a talk as part of the LRUG BOF (Birds of a Feather) session at NFJS, No Fluff Just Stuff. It will be my first time presenting outside of an academic conference and I am really looking forward to it. I’m going to be talking about how JRuby can be used to rapidly prototype new features into a Java application.

I must admit, the biggest concern I have is about estimating the audience. It’s quite a varied conference, mainly Java and Agile, and it’s not clear what proportion of the audience will know anything about Ruby, and what proportion will be experts. Figuring out what level of understanding in each language to pitch the talk at is going to be an open question. It won’t be until I start the talk that I will really know if I have got it right.

The BOF session is free, but you need to pay if you wish to attend the rest of the conference. On the plus side, as valued readers of this blog you get a discount. Simply quote NFJS-BLO182 when you register and you get £100 off the registration fee.

NFJS Logo

No responses yet

Jul 23 2007

Using JRuby to rapidly prototype changes in a Java codebase

Published by Laurie Tagged as:, ,

Today, as an exercise, I coded up a simple piece of java and ruby integration, via JRuby.

The task I set myself was simple. Start with a java only application, and then use JRuby to rapidly prototype adding a new feature to it. I used my favourite sample application: A library with three entities, books, borrowers and loans (the first application design I was ever taught – way back in A-levels). The design is pretty simple; a borrower is associated to a number of loans, each of which is associated to a book. There is also a link from each book to all the loans it’s refereced in.

I intentionally made a limiting design decision however. Each book’s author is saved as a string, and the meaning is lost when someone tries to enter several authors to a book

public class Book {
<snip>
private String author;
<snip>
}

Book jrubyBook = new Book(”JRuby for beginners”,
“Ruby Guy, Java Guy”, //second argument is author
“12365437890″,
LoanType.ONE_MONTH);

The feature I wanted to add was the ability to look at a book, and see what books influenced its authors. The logic used is:

  1. use the book.author property to find out the author(s) of the book
  2. look at the loans associated with the author(s)
  3. get the books for those loans

Not a very complex piece of logic, but good enough to demonstrate the point. Ideally the author field of book should be refactored to be a collection of people which would be created as a new super-class of borrowers. But before I go and do some refactoring, (which in a real project would mean quite a bit of changing the persistence mapping too) I want to get the functionality working to see if it really is useful. JRuby’s ability to load up some java classes and quickly change them allowed me to simulate doing these changes.

require ‘java’

include_class ‘com.wildfalcon.library.model.Book
include_class ‘com.wildfalcon.library.model.Borrower’
include_class ‘com.wildfalcon.library.persistance.Books’
include_class ‘com.wildfalcon.library.persistance.Borrowers

class Book
def authors
author_names=[]
getAuthor.split(”, “).each { |author| author_names << Borrowers.findByName(author)}
author_names
end

def inspirations
list = []
authors.each {|author| author.books.each{|book| list << book}}
list
end
end

I can then call the inspirations method:

book = Books.findByName(”JRuby for beginners”)
book.inspirations.each {|a| puts a.title}

all of which I put in a prototype.rb file an execute as follows:

ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName(”jruby”);
InputStream is = new FileInputStream(new File(”prototype.rb”));
try {
Reader reader = new InputStreamReader(is);
engine.eval(reader);
} catch (ScriptException ex) {
ex.printStackTrace();
}

Indeed when I execute it I find out what books have been read by the two different authors of “JRuby for Beginners”:

  • Java for beginners
  • Ruby for beginners
  • How to tie a tie
  • History of fairy tales
  • Cooking Italian Food for Large Groups

This quickly allows me to realise that looking at the books read by the author isn’t good enough, before I can deliver the feature I need to find some way to tell which books are relevant and which are not. But I found that out with a very small amount of coding, and without having to make any changes to the existing java application. I can happily go back to the drawing board without worrying that I broke something in the meantime.

No responses yet

Jun 10 2007

Stuff your Java model into your Rails project

Published by Laurie Tagged as:

The upcoming, and now recent, release of JRuby 1.0, along with some conversations with various friends has left me thinking a lot recently about how to integrate a Java project with a Ruby (on Rails) project. If you have an existing domain model written in Java then the reasons you might want to do this become obvious. Rails is designed using the MVC architecture, and if you can get it talking to your java domain model, then the M is already written for, you just have to write the views and controllers. Views especially can be painful in Java.

The standard answer for integartion between languages is currently web services: Write a simple XML wrapper round the Java domain objects allowing methods to be called on them, then use that API from within your Rails models. It doesn’t really matter if you use SOAP, REST or your own “standard” (although REST lends itself nicely to having a toXML() and a setXML() method on your java classes and using ActiveResource to GET and SET instances).

However, XML has never been a major contender for speed, and the chances are that your API isn’t designed to minimize the number of calls you make. So you have to pay that overhead more often than you need to. Of course you could add a remote facade, but now things are maybe starting to get more complex than you need…

JRuby provides a much more integrated way of solving the problem. It works like this: JRuby lets you import Java classes into your Rails code. Your controllers do not need to know (or care) that they are not Rails models. They can just find a new User instance, set the password on it, and move on to the next one.

Of course, I’m not suggesting that it’s that simple. Rails expects the models to be ActiveRecord instances. You are likely to suffer from code expecting to find an ActiveRecord method, like User.find and it not being there. I imagine the solution to this would be a library that loads all of your Java classes, and then changes them (as Ruby can do that) to add methods normaly provided by ActiveRecord. You can add the validation methods, then you can add the persistence methods like save, and find. How you do this is going to be dependent on how your Java persistence is done (ok, I’m assuming your Java code has a persistence model - I probably should have mentioned that earlier). If you have used the DAO pattern, the find method could instance a DAO object, load an instance though it, and return that. If you don’t use DAOs, then you map the methods to whatever you do use.

Finally you need to wrap all your code up into a library that runs when rails starts, automatically loads all your java classes, and decorates them. Hey presto, your old legacy Java domain model has a new lease of life as a trendy Rails application. If anyone has the time to write this library, let me know - I would love to have a play with it.

Unlike the rest of the Rails system, this integration won’t be solved by convention over configuration. Potentially it could be, but I think there are just too many different designs; different persistence models and different ways of locating your domain model out there…

2 responses so far

Jan 23 2007

Sometimes Models Make Reality

Published by Laurie Tagged as:,

Table of contents for The Limits of Science

  1. An Orrery - All of science in a clockwork model
  2. When Scientific Models End
  3. Believe Data, not Models.
  4. Sometimes Models Make Reality

Ok, so it’s important that we understand that there is a distinction between the models, or paradigms that scientists use and the real world. But when I first started to think about these things I got a bit confused. What about computers? Computer people always say “that’s not possible” without any hint that there is a chance that their understanding of how a computer works could be wrong. Unlike scientists, they are, normally, right.

The reason for this is that computers are a special case of building a model. In contrast to science, where we are actually theorising that maybe this model describes the world, when we design computer systems we are building a model, and then deciding to accept whatever the model says as fact.

Let me switch examples now - many people find computers too confusing to follow. The same is true of an election, such as the UK general elections. A model for how to count the votes and how to interpret them has been created. It is available from the government, and its intricacies have been studied in great deal. It’s not a perfect model, though for elections, there is no such thing.

This model gives us a prediction. Once we know how everyone in the country has voted, we can predict who will be the “most fairly elected winner”. At this point, in a scientific model, we would go and measure who the “most fairly elected winner” was, and compare that to our model. In elections, we take the answer from our model, and enforce it in the real world. Computers are the same, although the models are more complex.

The reason I got confused when I first came across this, is surely computers are real, physical things, which obey the real world, why should they obey our models any more than anything else does? It took me a while to figure this out.

Computers are at their most basic level built on semi-conducting transistors. We have a very good (scientific) model of how these work, but perhaps more importantly, for a reasonably small range of conditions (those that exist in a computer) we have looked at them, and observed them, and measured them in enough detail to know how they respond. They have a nice set of properties: they can be configured take two yes/no inputs and produce a yes/no output, in a variety of behaviours. These ways behave exactly like some of the basic logical concepts (AND, OR and so on). So we can use transistors to build a logic engine. A machine that is capable of manipulating our logical models. All that is required is that the behaviour of our transistors doesn’t suddenly change. We then build out logical models in the computer (programming). The “Microsoft Word” model says that when it receives an input showing that the “A” key has been pressed; the state of the screen should be updated to add the letter “A” at the cursor position. We then accept this as reality. Because the model in the computer says there is an “A” there, then there is.

No responses yet

Jan 04 2007

Checking that it is true that true is true should not be hard!

Published by Laurie Tagged as:

I spent most of the last day or so playing with testing in ruby on rails. It should be pretty easy, after all rails has testing built in, right? Well that’s what I thought, and I was right, but only to a point.

Starting off with a simple example

class ItemTest < Test::Unit::TestCase
def test_truth
assert true
end
end

Not much to go wrong there. Check if true is in fact true, and if it is, say its true. Always best to start with a trivial example - something that clearly will work. Of course, this is the real world. Did it work? Did it hell!

Instead I get printed a nice little line telling me that there is an error in testing.rake, line 35. Looking at line 35, it is a pretty simple little line: “If there was an error, show error message”. Great, this is going well.

I probably should tell you a bit of background here. I’m not trying to use a database. All my data is going to be obtained from a nice sexy web service, in a way that is really quite cool, but apparently beyond the expected uses of RoR. James Andrews pointed me in the direction of recipe 14 of Rails Recpies, and a blog post on databaseless rails application testing. Both were of course out of date. So here is what you need to do, of course, this only works for ruby 1.1.6 for sure, and revision of 5832 of edge rails. Who knows if it will work for any other version.

1) Change the file test/test_helper.rb so it reads as follows:

ENV["RAILS_ENV"] = “test”
require File.expand_path(File.dirname(__FILE__) + “/../config/environment”)
require_dependency ‘application’
silence_warnings { RAILS_ENV = “test” }

require ‘test/unit’
require ‘action_controller/test_process’
require ‘action_controller/integration’
require ‘action_web_service/test_invoke’
require ‘breakpoint’

class Test::Unit::TestCase
# Add more helper methods to be used by all tests here…
end

This basically just removes any reference to databases from the test framework

2) Add a file in lib/tasks called something like “remove_database_dependency.rake” and put the following in the file

["test:units", "test:functionals", "test:integration", "test:recent", "test:uncommitted"].each do |name|
Rake::Task[name].prerequisites.clear
end

This goes through all the rake testing tasks, and removes all of their prerequisites (which in my version of rails only consists of loading the database)

There you go, after all of that, you can now tell that true is true!

No responses yet

Oct 10 2006

Can we trust logic - revisited

Published by Laurie Tagged as:

A few days ago (well, more than a few days ago, but some technical problems got in the way since I wrote this post) I wrote about how logic cannot be conclusively shown to be correct. I mentioned that the argument is explained better in the book Gödel, Escher, Bach. I knew it was actually an application of Gödel’s theorem.

That night I went to bed, and picked up my book, “The music of the primes”. I turned to the next chapter, and what do I discover, an analysis of Gödel’s theorem! So I can now explain with a bit more accuracy the history.

I had thought that the theorem was originally presented in terms of sets, but in fact it was originally presented in terms of mathematical axioms. Maths, like any logical system is defined by axioms and rules. The axioms set out a list of facts, things that are “true” by definition. The rules allow you to modify the axioms to create theorems, statements that can be derived from axioms. For a long time, one of the biggest questions for mathematicians was “are our axioms consistent”. That is to say, is it possible to construct two different theorems from the axioms that contradict each other? This is another way of asking if mathematics works. If maths allows us to produce two theorems that contradict each other we cannot trust either of them. We would not be able to allow ourselves to trust any result in mathematics. Unless we simply accept that the axiom’s are consistent.

Gödel’s theorem, in its original form, shows that no set of axioms and rules, can be used on their own, to prove that those axioms are consistent. Mathematics alone cannot prove that mathematics is consistent, that it is valid, and that it works. A greater system is needed, one that encompasses the axioms of mathematics, maybe it produces them as theorems, or has them as axioms itself. Logic is this system. But how to we to be sure the axioms of logic are consistent…

One response so far

Jul 06 2006

Agile Enjoyment

Published by Laurie Tagged as:

As most of the people I talk to on a day to day basis are probably fed-up of hearing about, i’m very keen on this whole  Agile Programming thing thats doing the rounds at the moment. I think it has some problems, mainly when it comes to developing usable software, but on the whole, its pretty good. Perhaps the best bit about it is that it places an emphasis on planning the project in a way that doens’t bore the developers, Lots of different things, and always looking at novel ways to solve problems (if its not a novel way - its been solved, so its not a problem any more)

I also from time to time read Steve Pavlina’s self development blog. He recently posted about a new method of planning how to achieve goals in your life. This is not based on the typical approach, that of achiving your goals as quickly as possible but on having as much fun as possible along the way along the way!

I’m not saying that thats all agile programming is about, but reading though the idea, its not a million miles away either…

Technorati Tags: , ,

No responses yet

Feb 20 2006

Photographic websites

Published by Laurie Tagged as:,

Photography and websites; sometimes they mix well, but so many of the photography web sites I have seen out there just don’t work. They look ugly, or flat, or are just somehow lacking. As both a photographer and sometimes web developer, this is something I have had running about in my head for ages now. The basic problem seems to be, to my mind at least, that the “goals” of creating a good web site are somewhat contradictory to the “goals” of presenting photographs as works of art.

A good website should be usable and accessible. A good work of art should be presented in a way that reinforces the piece. These are not fundamentally conflicting, but it seems that people either care about one, or the other, rarely both.

A friend of mine from Imperial has written Gallery as a general put-some-photos-on-the-web type thing. He is very keen on AAA web accessibility, and making things work for all people in all situations. The site is very good: it works in different sizes; different browsers and even has meaningful behaviour. From a purely computing point of view, its one of the best sites available for photos. But just look at it, I hate to say it about something a friend of mine wrote, but it’s ugly :(! Who wants to go to the effort of taking a photograph they are proud of when it’s going to appear surrounded by so much visual noise, all distracting from the photo?

Flickr is much cleaner in terms of its view, and it’s a very nicely written site (even if it does have long strings of numbers in most of its URLs). But it still doesn’t give any control over the context that your image is placed in. It’s always on a white background, always with the Flickr menu, and so on.

The photographic course I’m attending has, along with reading on the subject, really got me thinking about presentation. A large part of the impact of any piece of art is the surroundings you see it in. A reproduction of a famous oil painting on my wall has different associations to the same work of art elsewhere. It now shows that I have chosen to place it on *my* wall. That says something about me, something that clearly wasn’t included in the original painting. The colour of the wall has an effect, as do the other things on display in the room. If they look like the something depicted in the painting that can change what you see when you look at it. In short, presentation is vital, a photo where the presentation is not decided on is like a piece of writing that hasn’t been spell-checked.

So let’s look at some websites that are designed by photographers rather than computer scientists:

Harriet Logan has a beautiful web site. I think it could do with a bit more text setting a context for the photos, but its beautiful, simple to navigate, and the photos are stunning. It’s also written using Flash. In this case, the Flash is totally unnecessary. The only thing it adds over basic HTML is the nice way that the panes animate when you change from one part of the site to another. You loose the ability to link to a specific photo, and I don’t think an animated bar is worth it, even from a design point of view. Flash makes too many assumptions about the viewer’s environment. This is a debate I often have with my dad. I think I have finally got an argument that will convince even him. I have two monitors connected to my computer – as I imagine do many professional art directors. When I look at this web site, it automatically maximises across both of the screens. The effect of this is that the left half of each photo appears on my left monitor, and the right half on the right monitor. This really is not good. I can imagine a few pissed off magazine editors being so too!

Next we have Lesley Aggar. Lesley is a friend of my dads and an absolutely amazing darkroom printer. Her web site has some very strong point, but ultimately I think it’s a failure. The strong points first. The design is stunning. It’s so elegant that its breath taking. The bad points are that it is in Flash when it doesn’t need to be (see above), but the biggest failure is that a computer monitor simply cannot come close to a fine art print. When I look at one of Lesley’s prints I am speechless, but the computer version just can’t compare. A web site simply cannot work here.

Finally we look at Nick Briggs. Having complained about the last two sites use of Flash, this site doesn’t, it is pure HTML. The site is very simple, but effective. It’s easy to get to the photos, though I do have a few bugbears with it. I don’t like the font, nor do I like the names “portfolio 1″, “portfolio 2″. However there is no denying the fact it doesn’t look as slick, or as smooth as either of the two previous sites. I said before that the Flash doesn’t add much that you can’t do in HTML, and that’s true, but it’s not easy to do the HTML for a site that looks that slick. It’s certainly not a skill that many photographers are going to have.

So I’m left with a conclusion that I don’t really like. It’s possible to make a website that is both good from a computing, usability, and accessibility point of view, and from an artistic point of view. But it’s very hard. It requires both a combination of skills that is rare, and a caring about detail in two very different disciplines, ones that don’t often go together.

One response so far

Jan 09 2006

Online Communities

Published by Laurie Tagged as:,

I have been thinking quite a bit recently about online communities. Not just the technology that allows them, but what exactly is their role. No doubt this has been inspired by my recent work on Paso, a replacement web based online community tool for IVDA.

My friend James pointed me in the direction of Joel Spolsky, who has written a bit about how the tools provided by an online community can have a drastic effect on its culture, and its sociology. For example, putting a “reply” button at the end of a thread rather than the beginning increases the likelihood of people actually reading the thread before replying.

From there, I did a little bit of research about Ray Oldenburg, who has written a book, The Great Good Place, in which he talks about a “Third Place”, somewhere other than work or home for people to gather, and be social. Joel Spolsky pointed out that more and more online communities are becoming a “Third Place” for people. This strikes me as both very true, and very unfortunate. I find that an online community, such as UDS is capable of providing enough social interaction to remove the feeling of loss that can otherwise drive people out in search of a Third Place, but, falls short of providing the social needs that such a place should satisfy. This raises the question, are online communities doomed to be pale shadows of real communities, or have they just not yet reached the point at which they can compare? I think the answer is somewhere in between. They will never (I hope) replace real face to face interaction, but I think the can serve as a great way to maintain social links when its not possible to be physical present, and I think they have much more potential to catalyse real communities. Over the next few months I will be thinking about how this can be achieved in UDS, and no doubt I will be posting some of my thoughts, and maybe even my conclusions here. I would say that the problem of creating viable online communities is no more than 10% solved.

Finally, I would like to point out a talk by Marc Smith, at Microsoft research, who studies online communities, to analyse behaviour patterns. He did a talk that is available on IT conversations. Well worth a listen.

Technorati Tags : , , , ,

No responses yet

Next »