Live data from Hacker News

Kal – a clean JavaScript alternative without callbacks

rzimmerman.github.io

71–80 of 130 posts

Re: Kal – a clean JavaScript alternative without callbacks

#72

This is a project I've been working on in my spare time for a while now and I've finally decided to throw it out there and get some feedback. Do you think the 'wait for' callback syntax is useful? What big features do you think are missing?

I'd be more interested in performance than features. If you use tasks when they're not needed, how much more JavaScript code does it take and how fast does it run? Also, what do stack traces look like?

Re: Kal – a clean JavaScript alternative without callbacks

#74

Earlier quoted context omitted.

There is no need for hacks, just run node with the `--harmony` flag to get yield support today. Q is a huge, monster library. It's 2x the size of caolan/async, which is already bloated. I personally think it's better to use https://github.com/mbostock/queue or another small, understandable library.

If you're taking about node, what difference does it make how large the library is?

These libraries work in the browser. It's not just size: debugging, understanding code, and performance matter too.

Re: Kal – a clean JavaScript alternative without callbacks

#75
post #3

This is a project I've been working on in my spare time for a while now and I've finally decided to throw it out there and get some feedback. Do you think the 'wait for' callback syntax is useful? What big features do you think are missing?

Looks pretty good! I like it. To be honest I will not use it in my projects. I prefer using ES6 syntax for this problem when it's available.

what's the (equivalent?) ES6 syntax? I'm genuinely curious.

Re: Kal – a clean JavaScript alternative without callbacks

#76
post #22

Earlier quoted context omitted.

I also vote for 'await' here. The 'wait for friends from' construct looks too much like BASIC for my liking. It's not clear which terms are built into the language ('wait', 'for', 'from') and which are not ('friends'). Also, since the eventual result of that line is an assignment to 'friends', using the existing = operator makes the language more consistent.

Thanks for the feedback. It seems like a lot of people would prefer a more normal looking assignment. If you get a chance (and use TextMate or Sublime Text), please give syntax highlighting a try ( https://github.com/rzimmerman/kal.tmbundle )!

I'll stick up for the "wait for" syntax here. It seems a lot cleaner to me than trying to shoehorn asynchronous handling into assignment, with all the edge cases that entails.

Re: Kal – a clean JavaScript alternative without callbacks

#77
I suggest to use ..= (or ...=) in place of the keywords 'wait for', and 'from'. Less words, and '...' traditionally means 'to be continued', or 'wait for a while'.

For this Kal code:

  task getUserFriends (userName)
    wait for user from db.users.findOne {name:userName}
    wait for friends from db.friends.find {userId:user.id}
    return friends
would become:

  task getUserFriends (userName)
    user ..= db.users.findOne {name:userName}
    friends ..= db.friends.find {userId:user.id}
    return friends

Re: Kal – a clean JavaScript alternative without callbacks

#79

For the curious, the equivalent example from the OP using promises[1]: function getUserFriends(userName) { return db.users.findOne({ name: userName }).then(function (user) { return db.friends.find({ userId: user.id }); }); } [1]: http://promises-aplus.github.io/promises-spec/

It's more obvious if you have multiple levels. function getUserFriends(userName) { return db.users.findOne({ name: userName }) .then(function (user) { return db.friends.find({ userId: user.id }); }) .then(function (friends) { return somethingAsync(friends); }); }

I don't ever write code like this personally. The multiple levels make it more difficult to reason about, IMO.
Post reply on HN