[Gambas-user] Another syntax sweetness question and request

Tobias Boege taboege at gmail.com
Wed Mar 6 21:28:47 CET 2019


On Wed, 06 Mar 2019, Cedron Dawg wrote:
> Question:
> 
> Which is preferred:  "Function  .. As .." -OR-  "Sub  .. As .." ?
> 
> Anybody have a strong opinion?
> 
> I lean towards, and am using, the latter.  A step away from BASIC perhaps, but one fewer thing a newbie has to learn.  More elegant.
> 

I personally use Function for pure functions, that take input and return
a value without affecting or being affected by state of the current object.
I use Sub for subroutines in the sense that they execute code that might
modify state but don't necessarily return a value. So in my code you'll
never see "Function" without "As", but you will see "Sub" with or without
"As". What I don't use is the third synonym "Procedure". (Maybe I should
employ that for "Sub that doesn't return a value"?)

> Request:
> 
> Would it be possible to make subs return multiple values like Python can?
> 
> That can be really handy. 

I second that. Meanwhile you can emulate this through ByRef. It isn't pretty
but IIRC the way ByRef is implemented could be used to make subroutines
return multiple values. That requires a new syntax for a "tuple L-value"
though.

Regards,
Tobi

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


More information about the User mailing list