coding style - Best way to write a conversion function -


let's i'm writing function convert between temperature scales. want support @ least celsius, fahrenheit, , kelvin. better pass source scale , target scale separate parameters of function, or sort of combined parameter?

example 1 - separate parameters: function converttemperature("celsius", "fahrenheit", 22)

example 2 - combined parameter: function converttemperature("c-f", 22)

the code inside function counts. 2 parameters, logic determine formula we're going use more complicated, single parameter doesn't feel right somehow.

thoughts?

go first option, rather allow literal strings (which error prone), take constant values or enumeration if language supports it, this:

converttemperature (tempscale.celsius, tempscale.fahrenheit, 22) 

Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -