ActionScript 3: Void is now void

One small gotcha in the Flex 2 Beta 1 build that a lot of ActionScript coders may get caught up on. Make sure your Void’s, usually used at the end of a function that returns squat, are changed to void. Note the lowercase “v”.

So this:

protected function hello():Void
{
}

Becomes this:

protected function hello():void
{
}

5 Replies to “ActionScript 3: Void is now void”

  1. might seem trivial to most people, but i always thought the cap ‘V’ was ugly; but if we are making changes now, why ‘()’ doesn’t default to ‘():void’ … leaving ‘()’ communicates ‘nothingness’ better to me than ‘():void’ but i’m not sure what others think

  2. First off, thanks Jesse – that would have bit me quickly!

    @eokyere:
    As silly as it may sound, defaulting to void doesn’t sound like a good idea. While not everyone may agree with me, you may still want to have a function be able to return various datatypes. Not typing the return makes it possible to do that and to not return anything if you so desire. If you used void you would be locked into not returning anything, or using Object to indicate the return could be any datatype, but would have to return something.

    I realize that sounds strange going into AS3, but that’s my take on why the default wouldn’t be void.

  3. I think functions should ALWAYS specify return types. AS is such a lienent language, and I think that the language should become more strict. I actually like seeing errors – I know it sounds weird – but then I know that my program has a better chance of running correctly and efficiently.

  4. For everything but constructors, you will see a warning if a function doesn’t return a type. If it is invoked like it returns something, you’ll get an error.

    While the warning is not an error, you pay for it in speed this time around, not just debugging time later on.

    Besides, if you’re lazy or in a hurry, you can always do:

    function getName():*
    {
    }

    The * is now ‘no-type’. There is a word for nothing, null, which is something. Same thing for *; it’s now representational of returning no type… which is differnt than void, which means no returning of values.

Comments are closed.