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.
IndexProgramming Questions & HelpSyntax Questions › Same identifier used for function and variable
Page Index Toggle Pages: 1
Same identifier used for function and variable (Read 641 times)
Same identifier used for function and variable
Jan 6th, 2008, 9:48am
 
I noticed that Processing does not give any errors when an already existing function name is used as a variable.

For example, this seems to work:
Code:
int max = 5;
println(max(2,3));
println(max);


In C or C++ this is illegal within the same block.  Is this really allowed/intentional in Processing?  Can it cause any trouble?  I am looking for some reassurance!

Something unrelated:  The colour selector seems to be broken in version 0135.  The colour that is picked is not the same that is clicked on.
Re: Same identifier used for function and variable
Reply #1 - Jan 7th, 2008, 12:12am
 
Cannot confirm or reassure this, but if it's with your version, it's maybe worth to do a bug report (if you haven't done this already Wink ...
Re: Same identifier used for function and variable
Reply #2 - Jan 7th, 2008, 6:44am
 
Well, it seems that the built-in processing symbols use this too, as there is both a frameRate variable and a frameRate() function.
Re: Same identifier used for function and variable
Reply #3 - Jan 7th, 2008, 7:49am
 
This is allowed in Java as far as I'm concerned.

I use stuff like

boolean visible = false;


and then for a "getter"

public boolean visible(){
 return visible;
}


Not really good and could be confusing but all you have to keep in mind is the () for methods. It's illegal in C / C++ because of function pointers... saying "visible" will refer to the pointer for that function if I'm not mistaken.
Re: Same identifier used for function and variable
Reply #4 - Jan 7th, 2008, 8:40am
 
i do the same thing of mflux.

variables in java is reference, i understand.

"TYPE var" in Java is similer to "TYPE& var" in C++.
Page Index Toggle Pages: 1