WISH: auto "result" variable for routines

qsrtech

Active Member
Licensed User
Longtime User
Hi,

I would like to see a "result" variable built into each routine that returns it automatically upon exiting (either completing or using the Return (i.e. exit)

For example:

B4X:
Sub DoSomething(param as boolean) as boolean
'result is automatically included as a local variable as boolean (or whatever type the routine returns)
try
'doing something
result=true
catch
result=false
end try
'upon completion our result is automatically returned, i.e. no need to use: return result
End Sub
 

Vader

Well-Known Member
Licensed User
Longtime User
Not a bad idea, but wouldn't it add confusion? Ie the variable wouldn't be there visibly, but it still worked.

VS has the same problem with the backing local variable behind their automatic properties.
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
??? If you run something that will crash or throw an error you should write your Try/Catch to handle the return value like this already. Why would I want extra overhead in all my methods for this when 9 times out of 10 what I'm executing in the method doesn't throw an error to create a possible issue? B4A actually handles much more of these for you already than when compared to JAVA.

When coding in other advanced IDE environments it will often even tell you it is possible to fail getting a Return due to an If statement/Error/etc and you should use a Try/Catch or Using or make sure that all paths of execution have a Return.
 

qsrtech

Active Member
Licensed User
Longtime User
result

Thank you for your comment Roger. That was just a simple example. There is a multitude of opportunities to use a built in "Result" variable, basically anytime you have a function you will need to return a result. I come from Delphi (originally VB), and this is a built in feature, among many other desirable ones.

I would add that View Events have a built-in "Sender" variable to I can't see this being to difficult to do.
 
Last edited:
Top