Wednesday, June 26, 2013

Turning on debug tracing in Eclipse

 Create a file called ".options" at the root of your eclipse install (sibling of eclipse.exe). In this file put the following:

org.eclipse.core.resources/debug=true
org.eclipse.core.resources/build/invoking=true

Then start eclipse with the "-debug" command line argument. This will now print out information on when each builder is invoked, and how long it ran. This is the best way to get an accurate picture of what is happening - perhaps it is a particular project, or particular build, that is causing all the delays. Having this information will give us a better picture of what's going on.


sources:
http://wiki.eclipse.org/FAQ_How_do_I_use_the_platform_debug_tracing_facility%3F
http://www.eclipse.org/eclipse/platform-core/documents/3.1/debug.html

Friday, June 21, 2013

Eclipse spy plugin - ALT+SHIFT+F1


It's currently part of org.eclipse.pde.runtime plug-in.

While working on eclipse, at any point of time if you want to know which class is currently being called, you can just press "ALT+SHIFT+F1". It will show you the dialog like below with classes which are involved.


Wednesday, June 5, 2013

JavaScript Learning #8 - Object-Oriented JavaScript Tip: Creating Static Methods, Instance Methods


Custom JavaScript objects can have instance methods (function that are associated with a particular JavaScript object), but like other Object-Oriented languages, they can also have static methods, that is functions that are associated with the JavaScript class that created an object, as opposed to the object itself. This is useful in cases where a function (a.k.a. a method) will not be different in different object instances. Let’s look at an example…

Suppose you created a class to handle simple arithmetic calculations:

function Calculator()
{

}
To begin with, an instance method could be added to this class in one of two ways, either inside the constructor or through the class prototype. In this example, one method called multiply will be created, which returns the product of two values multiplied together. First, implemented in the constructor it looks like:

function Calculator()
{
this.multiply = function(val1 , val2)
{
return (val1*val2);
}
}
Via the class prototype, which is a more readable solution in my opinion, it would look like:

function Calculator()
{
}

Calculator.prototype.multiply = function(val1 , val2)
{
return (val1*val2);
}
Use of this method would then occur through instances of the Calculator class, like so:

var calc = new Calculator();
alert( calc.multiply(4,3) ); //pop-up alert with product of 4 times 3
However, it shouldn’t really be necessary to create an object to use the multiplymethod, since the method isn’t dependent on the state of the object for its execution. The method can be moved to the class to clean up this code a bit. First the class definition is created, which looks almost identical to the instance method declaration above, with the exception of the prototype keyword being removed:

function Calculator()
{
}

Calculator.multiply = function(val1 , val2)
{
return (val1*val2);
}
Now the multiply method can be called through the class itself, instead of an instance of the class, like so:

alert( Calculator.multiply(4,3) ); //pop-up alert with product of 4 times 3

source:
http://blog.anselmbradford.com/2009/04/09/object-oriented-javascript-tip-creating-static-methods-instance-methods/

JavaScript Learning# 7 - Static variables and methods

Static variables and methods

A function is an object. That provides us with a nifty way to create static variables or, in other words, the variables which persist along multiple calls.
For example, we want a variable which counts function calls.

Static variables

There are languages which allow to put a static keyword before a variable, and then such variable is not cleared in next calls.
Example of a static variable in Java language:
1static int count = 0;void f() { 
2
3 count++;
5}
6 
7new f(); new f(); new f(); // 1 2 3
In JavaScript, there is no term or keyword static, but we can put such data directly into function object (like in any other object).
1function f() {
2  f.count = ++f.count || 1 // f.count is undefined at first
3 
4  alert("Call No " + f.count)
5}
6 
7f(); // Call No 1
8f(); // Call No 2
Of course, a global variable can keep the counter, but static variables lead to a better architecture.
We could make the code more universal by replacing f with arguments.callee.
1function f() {
2  arguments.callee.count = ++arguments.callee.count || 1
3 
4  alert("Called " + arguments.callee.count + " times")
5}
Now you can safely rename the function if needed Smile

Static methods

Static methods, just like variables, are attached to functions. They are used mostly for objects:
01function Animal(name) {
02  arguments.callee.count = ++arguments.callee.count || 1
03 
04  this.name = name
05}
06 
07Animal.showCount = function() {
08  alert( Animal.count )
09}
10 
11var mouse = new Animal("Mouse")
12var elephant = new Animal("elephant")
13 
14Animal.showCount()  // 2