Web Info & Tutorials

February 4th, 2008

STOCKS LOWER ON RAFT OF U.S. FINANCIAL SECTOR DOWNGRADES

A blackamoor walks by an electronic pass commission in downtown Hong Kong which shows the city’s criterion finger increases 908.50 points to 25,032.08 on Monday, Feb. via river Business Magazine

February 4th, 2008

EXT JS IDE SUPPORT ROUNDUP

There’s been a lot of talk lately about the different IDEs and the support they offer for the various JavaScript libraries. Ext’s uber-coder, Jack Slocum, has put up a blog entry explaining which IDEs support the Ext JS framework:

The Ext 2.0 API is very extensive and remembering all of the functions, properties or configs available is virtually impossible. The API documentation is very thorough, but it would be nice if IDEs would provide code assist options in JavaScript as they do in other languages such as Java and C#. Luckily, there are some IDEs and plugins available that do just that — and also have direct support for Ext 2.0.

Included in the mix are:

This great news and it shows that IDE vendors are taking JavaScript frameworks seriously. Anything that makes development easier is definitely welcome.

February 4th, 2008

ADOBE TAMARIN TRACING JIT FOR JAVASCRIPT

Chris Double attended the Tamarin Tech summit, and gives us some information about Tamarin Tracing the new trace based JIT experiment:

‘Tamarin Tracing’ is an implementation that uses a ‘tracing jit’. This type of ‘just in time compiler’ traces code executing during hotspots and compiles it so when those hotspots are entered again the compiled code is run instead. It traces each statement executed, including within other function calls, and this entire execution path is compiled. This is different from compiling individual functions. You can gain more information for the optimizer to operate on, and remove some of the overhead of the calls. Anytime the compiled code makes a call to code that has not been jitted, the interpreter is called to continue.

Apparently the JIT for Lua is also being written using a tracing jit method and a post by Mike Pall describes the approach they are taking in some detail and lists references. A followup post provides more information and mentions Tamarin Tracing.

Brendan Eich talked about trace based JIT’s as being the future of JavaScript VM’s, and a reason why we will see insanely fast JavaScript without needing all of the type fun.

Here is one simple benchmark of a fibonaci equation solution that doesn’t do any caching tricks:

# Turn off the tracer
$ shell/avmshell -lifespan -interp fib.abc
fib 30 = 1346269
Run time was 26249 msec = 26.25 sec
	
# Turn on the tracer
$ shell/avmshell -lifespan fib.abc
fib 30 = 1346269
Run time was 1967 msec = 1.97 sec

Chris finishes with some fun facts:

  • The interpreter is written in Forth. There are .fs files in the ‘core’ subdirectory that contains the Forth source code. Each ‘abc’ bytecode is implemented in lower level instructions which are implemented in Forth. The tracing jit operates on these lower level instructions. The system can be extended with Forth code to call native C functions. The compiler from Forth to C++ is written in Python and is in ‘utils/fc.py’
  • The jit has two backends. One for Intel x86 32 bit, and the other for ARM. See the ‘nanojit’ subdirectory.
  • The complete interpreter source can be rebuilt from the Forth using ‘core/builtin.py’. This requires ‘asc.jar’ to be placed in the ‘utils’ subdirectory of Tamarin Tracing.
February 4th, 2008

FUNCTIONAL PROGRAMMING WITH JAVASCRIPT AND DOJO

Eugene Lazutkin has written a piece on Functional fun in JavaScript with Dojo where he delves into the land of functional and how it is available in JavaScript.

Eugene maps out some of the helpful functions that JavaScript itself has added over time:

  • JS 1.6 (in Firefox 1.5) introduced
    so-called Array extras:
    special Array methods, which help to simulate lists with arrays:
    indexOf(), lastIndexOf(), every(), some(), filter(), map(),
    forEach(). The last five methods are especially important because
    they help to eliminate the most common direct loops.
  • JS 1.7 (in Firefox 2) introduced Array comprehensions borrowed from Python. The new syntax allows to generate arrays using
    a compact yet clear notation reducing the possibility of errors. And
    of course iterators and generators will helps us with cleaner loops
    too. Another goody is the block scope with “let”.
  • JS 1.8 (in Firefox 3) brought us
    more Array extras:
    reduce() and reduceRight(). They give us a native support for
    all-important folds. Another notable additions are expression
    closures (simplified one-line functions), and generator expressions.
  • JS 2 (ES4 PDF)
    takes us even farther: for each statement, tail calls, and the whole
    raft of language improvements. Presumably JS 2 will come with the
    next generation of JavaScript virtual machines helping to reduce
    penalties for using new abstractions.

