Results 1 to 6 of 6

Thread: Declarations and Procedures in Class Modules vs. Dependencies

  1. #1

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819

    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.

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,915

    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.

  3. #3
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,700

    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.

  4. #4
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,700

    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.

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,915

    Re: Declarations and Procedures in Class Modules vs. Dependencies

    Quote Originally Posted by Eduardo- View Post
    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.

  6. #6
    Lively Member Tabi's Avatar
    Join Date
    Jan 2024
    Location
    Argentina, Santa Fe
    Posts
    67

    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
  •  



Click Here to Expand Forum to Full Width