What do you do when it seems unavoidable to have a single function perform multiple tasks?
Since I began learning, I've heard time and again that a function should do one thing and one thing only. It should have a name like
do_foo() and it should do foo and nothing more.
But it seems like I frequently run into issues where it just seems unavoidable to make the function
do_foo_and_do_bar(). For instance, I'm programming for the gmail API and I need to get unread emails and mark them as read. Based on the above, the 'right' way to do this is to make
mark_unread_as_read(). But that would be pretty inefficient, since you're finding each unread email twice, when you could just find it and mark it as read in one go.
Is it better to accept that inefficiency or to just call the function
get_unread_and_mark_read() and move on with my life?
Submitted July 12, 2017 at 12:14AM by Endome
via reddit http://ift.tt/2t2ULXT