28. marts 2009

Mascara 1.0 Released

The Mascara ECMAScript 4 translator version 1.0 has been released. Download here.
You can try it out online here.

Thanks to everyone who supported along the way!

To sum up, Mascara is a tool which extends JavaScript with a number of powerful features like Classes, namespaces, type-verifications and so on, and then translates this advanced code into "object-code" which will run in any browser. This allows forward-thinking developers to take advantage of future improvement to JavaScript, today.

The background is this: JavaScript was initially designed for small scripting tasks, and does not support features like classes, packages and types useful for structuring larger programs. However, today JavaScript is increasingly used for larger and more complex applications, and these shortcomings becomes a problem. Larger JavaScript applications easily becomes slow and error-prone to develop and costly to maintain.

Luckily, the ECMA organization which maintains the JavaScript standard, have developed a number of improvements to JavaScript, to alleviate these problems. This new standards is known as ECMAScript 4 or ECMAScript Harmony. However, due to browser wars and politics, it may take years before it is implemented in all new browsers, and even then we will have to worry about backwards compatibility with legacy browsers.

Mascara solves this problem, and allows us to use ECMAScript 4 today.

Some of the features in Mascara are:
Of course this is just the beginning. The ECMAScript standard is not yet finalized, and some features may change. Mascara is also working on better packaging and deployment, and we are working on editor-integration.

Mascara can be tried out and explored without installing anything, by using the online tool.
Have fun!

7. marts 2009

Mascara 1.0 Release Candidate

The Mascara 1.0 release candidate has been released. If no bugs shows up in this release, this is the version which will be officially released as Mascara 1.0.

26. februar 2009

Mascara 1.0 beta 7 released

Includes various bug fixes and improvements.

8. februar 2009

A note about warnings versus errors.

Mascara produces two kinds of messages, warnings and errors. This is similar to how compilers for other languages work: A warning indicates something that look suspicious and may be a problem, but an output program is still generated. An error on the other hand is a problem severe enough that no output program could be generated. Errors therefore cannot be ignored.

A notable difference between Mascara and compilers for other statically analyzed languages like Java or C#, is that Mascara produces relatively more warnings but less errors.

For example, referencing a variable which is not defined anywhere, will be an error in most other languages. In Mascara, however, this is only flagged with a warning, and output code is still produced.

Why is Mascara more lenient in this case? Why would anybody want to run code which contains such an error?

The reason is that in some cases it might be intended. For example, the output code can be combined with another script at runtime (in a separate SCRIPT element), and that other script may define the variable. Or the script may use the eval function which allows variable definition at runtime.

It is not necessarily recommended to do things like this, but Mascara realizes that you might be smarter than the compiler, and you may have your reasons.

So if you know what you are doing, warnings like this can be ignored.

Of course, in most cases warnings indicate problems which is indeed typos or mistakes, so it is definitely recommended to inspect the warnings closely!

25. januar 2009

Beta 6 released

With fixes for some obscure bugs.

7. januar 2009

Beta 5 released

It is even better than the last version!

4. december 2008

Beta 4 released

Beta 4 fixes a few bugs, most notably destructuring assignments now works in for-each loops. This is notable since it combines two of my favorite features!

for-each loops iterates through the values of an array (or object). This is different from ordinary for-in loops which iterates through the indices (or property names) of the array/object.

For example:
for each (var x in [7, 9, 13]) write(x);
Will write 7, 9, 13. An ordinary for-in loop (without each) would write 0,1,2. In most cases the for each behavior is what you need.

Destructuring assignments "unpacks" an array or object:
var [x, y] = [2, 4];
sets x to 2 and y to 4.

Combining destructuring with for-each allows us to iterate through complex objects with a simple syntax:
var pairs = [[1,2], [3,4], [5,6]];
for each (var [a,b] in pairs) write(a+b);
I like these features because they remove boilerplate code, and makes some very common patterns clearer.

Destructuring and for-each are already implemented natively in Mozilla, by the way.