Saturday, April 23, 2011

A quote

".. there are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult."
 -- Tony Hoare, 1980 ACM Turing Award Lecture.

Tuesday, February 22, 2011

Init implementation MVP in Flex / Action Scripts

The motivation is MVP turns out to be less couple as well as more flexible that MVC in my opinion.
This init version have been done without taking into account "Event Bus".

Detail here.

Tuesday, February 15, 2011

Try to understand Git internal in one picture

The image is actually origin from a cool book GitPro by adding a few comments in order to have all key point in one place hopefully...

Sunday, February 13, 2011

How to do multiple row/column dimensions in OLAPDataGrid

A simple OLAPDataGrid sample here.
A good sample having multiple dimensions here.

The key point is that OLAPSet could join each other.
For instance,
var customerSet:OLAPSet = new OLAPSet;
customerSet.addElements(cube.findDimension("CustomerDim").findAttribute("Customer").children);
var quarterSet:OLAPSet = new OLAPSet;
quarterSet.addElements(cube.findDimension("QuarterDim").findAttribute("Quarter").children);
colQueryAxis.addSet(quarterSet.crossJoin(customerSet));


Thursday, November 25, 2010

Saturday, August 21, 2010

Dive into mercurial

IMHO Mercurial is using the Tree structure idea to manipulate the so-called 'trunk/branches/tags' which probably because of its storage scheme revlog.

This tree has only one top (r0) and one end. In case this rule is being broken, merge comes in.

The following graph show a common scenario that one person change something base on r2.
After he make the change, revision goes to 6.
In Subversion, if person do update base on r5, he will get the change which is at r6.
Therefore Subversion need create another folder branches/tags to track change by name.

By contract, Mercurial will ask for merge because it predicates there are two headers r5 and r6 (broke the rules of that Tree).
After merge, new revision r7 created which has parent r5 and r6. (The storage schema revlog always doing append)
So the Tree has one end again.

Doing the change (commit) truns to be extending the tree by appeding nodes start from one specific node.

0 -> 1 -> 2 -> 3 -> 4 -> 5
-----------------> 6

My understanding of tag/branch in mercurial just give each node (revision) a name(alias).
While the branch tracks the change after being branched, tag does not do that.
Therefore we are able to check out any branches/tags without introducing extra folders.

Further reading including but not limit to storage scheme and examples.

Tuesday, August 10, 2010

"Operation" Enum

public enum Operation {
PLUS {
double eval(double x, double y) { return x + y; }
},
MINUS {
double eval(double x, double y) { return x - y; }
},
TIMES {
double eval(double x, double y) { return x * y; }
},
DIVIDED_BY {
double eval(double x, double y) { return x / y; }
};
// Perform the arithmetic operation represented by this constant
abstract double eval(double x, double y);
public static void main(String args[]) {
double x = 2.0;
double y = 4.0;

for (Operation op : Operation.values())
System.out.println(x + " " + op + " " + y + " = " + op.eval(x, y));
}
}

The document says it is anticipated that the need for this will be rare and it it a bit tricky.
How people think it is tricky?


Reference
  1. Java Lang Spec

Increment/Decrement operators

The increment/decrement operators can be applied before (prefix) or after (postfix) the operand.
The code result++; and ++result; will both end in result being incremented by one.
The only difference is thatthe prefix version (++result) evaluates to the incremented value,
whereas the postfix version (result++) evaluates to the original value.

If you are just performing a simple increment/decrement, it doesn't really matter which version you choose.
But if you use this operator in part of a larger expression, the one that you choose may make a significant difference.

The following program, PrePostDemo, illustrates the prefix/postfix unary increment operator:

class PrePostDemo {
public static void main(String[] args){
int i = 3;
i++;
System.out.println(i); // "4"
++i;
System.out.println(i); // "5"
System.out.println(++i); // "6"
System.out.println(i++); // "6"
System.out.println(i); // "7"
}
}

Reference
  1. Java Language Basic