sideshowcoder / canned

Server to respond with fake API responses, by using a directory of files for finding out what to say!
213 stars 46 forks source link

Introduce Promises to make reading code easier #24

Closed mulderp closed 10 years ago

mulderp commented 10 years ago

Hi,

not sure if this is a topic you are interested in, but I tried to cleanup the callbacks a bit by introducing Promises and the Bluebird library ( https://github.com/petkaantonov/bluebird ).

Feel free to give critical feedback or close if it is not relevant right now. I was wondering that it might help to track problems with finding the right files easier.

Thanks for your interest!

sideshowcoder commented 10 years ago

Thanks a lot for your work, I appreciate any input and I hope I can give you some valuable feedback here.

Personally I'm not convinced about Promises in this case, I feed like having to know how they work makes it not really easier to debug in this case, I think the way to make promises readable is to extract the steps the data has to flow through in different functions, otherwise they only introduce a .then and a .catch. But I'm gladly to be proven wrong so what makes you feel like this is an improvement to reasoning about the code? Also is there maybe a way to make it more readable via extracting functions instead?

Thanks so much for your time!

mulderp commented 10 years ago

Thanks for the feedback! I follow up in some days, but for sure this PR is very experimental, so no problem if it's closed. Background is that to me, Promises improve reasoning about exception in the code flow. I thought it might help, with the problems I had earlier about not finding files, or having files with wrong syntax. But indeed, this is not yet visible from this spike so far. Ok, have a nice evening, update later.

sideshowcoder commented 10 years ago

I like the idea but like you said it's not visible in the spike, so I'm gonna tag this as future ideas.

mulderp commented 10 years ago

I am closing this one for now, since I currently I won't have much time to look into this further. But possibly, when someone tackles https://github.com/sideshowcoder/canned/issues/23 or https://github.com/sideshowcoder/canned/issues/22 catching exceptions with a Promise setup might get interesting again.