BYVoid / continuation

JavaScript asynchronous Continuation-Passing Style transformation (deprecated).
Other
390 stars 42 forks source link

continuous return value instead of continuous passsing style? #19

Closed eurekaa closed 10 years ago

eurekaa commented 10 years ago

Hi, great job there, is it possible to implement a trasformation which makes it possible to pass return values on the left side of the expression? example:

    var value = async_call(arg1, arg2, obtain);

Do you think it's hard to implement? Any suggestion about that? Thank you very much!

BYVoid commented 10 years ago

Hi,

Thank you for contributing continuation.js. The style you have given in the example is another style, which is used by streamline.js or wind.js. It is definitely possible to implement, but I personally do not prefer it, because it is hard to support multiple return values. It is a convention that the first parameter of the callback function is the error object, therefore I implemented both cont and obtain. If the callback function has more than 2 parameters, for example:

var request = require('request');
request('http://www.google.com', function (err, response, body) {

})

How do you handle the return values using a function return value? You can wrap them into an array, but it will make your code even uglier.

eurekaa commented 10 years ago

Yes, i perfectly understand your point of view. But programmers are addicted to left assignment passing style and there are few cases in which a function need to return multiple values. The error and a single value are sufficient in my opinion, you can also return a object with multiple keys and that is solved.

I really love your work, i was searching for a compiler which was usable both on client and server side and yours is the only one i found really good (i loved the sintax of streamline but it doesn't work well on the browser side).

The only thing is that it is really difficult to me to read right assignment style (also my ide marks passed values as errors and, you know, it is quite ugly to see a code with lots of non-errors, etc..).

I was very interested in your project so i forked it to https://github.com/eurekaa/continuum.js and did some changes (add async stuff, new compilers (less, jade, ..) and start to try to change left into right assignment style but i don't know so much about transformation so i'd like to ask you if you'd like to help me (in need some suggestions to start).

Maybe it would be nice to add left assignment style to continuous in order to have both. What do you think about?

BYVoid commented 10 years ago

Yes you can do that. Please tell me if you have any problem.