Personal


This time I am not alone. Infact, I will soon be joining the entire family. Renu and I left Bangalore yesterday night for Manmad. And so did Papaji and Mammi from Lucknow. What more, Vaibhav will join us from Mumbai!!

So, a full family gathering at Manmad - a half for us en route Shirdi.

Yesterday, when I looked at the final reservation charts, I was a little confused as to what is PQWL and that too two people were alloted the same seat. Then it turned out that the other person will board at Manmad.

That was 7pm yesterday evening.

And then the compartment where our seats were confirmed, the remainder of it was alloted to a family from Tamil Nadu but now settled in Bangalore.

So, we shifted for “seat exchange”.

That was a live compartment because of family and kids. And this is a real dumb one with people confined to themselves.

Anyway, that’s how the life also is - a journey with lots of twists.

Because of cold and no-pillow head-rest during sleep last night, Renu’s back - neck specifically - is in pain. She just can’t turn her head around right now.

Waiting for Manmad to get down and get some medicines for her.

So, we should reach by 3pm. My parents should arrive by 2pm while Vaibhav by 12-1pm! Hurray!

 

A journey ends and another begins. That’s the journey of my life for the past 3 years or so. Today, I’m on my way to Ernakulam. Yes, it’s the train once again. Open windows allowing me to have a closer look at the countryside.

The lush green farms. The dense forest-like trees. The hazy clouds. The cool and cold breeze. The wet soil. The सौंधी odour. It’s back to be in self again.

I seem to have found the lost touch.

Tomorrow it will be trainings once again. It will be consulting, product development, biz plan - all the nasty stuff again. But right now, I stop writing.

Let me enjoy the real life!

 

Good Morning!

We are in train en-route to hometown. Just crossed Secunderabad - where “The train does not halt presently” - but still stopped because of change of engine. And we hope something similar at Jhansi. Let’s see how and what happens.

The next halt is in Nagpur at 5:20pm. And it seems to be in total control of time - at least as of now.

What a journey! Across the countryside. With all windows open - Hey! We’re in the Sleeper Class and not A.C. Gotcha! :)

 

The day is over with the training? No really! The action begins now.

There is already a curfew in Shivajinagar because of Hindu-Muslim riots. Don’t really know when these people with learn. As if they don’t have any other work.

There we - Ashish and myself - need to leave for Lucknow tonight. Couldn’t get a ticket in Ktka Express. Got in Sampark Kranti. Have to get down at Jhansi. And the best part is - the train does not stop at Jhansi!

So, there is a lot of action already waiting for me.

 

(Sutra: noun, that which runs through and holds things together)

JavaScript is a fantastic language to work with. I will, personally, prefer to work with runtime dynamic language like JavaScript than compile-time feature constrained languages like C++ or Java (well, C# is still far richer than C++ and Java).

However, working with JavaScript is not - quote-unquote - trivial noting that majority of the developers start with C/C++ or languages evolved from them.

I’m not here to talk about JavaScript, but 4-Sutras that I’ve developed that one should keep in mind while working with JavaScript.

These sutras are:

  1. All data-types are infinitely flexible.
  2. All objects are infinitely extensible.
  3. Objects are associative arrays.
  4. It’s all about functions.

Let me explain them in some detail…

In JavaScript, we can provide more functionality to any data-types, including the predefined ones through the prototype object. Infact, there exists a JavaScript library with this very name. For example, we need to add a function insertAt to the Array object. Here’s how we can accomplish the task.

Array.prototype.insertAt = function(item, index)
{
  if(index >= 0 && index < this.length)
  {
    this.splice(index, 0, item);
  }
}

And then, I can do:

var a = new Array();
a.push('one');
a.insertAt('two', 0);

alert('Item at index 0 = ' + a[0]);

So, what I meant in “flexible data-types” is that we can add (infact, remove and change as well, at will) the functionality to any data-type (native JavaScript object) irrespective of whether the code for the type is available or not. Isn’t it great?

Coming to the next point - properties / methods associated with any object (instance) is totally configurable. Assume that we have a reference obj to which we want to associate two properties - exx and vayee - and one method checkPoint, we can add that!

Note that this is different from the flexibility of the data-type. Here, only obj will have these properties, any other object obj2 will not have these properties and methods.

var obj = new Object();
bj.exx = "Value x";
bj.vayee = "Value y";

obj.checkPoint = function()
{
  if(this.exx && this.vayee)
  {
    return true;
  }
  return false;
}

What do you gain out of this? Well, this extensibility allows you to grow your objects - at runtime, on demand. And that’s one of the features that I love in JavaScript.

Everybody loves OOAD because it helps us relate programming to our real life - objects with attributes and functionalities. However, it fails to address one key issue - objects in real life grow. They grow as themselves not requiring a child. However, this is absent in almost all languages barring JavaScript and Smalltalk.

btw, do you remember Smalltalk? The world’s first object oriented language. But somewhere, C and C++ grew more popular and we really lost the fun and power of Smalltalk. Sad. :(

So, I am assuming that you’ve understood what I mean when I say that all objects are infinitely extensible.

Let me proceed to the next item. It may or may not be classified as a sutra, because it’s a very basic feature of JavaScript. However, we tend to forget about it while working with JavaScript. So, I thought about making it a sutra so that it’s not forgotten.

Objects internally are implemented as associative arrays, or whatever alternate name you want to use. The effect is that you can use any object in two ways, as given below:

var obj = new Object();
//Assigning as a property
obj.x = "Ex";

//Assigning as an associative array
obj['x'] = "Ex";

//Similarly, assining a function
obj.fn = function()
{
  alert('Hello, World!');
}

//And calling it
obj['fn']();

The two ways to work with properties, as given above, are identical. So, don’t worry if you do not know the name of the method or property at design time. Just store it in a variable and access it using the format given above!

Voila! So easy! And damn powerful! Isn’t it?

And finally, never forget about functions. JavaScript is all about functions - to start with and till the end!

The attributes associated with JavaScript functions are:

  1. Functions are the ways to create data-types: Encapsulation
  2. Functions can be nested, any level deep: Some kind of private functions?
  3. Functions can be used as simple functions as well as constructors
  4. Instance functions (associated with any object) can be called with any context, so that the value of this can be changed on the fly! Voila!
  5. And there’s a lot more magic that you can do with functions in JavaScript.

 

Next Page »