Say I have a function that performs one calculation, but for different 
argument types. For instance, I have a satellite orbit propagator that 
returns the satellite state at some time, given the initial state and the 
desired time. I would like to specify the desired time either as an elapsed 
number of seconds OR, say, a DateTime object. The calculation itself is 
largely the same, and requires elapsed seconds. What is the best way to 
write this?

I suppose my options are:

   1. Multiple dispatch - two methods, with essentially duplicate code 
   (seems undesirable to me).
   2. Multiple dispatch - two methods, but the method that takes DateTime 
   as input simply converts to seconds and then calls the other method. Is 
   there a performance hit for this?
   3. One method, where the type of the desired time is checked and 
   converted up front if necessary.
   4. Other (?)

I've read through the documentation and searched this list, but I am still 
confused. Any direction is appreciated.

Chris

Reply via email to