torsdag den 26. februar 2009

Mascara 1.0 beta 7 released

Includes various bug fixes and improvements.

søndag den 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!

søndag den 25. januar 2009

Beta 6 released

With fixes for some obscure bugs.

onsdag den 7. januar 2009

Beta 5 released

It is even better than the last version!

torsdag den 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.

søndag den 16. november 2008

Beta 3 released

Beta 3 has just been released, with a few minor bug fixes. Thanks for the feedback, everyone!

mandag den 10. november 2008

Beta 2 released

First stupid bug found and fixed! The issue was with parameters sharing the same name, e.g.

function f(a, a) {}

This gave an obscure internal error. Now it is fixed so it gives a nice "Duplicate definition of name: a" error message instead :-) It is probably not a common situation, but there is one case where I have seen it happen. Consider if someone writes:

function f(int : a, int : b) {}

Do you see the error? The parameter type and parameter name are reversed, which is a typical beginners error for developers used to C-style syntax. In this case it would lead to the previously described internal error, which would be pretty confusing. Now at least it gives a meaningful error message.

Thinking aloud: This makes me wonder though, if there should be a warning if one shadows a built-in name? E.g if I create a variable or parameter named int or String? This is actually perfectly legal in ECMAScript, but I think that in almost all real-world cases it would be a bug.
This blog has moved to http://blog.mascaraengine.com. See you!

This blog is (was) for news, announcements and questions regarding the
Mascara ECMAScript 6 -> JavaScript translator.