Postel's law:
Be conservative in what you do, be liberal in what you accept from others.
"Lazy" code (per The Pragmatic Programmer):
Be strict in what you will accept before you begin, and promise as little as possible in return.
I'm developing a finance (asset pricing, etc.) framework for Python. Question: when designing the API for the framework, what factors should I consider when I assess the tradeoff between being strict and being liberal re: inputs?
Example:
I have the following method that downloads stock prices from Yahoo.
def historical_prices(ticker, start=None, end=None, data='d', convert=True):
# Do stuff
For the date arguments (start & end), I could:
- Be strict, and only allow a string of ISO format YYYY-mm-dd, or
- Be liberal and accept datetime objects, strings (of specified formats), etc.
datetime.dateobjects instead? – Martijn Pieters Jul 30 '12 at 14:12datetime.date, then call the function. Question still stands even if I switched todatetime.date: do I just allowdatetime.dateor also allow strings? – MikeRand Jul 30 '12 at 18:17