[Gambas-user] Array.Sort

Tobias Boege taboege at ...626...
Fri Jan 9 11:34:24 CET 2015


On Fri, 09 Jan 2015, adamnt42 at ...626... wrote:
> On Fri, 09 Jan 2015 01:12:50 +0100
> Beno?t Minisini <gambas at ...1...> wrote:
> 
> > Le 09/01/2015 01:09, T Lee Davidson a ?crit :
> > > "The empty set of parentheses is REQUIRED when sort is used as a function to return an array without the optional mode parameter"
> > >
> > > I don't know. Wouldn't it be more accurate to say that the parentheses are required to be able to use the function call as the object which it
> > > returns; as opposed to the syntax, without the parentheses, referring to the function itself?
> > >
> > >
> > > Lee
> > 
> > Why not just say that?
> > 
> > ? You can omit the "()" at the end of a function or method call 
> > statement only. If you don't understand the previous sentence, always 
> > use "()" to call a function or a method. ?
> > 
> > :-)
> > 
> 
> I would have thought that the issue is "the other way up", viz:
> 
> If any class method is used as the predicate of an assignment or as the implied object of a command, then the parentheses "()" must be included, even if any or all (optional) method parameters are not specified. The parentheses "()" may be left out if the method is used purely to manipulate the internal state of the object (whether or not that method may return a value).
> 
> Examples
> Consider a hypothetical class method "Negate" that inverts the value of some attribute of the object and returns that value. Thus the "()" is required for:
> 	SomeLocalVar = MyObject.Negate()
> 	Print MyObject.Negate()
> but
> 	MyObject.Negate
> is perfectly legal. In this case the value is inverted but the result is "thrown away" by the interpreter.
> 
> I cannot think of any exceptions to this.
> 

Me neither but it should be noted (NOT on the Array.Sort() wiki page but in
our brains) that the behaviour is different for intrinsic functions, since
Format$(Now) works.

Note that I, as a matter of consistency, *always* append parentheses to
method calls, or else my internal parser gets confused later when reading
the code. (Although sometimes it's cool to pretend that Now is a variable
which gets updated through magic.)

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list