hupili / snsapi

Cross platform middleware for Social Networking Services: Twitter, Facebook, SinaWeibo, Renren, RSS, Email, Sqlite, ... (more coming)
http://snsapi.ie.cuhk.edu.hk
159 stars 53 forks source link

Vertical Interface Style Unify #93

Open hupili opened 10 years ago

hupili commented 10 years ago

There are several vertical interfaces:

Facts about vertical interfaces:

Style 1:

xx_request(path, method, params={...})

Style2:

xx_request(path, method, param1=?, param2=?)

Problem of style2: (when the param of the API is not a valid Python identifier)

$cat t.py 
def f(**kwargs):
    print kwargs

f(a=1, b=3)
f(a=1, **{'a.b': 3})
$python t.py 
{'a': 1, 'b': 3}
{'a': 1, 'a.b': 3}

Although the vertical interfaces are mainly there to support horizontal interfaces (the major use case), some users want to use vertical interfaces directly to extend the function. We can not unify the data structures but we can make the invocation style coherent.

Call for discussion. pros/ cons with cases.

hupili commented 10 years ago

More problem of Style2: inconvenient for logging and error handling.

params = {...}
response = self.xx_request(method, params)
log(params, response)
error_handle(params, response)

Enclosing parameters in a definite argument is a better style for the vertical interfaces.