Hi Dragan,
>Talking about readability, this is very confusing.
Yes it confused me too in the beginning...
>LOCAL Hello as SayHello
>What, a variable is declared as a function? And actually just a declaration, because the function doesn't exist. And it's not even a function class, it's a dummy. Next it doesn't say FUNCTION French() AS SayHello, but "as string". Then
>Hello = English
Yes the compiler is clever enough to understand that DELEGATE is a Type and hence can be used as an assignment type. It returns a string hence our SayHello will also returns a string.
>variable is assigned a function (!).
Yes it is a variable that holds a pointer to a function.
> How would that name translate into one of those function names? Would you have to write a long case statement with
>case method="m01"
> CalcFn=method01
No, you would first create a DELEGATE to declare parameters and return value
DELEGATE InterestCalc(rStart AS REAL4, rInt AS REAL4, nPeriods AS INT) AS REAL4
FUNCTION Compound(rStart AS REAL4, rInt AS REAL4, nPeriods AS INT) AS REAL4
RETURN nStart * (1.0 + rInt/12.0) ^ nPeriods
FUNCTION Straight(rStart AS REAL4, rInt AS REAL4, nPeriods AS INT) AS REAL4
RETURN nStart * (1.0 + rInt / 12) * nPeriods
LOCAL myCalc AS InterestCalc
SWITCH intType
CASE Compound
myCalc = Compound
CASE Straight
myCalc = Straight
END SWITCH
SomeOtherFunction(myCalc)
FUNCTION SomeOtherFunction(calc AS InterestCalc) AS VOID
? calc(100.0, 10.0, 36)
RETURN
>Keep in mind that in fox I could simply add a method99.prg and store "m99" in the contracts table without even recompiling the project - just existence of
Yes because fox is an interpretive language, X# also have macro substitution, and also add something called a codeblock that can be runtime compiled. It is very similar to delegates, but late bound. That is however a discussion on its own.
>You can see how this can look confusing for native foxen who don't speak .net - and such things were mostly the reason I still don't speak it :).
Indeed, but just wanted to show some of the new features that X# brings to the table, love it or hate it, it is there to be used...