Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sequential In-Line Function Calls
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01508815
Message ID:
01508933
Views:
42
>I've been dabbling in different languages lately (Python, Ruby on Rails, C#, etc.) and one thing I found that I really like with Ruby is the sequential in-line function calls.
>
>In VFP we work inside out which isn't easy to read:
>
myudf(padr(trim(str(lnVariable)),10))
>
>In Ruby (using VFP methods) the same thing would be like this:
>
lnVariable.str().trim().padr(10).myudf()
>
>The sequential way is SO much more readable. Here's my question. Generically, what do you call this difference/paradigm (as I'm sure it's not called Sequential In-Line Function Calls) ?

I think the generic name for this is a fluent interface (although method-chaining is a good description) - a method modifies an object but returns the modified instance of the object to be used as input for the next method. In .NET extension methods provide a simple way on adding your own functions using this paradigm. You've proved that it's possible to achieve the same thing in VFP but I think you will have lost in performance more than you have gained in readability :-{

>
>Secondly, how easy would it be to create this capability in VFP?
>
>Here's a really short (and bad) sample that illustrates the idea.
>
>** SILF.prg - Sequential In-Line Function
>** Allow us to make Ruby type calls
>** lxValue = original source value
>** lcF = functions calls use pipe | for proper variable placement
>**
>** Example call: SILF(5,[STR(|).ALLTRIM(|).PADL(|,3,'0')])
>LPARAMETERS lxValue,lcF
>
>LOCAL lnX,lnFCount,lxReturnValue
>lnFCount=GETWORDCOUNT(lcF,[.])
>lxReturnValue=lxValue
>
>FOR lnX=1 TO lnFCount
>	lxReturnValue=EVALUATE(STRTRAN(GETWORDNUM(lcF,lnX,[.]),[|],[lxReturnValue]))
>ENDFOR
>
>RETURN lxReturnValue
>
>
Previous
Reply
Map
View

Click here to load this message in the networking platform