... and how Dojo implements many so you have cross browser access.

He goes into detail on his favourite five: filter(), map(), forEach(), every(), and some().

E.g.

JAVASCRIPT:
var percents = dojo.map(values, function(val){ return val / sum; });

var sum = 0;
dojo.forEach(values, function(val){ sum += val; });
 

Next he goes beyond core to dojox.lang.functional where lambda is your friend:

JAVASCRIPT:
var div2 = df.lambda("/2");
 

What about performance? We get a nice run down on the performance of the Dojo functions compared to native ones if they are available.

Very thorough indeed.

February 4th, 2008

LOW PRO FOR JQUERY

Dan Webb has ported Low Pro to jQuery and along the way discusses differences between Prototype and jQuery:

The one big reason was that, while jQuery was super simple and concise when working on smaller projects, it offered no help in structuring larger applications. All you get in jQuery, aside from Ajax methods and a handful of utilities, is the ability to select nodes then doing something with them. On the other hand Prototype is much rounder in scope. It generally plumps out JavaScript as a language adding lots of useful methods to built-ins, a host of functional programming tools and recently a full Class-based OO system with inheritance and the whole shebang which has formed the back bone of Low Pro’s behavior classes.

Let's not get into that debate though, instead, lets just look at the port.

How do you use it?

Create a class

JAVASCRIPT:
Draggable = $.klass({
  initialize: function(options) { },
  onmousedown: function() {}
});

GhostedDraggable = $.klass(Draggable, {
  onmousedown: function($super) {
    // do extra stuff here then call original method...
    $super();
  }
});
 

Attach behaviour

JAVASCRIPT:
$('div.product').attach(GhostedDraggable, { anOption: thing });
 

Also, if you are using livequery jLow (I had to use it Dan!) will play nicely and work as the DOM changes too!

February 4th, 2008

NAMESPACED MADE EASY WITH PROTOTYPE

kangax keeps up his "Prototype by example"-ness by showing a use of Enumerable#inject.

He shows us namespacing made easy:

JAVASCRIPT:
String.prototype.namespace = function(separator) {
  this.split(separator || '.').inject(window, function(parent, child) {
    return parent[child] = { };
  });
}
 

And then you can use it via:

JAVASCRIPT:
// Default separator is '.'
'foo.bar.baz.quux'.namespace();
 
foo.bar.baz.quux = 'Nothing special...'; // => "Nothing special..."
 
// Or using a custom one
'MY_AWESOME_APPLICATION::util::DOM::dimensions'.namespace('::');
 
'dimensions' in MY_AWESOME_APPLICATION.util.DOM; // => true
 
February 4th, 2008

ERLYJS: JAVASCRIPT ON ERLANG

Roberto Saccon has cursive ErlyJS, a programme that takes JavaScript and makes it separate on the Erlang VM.

It is rattling primeval days, and supports:

  • Support of a tiny lowercase Subset of Javascript
  • Compilation to Erlang shine files
  • Global Javascript variables are stored at runtime in the Erlang impact lexicon (therefore: don’t ingest orbicular variables !)
  • Local Javascript variables are replaced during assembling with Erlang variables

This isn’t the prototypal taste of Erlang recreation that we hit seen. We posted on Er.js, the accumulation that aims to provide you Erland same IPC for JavaScript.

February 4th, 2008

BANK OF MONTREAL, CANADIAN IMPERIAL, CUT BONUSES AS WRITEDOWNS CURB PROFIT

Bank of Montreal and Canadian Imperial Bank of Commerce scrapped bonuses for some of their top executives in 2007 after the two lenders recorded trading losses and debt writedowns. via Bloomberg.com