Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Naming conventions for custom methods?
Message
 
 
To
18/11/2008 19:57:56
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
01362229
Message ID:
01362805
Views:
31
More italics instream....

>>>>>>Then, Mr chameleon, let me tell you that was also pi..ed off. Bought a lot of java books (language/assembler/....) and the one thing that turned me off what that in java you cannot pass parameters by reference
>>>>>
>>>>>So how do you do anything to an object? Every object has to know how to do it to itself, or else it happens to a temporary copy? That sucxques...
>>>>
>>>>Not sure what you mean about temporary copies but you may have just described encapsulation. An object (class) defines both data and the operations upon that data.
>>>
>>>If not passed by reference, then it's passed as a copy. Whatever happens with that copy gets lost when it goes out of scope and autodestructs.
>>
>>OK, now I see what you are getting at. Typically a class contains something called a property which reads and/or writes each piece of data defined by the class. You update a value by calling its Set method, and retrieve it by calling its Get method.
>
>IOW, you can't access the properties directly as you do in VFP, but need code for each of them. Not sure I like that, either, but that's a different story. "Typically"? I.e. are there exceptions?
>

Sure, you can do it the old way by coding a Get method and a Set method. The main difference is you reference a property like a field rather than a method, i.e. no parentheses. As far as writing code, yes, you do have to write it, but IntelliSense does most of the work for you. Type "prop", press Tab and Enter, and it generates a stub. You change the data type and field name and it propogates those. It's a very simple, quick process.

>>As far as copies, all .NET data types are broadly divided into what are called value types and reference types. Value types, which include almost all the primitive data types such as integers and booleans, contain their values directly and are stored on the stack. Reference types contain references to objects. The reference is stored on the stack and is a pointer to the object itself, which is stored on the heap. I'm sure VFP works the same way behind the scenes.
>
>Works both ways except for objects, which always go by reference. Other than that, parameters in function calls go by value, in DO commands by reference, but you can override each - function call, prefix variable with a @ so it becomes by ref, or in a DO, surround it with parentheses and it goes as a value (because parentheses make it an expression - neat trick without writing a line of code in VFP core :).
>

I haven't completely forgotten how FoxPro works. Not yet ;-)

>>Back to parameters, the default in .NET (as in VFP) is to pass by value. If you don't need to update the parameter, why not? It doesn't matter that it's "lost" when the procedure / method ends. If you do want to update it, that's easy to do -- just attach the "ref" keyword to the parameter. (Or the "out" keyword if you want to initialize it).
>
>If you backtrack on this branch, you'll see this was about "objects always go by ref in Java".

Sorry, I guess I missed that.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform