|
-
Apr 4th, 2024, 03:41 PM
#1
Thread Starter
PowerPoster
Declarations and Procedures in Class Modules vs. Dependencies
I keep reading that Class Modules should be self-supporting. That makes sense but it also means when you have, like in my app, over 100 class modules and they're all using bits and pieces of different .bas modules such as sorting arrays, API declarations and whatever else.
Is it best practice to copy and paste all of that into each class that uses them?
These dependencies are all over the place so making a dll isn't really a good option.
The only time it's really a problem is when I post code here and have to scamper all over my project finding all the dependencies so anyone else can try to use it.
For myself it's kind of a pain when I pull something into a new project but usually it only takes about 10 minutes to get it all sorted out by starting the project which then asks me what's going on with that thing that's not there and I go find it and pull it into the project too.
But let's say this was pro-development.
What is best practice?
Last edited by cafeenman; Apr 4th, 2024 at 05:36 PM.
-
Apr 4th, 2024, 05:04 PM
#2
Re: Declarations in Class Modules vs. Dependencies
For me, it's just a matter of what I ultimately want to do with that class. If I want to post (and support) it in the CodeBank here, I'll make it as self-sufficient as I can.
If it's a specialized class in my primary project, I don't mind if it's got calls to general BAS modules, because it'll never be used for anything else.
For me, it's a very gray area.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Apr 4th, 2024, 10:54 PM
#3
Re: Declarations and Procedures in Class Modules vs. Dependencies
Best practice, but best practice for what? Yes, for posting it is best practice if possible to make self contained classes.
Unless you have 5 classes that use the same function and you decide to put it in a bas module once and for all them to use it.
-
Apr 4th, 2024, 10:57 PM
#4
Re: Declarations and Procedures in Class Modules vs. Dependencies
Sharing code here is usually not just "I'll post what I have, like it is", but it requires some work to make something shareable.
-
Apr 5th, 2024, 09:12 AM
#5
Re: Declarations and Procedures in Class Modules vs. Dependencies
 Originally Posted by Eduardo-
Sharing code here is usually not just "I'll post what I have, like it is", but it requires some work to make something shareable.
I'd like to second that sentiment. When posting a code snippet, I often find myself doing some copy-pasting so that it's a "complete" snippet. And, for my two-cents, that's as it should be.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Apr 5th, 2024, 01:45 PM
#6
Lively Member
Re: Declarations and Procedures in Class Modules vs. Dependencies
I agree
The problem with achieving totally independent classes, at the cost of having copies of code fragments in more than one module, is that all code can generally be improved, whether in execution speed, reading clarity, number of lines, etc.
In addition, it is also possible that we realize the possibility or need to add new functionalities.
So, if we want to modify one of these fragments, after doing so, we should be careful to search for and modify all the remaining ones, unless we don't mind having different versions of code, for the same problem resolution.
In my humble opinion and as far as I am concerned, since my memory is a disaster, I prefer to have a single code, and also a well-documented one, because it makes me feel more secure.
When sharing, to try to help someone, I will take the trouble to put together a module for this purpose.
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
|