Local Sub or Function

Is there a way to add a (Local) Sub or Function within in a Method?

LG says no, but maybe there’s another way?

What would be the point???

I do this alot in Swift… it tends to encapsulate the logic, if there is a need for small functions that are only called by a single larger function.

func  myBIGFunction() {
    func mysmallfunction() { ... do stuff }
    //
    mysmallfunction()
}
1 Like

No
A sub within a sub … no

For local subroutines? I find them very useful. Not everything needs to be class-wide.
I also use inline functions in everything but Xojo. It’s not everyone’s cup of tea, but I find it efficient.

I find that whenever I write the same code twice, it is useful code that should be abstracted into a method of its own. Makes reusing that code easier too.

as do I… but also found situations where the internal function doesn’t need to be external to the the function using it… so the logic is all in one package

Both can be true
If the private function needs to be exposed so other can use it then great - do so
But there can be cases where a private bit of code as a function simplifies some other code but doesnt need to be exposed to anything else

Xojo doesnt support those private functions

1 Like

A common use for inline functions are custom comparison operations for sorting, but there’s plenty of places it makes sense to use them.
It would be nice if Xojo had that, but not holding my breath!