2 is the way to go – it's very likely that there is zero overhead due to inlining.
On Sat, Aug 9, 2014 at 6:36 PM, Kevin Squire <[email protected]> wrote: > Hi Chris, > > On Sat, Aug 9, 2014 at 3:30 PM, Chris Binz <[email protected]> > wrote: > >> 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 (?) >> >> Your number 2 type is probably the best solution. How much of a > performance hit depends entirely on how long the different parts of the > calculation take, so you'll have to test that and tell us. :-) > > Cheers, > Kevin >
