erlang - Passing arguments to a function: a two element tuple v. two separate arguments? -


in situations, find clearer if pass 2 arguments function, e.g. 2 lists, rather passing tuple containing 2 lists. considered better style? differences in efficiency?

thanks.

it matter of taste , designed api. if follow "don't make me think" philosophy, might end using both ways.

using tuple in argument can confusing, because non-trivial , has documented. example, lists:zip({list1, list2}) confusing because sending in lists separately more intuitive.

if 2 lists belong , passed through several functions before being used, can handy group them 1 tuple functions on way don't have pass them separately. makes tuple lightweight "object" can pass around. functions understand "object" can either it, or split , call deeper functions operate on elements separately.

sometimes 2 lists related each other makes more sense keep them in tuple:

aquire(caller, {[item|free], busy}) -> {free, [{caller, item}|busy]}; aquire(_caller, {[], _busy})        -> {error, no_free_items}. 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -