Redundant code


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Redundant code

  1. #1
    Doug Crowley Guest

    Redundant code

    I often have different classes in a project whose methods rely on standard
    routines. For example, I'm working on a project now that has two classes which
    uses bitwise operations that are contained in a module called modBitWise.bas.

    One of these classes is project specific while the other could be used in future
    projects. Do you consider it prudent to duplicate this code in the reusable
    class so that it can be standalone? Otherwise I'll have to make sure that I
    include modBitWise.bas in any project that reuses this class.

    Share on Google+

  2. #2
    Tim Patrick Guest

    Re: Redundant code


    One of the main purposes of a class is to hide the details of functionality
    behind a set of defined interfaces (much like an ActiveX object's purpose).
    The class is like a black box; the consumer of a class shouldn't be bothered
    by the insides of the box, including any dependencies required by the box.

    While this is a great goal, it can lead to some inefficiency, such as the
    duplicate code issue you mention here. You can call global functions from
    inside a class. In fact, the presence of the Friend keyword almost begs
    the programmer to have classes interact with each other.

    You could place the bitwise functions in a DLL of their own, and make that
    DLL a dependency of each of the two classes. In that way, it could continue
    to be a dependency for the class that will go on to future projects. Still,
    that seems like overkill for the type of work you are describing.

    If I was in your place, I would probably duplicate the code in the module
    that you plan to use in other projects. It would be hard, and my hands would
    shake with each copy and paste of the code. But this would have the benefit
    of giving the class that true black-box feeling. And, isn't that was every
    class really desires, deep down in its heart? :-)

    -----
    Tim Patrick
    tim@vbstyleguide.com


    Share on Google+

Similar Threads

  1. Microsoft's C++ bigotry
    By Phil Weber in forum .NET
    Replies: 632
    Last Post: 10-01-2003, 12:00 AM
  2. .NET equals Efficiency
    By Kevin in forum .NET
    Replies: 150
    Last Post: 03-04-2002, 05:40 PM
  3. Replies: 3
    Last Post: 07-09-2001, 03:25 PM
  4. Another Language
    By Steven Bell in forum .NET
    Replies: 260
    Last Post: 06-01-2001, 04:32 PM
  5. Replies: 90
    Last Post: 04-17-2001, 12:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center