BIT-101 [2003-2017]

Void is an odd bird


I’ve been jumping back into MTASC recently, and tried turning on the -strict option. Started giving me errors for all functions I had declared like this:

function foo(Void):Void
{

}

Telling me that I have an untyped parameter. I had seen something about using Void as a parameter in the comments of this post. To quote: “avoid using Void as parameter to methods. In AS2 it creates no value. The compiler simply creates an untyped parameter named Void.”

OK. I gotta find out more about this. Research let me to this post. Again, to quote: “the compiler instead declares a local variable called Void!”

A local variable called Void? How can you have a local variable with with a key word of the language as its name? Wait. Is Void a key word? A quick search of the key and reserved words list in Flash help says no. Of course, “void” (small v) is, but not its big brother, Void.

So wait a minute. That means you could do something like this:

function x(Void)
{
   trace(Void);
   trace(typeof Void);
}
x("hello");

Surely, that’s not going to work. Hmmm… it does. Damn.

OK, now I’m torn. From a code writing/reading viewpoint, Void is useful. It says, “You ought not to be passing me any arguments.” This is good to know. But if you use it, you are creating a local variable that (in any program written by a sane person) is never going to be used. Also, if you are using MTASC with -strict, you’re going to run into the issue that brought this all up for me.

I think for now, Void and I are going to be on a trial separation. Let things cool down a bit, get a clear perspective on things. I’m going to be doing some thinking… about stuff like, what the hell is Void doing here:

function foo():Void
{

}

???

« Previous Post
Next Post »