October 27, 2010

Java_Script demons

Hi,
 I'm programmer and I'm writing JavaScript.
As any addicted person I have perfectly legal explanation for my behavior and here I'm going to show three things:

  • what motivate me doing this
  • why I think that it isn't addiction
  • how to quit

One

When I tried it first time it feel OK and looks harmless- just a toy, stripped down Java.
But it was naive - there always was monster inside. In fact two monsters and you already been warned about this by authorities such as Wikipedia.

The key design principles within JavaScript are taken from the Self and Scheme programming languages.[8]

Ha! It helps, if only you posses ability to read in between lines and see the future. I wasn't able then but I can help you now.

It is true, JavaScript is LISP and we all know how contagious LISP is. JavaScript hides it's true semantic behind M-expressions but you can convert any "HelloWorld.js" to "good-by-world-p" simple translating to S-expressions syntax and then you will see it true inner.

Second monster comes from Self and disgust in object. Many experienced folks lost there by creating loops with Object.prototype. They were thinking that JavaScript has class'es and that was their last mistake.

One and the only hero was Luca Cardelli, he saw it clearly, he fight it splitting object creature in pieces:

prototype class object
^
real class object
+
trait class object


Two

In the end of the day, I think that problem is more in writing but not JavaScript language. Ones you start programming it, it instantly become Zen. Programs creates programs, objects extended and contract in magical way, even functions not save in that world. It is meta programming and can not be controlled by human.

// Mix in composition helper
Object.extend = function(destination, source) {
  for (property in source) {
    destination[property] = source[property];
  }
  return destination;
}
Object.extend(Array.prototype, Enumerable);

// curry
Function.prototype.curry = function(object) {
    var method = this,
        copy = Array.prototype.slice,
        args = copy.call(arguments, 1);
    return function() {
        var newArgs = copy.call(arguments);
        return method.apply(object == null ? this : object, args.concat(newArgs));
    };
};
Function.prototype.$ = Function.prototype.curry;
function hello(a, b, c) {
    repl.print("I am " + this + " and got: " +
          [a, b, c].join(", "));
};
var f = hello.$("foo", 1, 2);
f(4);

The consequence that you have to face is really horrible. You freezing in time, in space, and in mental state.

Three

The way out is to take control back before coding aimlessly. Learn discipline, limit yourself. You can start today: Learn You a Haskell for Great Good! or do some Scala if you weak.

October 24, 2010

GDC

It's good to have two pupil at home.

They explain me that
gdc(a,b) . lcm(a,b) = a . b

Equally nice to have i-net it explain that because
max(a,b) + min(a,b) = a + b

Can you see connection?

Trivial explanation is in fact that divisibility define lattice on R with meet given by gdc and join by lcm.

October 18, 2010

`three pieces of `four

Hi,

One morning Me, Iri and BGD were coming home after swimming. Cap of hot tee was long anticipated and we bought to it 3 peaces of `cremsnit (aka. Napoleon in U.S.).

Already far from backerei we realize - there 4 of us to share 3 peaces. How to share?

BGD suggest that we split each unit by 4, formally
Solution 1:
3u = 3 * 4 * u/4 = 4 * 3u/4  

I wanted extra unit for myself (irrational part of deal), than we can take module and split it even !
Solution 2:
|2u + i1u| = 1u + 2 * 2 * u/2 = 4 * u/2

Ups.. nobody liked my idea much.

Iri comes with another split where two pieces divided by half and one by four:
Solution 3:
2 * 2u/2 + 1 * 4u/4 = 4 * u/2 + 4 * u/4 = 4 * (u/2 + u/4) 

She argued that this fractal approach guaranty to work if we were N modulo 4:
N * (u/2 + u/4 + .. + u/N)

At the time of last solution we already finished tee.

I told kids folks tail about smart crow who helped divide cheese ball between two baby foxes. After initial split, ether fox wasn't happy with it piece so crow have to eat smaller one and start all over again. Eventually they reach atomic cheese unit. You can imagine how small it was but everybody left happy, including stomachached craw.

Kids agreed that crows solution was fare.
It makes me think about kind of education I provide to them.

October 2, 2010

Smell of Flower

Hi,


I'm programmer. It feels like being a Cylon most of the time and I'm not alone in this.

There is this program which freaks me out. It emulate sunrise and sunset by tuning color temperature on my monitors.

/home/../bin/xflux -l 45.0 -g 21.0 -k 3400

Being totally pro geek I giving you idea: install F.Lux and invite your girl for sunrise date in front of the monitor.

I'm looking forward for `X.Flower program appearing soon.