Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
One big procedure file vs. hundreds of small UDFs
Message
From
03/02/2002 16:26:09
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00614343
Message ID:
00614612
Views:
22
This message has been marked as a message which has helped to the initial question of the thread.
Nadya,

I used to use individual PRGs for each function. I still do so for generic functions for the same reasons mentioned by David and Sergej. However, with the event of VFP7 and intellisense, I tend to group similar functions into PRG based classes. I really love to type oWin32Api.w (and intellisense immediately proposes WNetAddConnection2 and displays the parameters WNetAddConnection2(tcNetworkName, tcDriveLetter, tcUserName, tcPassword).

I think in addition to PRGs vs procedure files you should also consider classes vs. procedural code. Intellisense as mentioned above is one advantage that is only available in classes. Another very handy advantage of classes vs. procedural code is the fact that you can take advantage of the constructor (init) to prepare an environment that you need for a function to work in. This runs only once when the object is instantiated and is available every time you call a method of this object until the object is released. As an example, I have written a class that does currency conversion and related things. Most functions of this class need to lookup data in different tables. If I did this with procedural code, then I would either need to open/close the tables each time (to keep things clean) or leave them open (for performance reasons). With a class, I can open the tables in a private datasession during init() and restore the environment upon release(). Additionally, with a class you can nicely encapsulate things.

There's a price to pay. It's obviously a bit more work to call a method in class than simply calling a UDF because you have to instantiate the object first. Also creating/debugging a class based method is a bit more painful since you need to release the object before you can modify the method then you need to reinstantiate it. Therefore, I usually first create/test/debug a PRG based method and once it's working move it into the class.

With regards to performance, I didn't find a significant difference between procedural vs. class. This was with VFP6 SP5.

Just my 02 cents
>Hi everybody,
>
>Yesterday I was totally lost in all different kind of programs, I created or found here and put in our CommonWg\Progs directory. So, I'm thinking, may be it's better to put some of them (which are used most) in our wgUtility.prg
>
>What is better in general: one big procedure or lots of small ones? Which approach do you use? Sorry, if this was asked before (may be even I asked it)...
>
>Thanks in advance.
Daniel
Previous
Reply
Map
View

Click here to load this message in the networking platform