[Tutor] How (not!) lengthy should functions be?

Mark Lawrence breamoreboy at yahoo.co.uk
Fri Apr 17 01:04:45 CEST 2015


On 16/04/2015 23:40, Alan Gauld wrote:
> On 16/04/15 22:03, Alan Gauld wrote:
>
>>> def percent2Gy(dose_percent, target_dose_cGy):
>>>     """
>>>     Convert a dose given as a percent of target dose into Gy (Gray).
>>>     """
>>>     dose_Gy = cGy2Gy((dose_percent / 100.0) * target_dose_cGy)
>>>     return dose_Gy
>>
>
>> Note in this case you could just create an alias
>>
>> percent2GY = cGy2Gy
>
> Except that the name would then be misleading - my bad!
> The value that your function adds is the percentage calculation.
>
> But if it is a straight renaming exercise then an alias would
> be more appropriate than defining a new wrapper function.
>
> Sorry, for the bad example.
>

Bah, that'll teach me to read more closely in the future :(

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Tutor mailing list