|
-
Nov 27th, 2000, 02:34 PM
#1
Thread Starter
Member
I have this question that really bothers me, and it has come time in my app to ask myself this question one more time. Is it good programming technique to put a massive amount of code in the Click event of a button? For example, I am writing the save routine of my app right now, and I'm putting all the save code into filSave_Click, the Save button on the menu. Is that good practice, or should I create a Save subroutine? Or should I put it all in a module, global to all forms? Thanks for the input!
-
Nov 27th, 2000, 02:41 PM
#2
Addicted Member
I put as much code as I can in Modules and Class Modules.
That way i can resuse a lot of the code in that project and other projects, also if your debuging it makes so you can isolate errors better.
-
Nov 27th, 2000, 02:41 PM
#3
transcendental analytic
What are you planning to do with your app? The more you expand it, the more you notice it's better to have it organized, especially save routines should be put either as a private sub in the form for simple SDI apps, or global for apps with several forms calling the save routine.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 27th, 2000, 03:17 PM
#4
Thread Starter
Member
It has gotten rather large, and thus, I REALLY am thankful that I have it somewhat organized. It's an MDI app, so I don't want a global save routine, I don't think. I want each form to be able to save its own data, so I think the best way is to keep the Save routines as private subs. So it is good technique to keep code out of the contol events as much as possible?
-
Nov 27th, 2000, 05:18 PM
#5
transcendental analytic
Yes, that way you keep track of your methods if they are named according to their functionality rather than having a comment above the event. it's not wrong to have code in the events though, i usually have a lot of condition checks and maybe several calls in the event to keep the methods as general as possible and having the detailed parameters leaved to the events.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 27th, 2000, 05:28 PM
#6
Fanatic Member
If you have alot of code that repeats itself in different forms then you should probably break them up into global functions to minimize your code and make it more readable. It also helps if something unexpected happens later, and you need to find a bug.
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Nov 27th, 2000, 06:38 PM
#7
There are many factors that affect this:
1) The complexity of the App. If the App is the next MS-Word or Excel, there's no way I'm stuffing all the code in the Form. On the other hand, if I'm making a 'Hello Word' App, I wont put it in a module.
2) Resuable code. If I need to call a saving routine more than 2 or 3 times, it's easier and more organized to use a standard module and simply call the function from there.
3) Size of code. If I only need to call a function once, but it's over 200 lines long, I would rather place it in a module.
4) Orgainzed Code. If I need the coordinates of 5 rectangles, it's much easier to create a Class Module or UDT for them, than to have 20 variables.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|