I've been developing with Python for so long that thinking in a pythonic way is very natural. For example, in developing pysmug I make extensive use of kwargs to keep the API simple but still capture the required, sometimes extensive, list of arguments for a method call.

For example, in Python, an albums_create method call might look like this:

>>> m.albums_create(title="This is the title", categoryId=22, public=False, description="My test album")

I think this reads quite well and is, I'd argue, the most pythonic way to model the API. So what's the erlangish way?

I'm currently supporting this API for erlsmug:

albums_create(Title) ->;
  erlsmug_server:albums_create([{"Title", Title}]).
1> erlsmug:albums_create("This is the title").

I'm thinking of changing the albums_create function signature to take the list of tuples or a dictionary straight-away because I want to be able to create the album in one shot with any arbitrary set of parameters. Creating a method signature for each combination is obviously dumb — I miss keyword args.

It also seems from some perusing of source code there is a preference for a list of tuples over a dictionary. The dict API allows the easy transformation from list to dict and back so perhaps this is pretty normal for some language-specific reasons? Of course, duplicate keys are allowable in the list approach while not in the dictionary approach.

Categories: development 
Tags: erlang  python 
comments powered by Disqus