Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Redundant function?

Redundant function?

Scheduled Pinned Locked Moved C#
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Spoon Of Doom
    wrote on last edited by
    #1

    I wanted to look up how the function TimeDiff is implemented exactly (a function to calculate how many hours there are between a start time and an end time) and found this. I'm not that experienced yet, so tell me... is there a way in which this might make sense or is this simply redundant and... well, stupid?

    public static XDateTime TimeDiff(XDateTime d1, XDateTime d2)
    {
    #region Local Variables
    #endregion

      #region Actions
      return APTimeDiff(d1, d2);
      #endregion
    }
    

    APTimeDiff returns the same type and does the actual calculation (and formatting). Why put it into another function?

    D J S 3 Replies Last reply
    0
    • S Spoon Of Doom

      I wanted to look up how the function TimeDiff is implemented exactly (a function to calculate how many hours there are between a start time and an end time) and found this. I'm not that experienced yet, so tell me... is there a way in which this might make sense or is this simply redundant and... well, stupid?

      public static XDateTime TimeDiff(XDateTime d1, XDateTime d2)
      {
      #region Local Variables
      #endregion

        #region Actions
        return APTimeDiff(d1, d2);
        #endregion
      }
      

      APTimeDiff returns the same type and does the actual calculation (and formatting). Why put it into another function?

      D Offline
      D Offline
      David Skelly
      wrote on last edited by
      #2

      Well, its just a guess but one reason for doing this might be to avoid changing the public API of the class. So, once upon a time method TimeDiff did something different. Then it was decided to use APTimeDiff instead (maybe it's more efficient, maybe it handles some corner condition more effectively). But it might be that this is a library class which is used in a number of places, and for whatever reason we can't go through and change all the calls to TimeDiff to call APTimeDiff instead. So, just leave the old method in place but change the internal implementation. Any new code should now be using APTimeDiff, but old code that uses TimeDiff will continue to function as is and does not need changed. It's a fairly common thing to do as part of a Refactoring process. Eventually, the aim would be to work through and replace all calls to TimeDiff with APTimeDiff.

      1 Reply Last reply
      0
      • S Spoon Of Doom

        I wanted to look up how the function TimeDiff is implemented exactly (a function to calculate how many hours there are between a start time and an end time) and found this. I'm not that experienced yet, so tell me... is there a way in which this might make sense or is this simply redundant and... well, stupid?

        public static XDateTime TimeDiff(XDateTime d1, XDateTime d2)
        {
        #region Local Variables
        #endregion

          #region Actions
          return APTimeDiff(d1, d2);
          #endregion
        }
        

        APTimeDiff returns the same type and does the actual calculation (and formatting). Why put it into another function?

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        It looks like half completed code, or post-refactored code which has not been cleaned up. In the former case, the completion of that method would perhaps put some validation in to check the inputs. In the latter case, the method may have been left as there are many places around the application calling TimeDiff and changing them all to APTimeDiff may be too time consuming at the current time.

        1 Reply Last reply
        0
        • S Spoon Of Doom

          I wanted to look up how the function TimeDiff is implemented exactly (a function to calculate how many hours there are between a start time and an end time) and found this. I'm not that experienced yet, so tell me... is there a way in which this might make sense or is this simply redundant and... well, stupid?

          public static XDateTime TimeDiff(XDateTime d1, XDateTime d2)
          {
          #region Local Variables
          #endregion

            #region Actions
            return APTimeDiff(d1, d2);
            #endregion
          }
          

          APTimeDiff returns the same type and does the actual calculation (and formatting). Why put it into another function?

          S Offline
          S Offline
          Spoon Of Doom
          wrote on last edited by
          #4

          Thanks guys, that makes sense. It is source code that has been passed on for many versions and many years, so it may very well be a change that has been made without cleaning the older parts up properly.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups