void data type

Subscribe to void data type 8 posts

avatar for 422537 422537 116 posts
Flag Post

Hi,

I often hear people say that the void data type is used for methods that don’t return a value, however that sounds pretty vague. A value for what? Does it mean it’s assigned to methods that don’t return a value to a variable?

Event if that was the case, I’m failing to see the logic behind their use at all. Can someone please clear this up for me?

 
avatar for UnknownGuardian UnknownGuardian 8207 posts
Flag Post

Wow. Did some research just cause. Semi-related to your question.

Livedoc’s Void.

void Operator

It’s an operator. Never realized that.

Evaluates an expression and then discards its value, returning undefined

Even more cool. It actually returns something.

The void operator is often used in comparisons that use the == operator to test for undefined values.

I’m a bit confused at this statement.

 
avatar for 422537 422537 116 posts
Flag Post

Ok I think I kinda get it. if it’s similar to the == operator, then it’s essentially saying that the directives contained within that method are equal to it. So next time the method is called on it’s own, it’s calling everything that was contained within it because they are one and the same i.e identical in information? That makes sense I think.

 
avatar for UnknownGuardian UnknownGuardian 8207 posts
Flag Post

No, not at all. That info was mainly just stated cause it was cool. I tried to avoid answering the question since I posted that information (thus confusing you anyways I guess).



I think I’ll try here.

Void doesn’t return a value:

public function moveCarFoward():void {
   y += 5;
}

Other types (example uses Number) return a value:

public function getRemainingFuel():Number {
  return _remainingFuel;
}

For the first, we want to tell a car to move forward. We don’t really need to know anything about the car, after it moved, for that method. Hence, we don’t have to return anything (:void). However, for the second, we are asking how much fuel does the car have. So we need to get a value. We get this value by returning it in a function. The function has a :Number type at the end, and has the statement return _remainingFuel; in it.

 
avatar for NineFiveThree NineFiveThree 1378 posts
Flag Post
Originally posted by 422537:

Hi,

Does it mean it’s assigned to methods that don’t return a value to a variable?

It’s not necessarily returned to a variable, could also be another function, operator, etc…
But if it’s a void function, you cannot do that, because – well – there’s nothing returned.

 
avatar for JohnnyBohnny JohnnyBohnny 113 posts
Flag Post

It’s odd why they chose the name ‘void’. I guess the origin comes from astronomy, where it is “the vast empty space between filaments (the largest-scale structures in the Universe), which contain very few, or no, galaxies.” It’s not like a singularity, where something goes in, and never comes out.

 
avatar for BobTheCoolGuy BobTheCoolGuy 3768 posts
Flag Post
Originally posted by JohnnyBohnny:

It’s odd why they chose the name ‘void’. I guess the origin comes from astronomy, where it is “the vast empty space between filaments (the largest-scale structures in the Universe), which contain very few, or no, galaxies.” It’s not like a singularity, where something goes in, and never comes out.

My bet would be that they just chose it because Actionscript-3 is a C-like language and C uses void in places to represent nothing.

 
avatar for 422537 422537 116 posts
Flag Post
Originally posted by UnknownGuardian:

No, not at all. That info was mainly just stated cause it was cool. I tried to avoid answering the question since I posted that information (thus confusing you anyways I guess).



I think I’ll try here.

Void doesn’t return a value:

public function moveCarFoward():void {
   y += 5;
}

Other types (example uses Number) return a value:

public function getRemainingFuel():Number {
  return _remainingFuel;
}

For the first, we want to tell a car to move forward. We don’t really need to know anything about the car, after it moved, for that method. Hence, we don’t have to return anything (:void). However, for the second, we are asking how much fuel does the car have. So we need to get a value. We get this value by returning it in a function. The function has a :Number type at the end, and has the statement return _remainingFuel; in it.

Oh right that makes sense. I guess I just hadn’t used functions in that way so the whole value return thing confused me. Thanks.

Originally posted by NineFiveThree:
Originally posted by 422537:

Hi,

Does it mean it’s assigned to methods that don’t return a value to a variable?

It’s not necessarily returned to a variable, could also be another function, operator, etc…
But if it’s a void function, you cannot do that, because – well – there’s nothing returned.

Right of course. I guess I would have naturally acknowledged this sooner or later but I can’t stand working with concepts that I don’t understand so I had to ask. Thanks.