Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What's the secret meaning of this piece of code?
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00042899
Message ID:
00043038
Views:
43
>
>BTW, I will never understand why params are passed by reference to procs and by value to functions. Why this difference? Can anyone give a good reason?
>
>Vlad
>
Vlad,

By definition, functions return a value, procedures do not. In either case, they should be designed to accomplish one and only one thing (this is referred to as program cohesion). Since the purpose of a function is to return a value (it's one thing), and modifying the parameter list would break down the cohesion. Thus, making the default method by value helps enforce this. A procedure, however, generally accomplishes a task, such as loading an array with values. In order to do this, of course, the parameter list must be passed by reference.

Couple of side notes on this. My tests indicate that VFP always passed objects by reference, regardless. The reason for this, I believe is that the stack is used to pass parameters. When something is passed by value, a copy of it is made. Given that objects can be much more complex than a simple variable, trying to load a copy on the stack not only would be more time consuming, but could exceed the limits of stack space.

When I first read the beginning of this thread, I wondered if the programmer may have inserted that code for fear that the variable would be passed by value, and he wanted to modify it.

Lastly, someone on this thread made the remark that OOP is new. Perhaps to him and FoxPro, but OOP theory dates back to at least 1986, which, in the scheme of things, is ancient.

Regards,

George
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform