Showing posts from March, 2012

Complexity of Time

I find time fascinating. I also find it a surprisingly complex subject. You have both TimeZones and Calendars which change from place to place but also over time. There are a number of interesting web sites on the subject. Some of the trivia I find interesting There was no year 0, in fact there was no number 0 when the Julian Calendar was created. The year before 1 AD was 1 BC. If Christians celebrate Jesus' birth on December the 25th was this is 1 AD or 1 BC? The start of the Julian calendar was March the 25th (nine months before 25th of December) and the time of the vernal or spring equinox at the time. The autumnal equinox was changed to be March 21st a few decades later. This assumed that Jesus came to earth March 25th (nine months before Dec 25th), the first day of 1 AD. March the 25th was also considered the anniversary of Creation. Sept means 7, Oct means 8 and Nona means 9th, and Dec mean 10th and in Roman times they were the Seventh, Eighth, Ninth and Tenth months.

Art of Programming

I have been wondering whether my blog has more to do with art than practical purpose. I say this because I want to blog to simulate ideas rather than be a how to guide on things which most people will possibly never have a need for. There are only two reasons we create art: for ourselves and for others -- Brenda Behr Art has no other purpose than to brush aside... the conventional and accepted generalities, in short everything that veils reality from us, in order to bring us face to face with reality itself. -- Henri Bergson Art is the perpetual motion of illusion. The highest purpose of art is to inspire. What else can you do? What else can you do for any one but inspire them? -- Bob Dylan Art for art's sake, with no purpose, for any purpose perverts art. But art achieves a purpose which is not its own. ― Benjamin Constant, 1804 My view is that art cannot be created purposely, and it has no direct function. However, it has an important role which is to stimulate creat

Quotes relating to System Design

There are a few quotes I think of when thinking about computer design. These are not specifically about computers, but I think they are appropriate. Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. -- Antoine de Saint-Exupery, French writer (1900 - 1944) "Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it’s worth it in the end because once you get there, you can move mountains.” Steve Jobs -[BusinessWeek, May 25, 1998,] Often contentious topics can labour under the assumption that it makes any difference in the first place. DEVENTER (n) A decision that's very hard to make because so little depends on it, such as which way to walk around a park -- The Deeper Meaning of Liff by Douglas Adams and John Lloyd. Everyone can learn something from your mistakes Mistakes - It could be that the purpose of your life is only to serve as a warning to others.

Adding code to an annotation

Overview Sometimes you have a framework you would like to be able to add custom annotations to. The problem is; how do you define what this custom annotation does. A possible solution is to use a nested enum. Nested types You can nest an interface, a class, an annotation or an enum inside any of these types. e.g. public class A { public interface B { public enum C {; public @interface D { public class E { // etc etc } } } } } But is this useful or just a novelty? Adding functionality to an annotation You can define an interface the framework can call to determine how your custom annotation should behave. import java.lang.reflect.Member; /** * @author peter.lawrey */ public interface AnnotationHandler<A> { void process(Model model, Member member, A annotation); } One way of associating the implementation with the annotation itself is to provide a Singleton enum w

Presentation on Using Shared Memory in Java

Yesterday evening I gave a presentation on using shared memory in Java. The slides are here. The library (and its source) mentioned is here Java Chronicle

Different results summing a double[]

Overview The order you add double values can give you different results. This gets worse as the sum approaches 0 as the error is large compared with the result. Something I found interesting recently is seeing how many possible results you can get depending on the order you sum the values. Looking at variations on the sum In the following code, the program creates random numbers around zero, adding a value to the list which ensures the sum is almost zero. It lists the different sums it finds. List<Double> doubles = new ArrayList&ltDouble>(); Random rand = new Random(); double sum0 = 0; for (int i = 0; i < 1000; i++) { doubles.add(rand.nextDouble() - rand.nextDouble()); sum0 += doubles.get(doubles.size() - 1); } doubles.add(-sum0); SortedSet<Double> sums = new TreeSet (); for (int i = 0; i &lt 10 * 1000 * 1000; i++) { Collections.shuffle(doubles, rand); double sum = 0; for (double d : doubles) sum += d; if (sums.add(sum))