We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
What is "void" (Read 1825 times)
What is "void"
Apr 28th, 2005, 5:18am
 
Hi whoever's out there,

The tutorials are great. One quick really remedial question: I don't understand how to use 'void' at all. It doesn't seem to be covered in the tutorial and it looks like it's critically important.

thanks for indulging me,

a. price
Re: Remedial question
Reply #1 - Apr 28th, 2005, 5:45am
 
void is a method that returns no result.

so if you have the following:

float function(){
 return var;
}

you could say me = function();  and it will return you a float.

With void, nothing gets returned.  So when you say void draw(), it does the stuff in the draw method, but isnt concerned with returning any variables.  Im sure TomC or one of the other smarties on this board could give you a better definition though.

Re: Remedial question
Reply #2 - Apr 28th, 2005, 7:57am
 
it's very hard to get an easy answer to many fundamental questions such as "what is 'void'?" i think the originators were a little too clever with names like this and "null". here's a brief explanation:
http://processing.org/reference/void.html
Re: What is "void"
Reply #3 - Apr 28th, 2005, 2:44pm
 
There's a mini-tutorial on methods here, which might help too:

http://stage.itp.nyu.edu/ICM/shiffman/week4/index.html

This is old info for v68, but the basic concept still applies.  I'll be reworking all of these tutorials over the summer so if anyone has comments, critiques, etc., please send them my way!
Re: What is "void"
Reply #4 - Apr 28th, 2005, 9:04pm
 
dang! I was using this explanation so far:
http://www.adishakti.org/subtle_system/void.htm
Re: Remedial question
Reply #5 - May 2nd, 2005, 8:45am
 
flight404 wrote on Apr 28th, 2005, 5:45am:
void is a method that returns no result.
[...]
With void, nothing gets returned.  So when you say void draw(), it does the stuff in the draw method, but isnt concerned with returning any variables.


And by using "void" you're telling the compiler that "void" (or "nothing will be returned") is correct, which is important for the compiler and error-checking in a typed language such as Java.


Chuck Liang, Hofstra University Computer Science, gives an example:
"In any typed language, you cannot have expressions such as

if (A) return "abc"; else return 2;

although such expressions are legal (and sometimes useful) in untyped languages such as Scheme and Perl. The down side of the flexibility of these languages is that it becomes impossible for the compiler to detect type errors before runtime."

Why "void" I suppose that for an object-oriented language, the opposite of an object is a void.

-K
Page Index Toggle Pages: 1