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!

Ingen kommentarer:

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.