JS without callbacks... so JS without the best part of JS?
Kal – a clean JavaScript alternative without callbacks
51–60 of 130 posts
Re: Kal – a clean JavaScript alternative without callbacks
#52For 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/
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);
});
}Re: Kal – a clean JavaScript alternative without callbacks
#53I'm puzzled by the bootstrapping process. It's written in Kal itself, and you distributed compiled code as JS. Do you have a way of re-boostrapping from only the source in github?
It's not turtles all the way down, though. If you look way back, the 0.1ish releases of the compiler were written in CoffeeScript. I ported the compiler source over from CoffeeScript file by file as it matured and eventually got rid of the dependency entirely. Technically, you could start with the last release that was written in CoffeeScript and compile up to the current release.
Re: Kal – a clean JavaScript alternative without callbacks
#54Excellent work. Especially useful since it appears to throw exceptions. That means it's a step up from Iced Coffeescript. The syntax is a little verbose and might be shortened to something like C#: `user = await db.users.findOne {name:userName}`. Would be a lot more clear to me.
Because, of course, there's no way to technically do that in anything that is JavaScript at its core -- at least as far as I'm aware of. Correct me if I'm wrong?
It says "This includes error handling via callbacks." -- not error handling via exceptions. Elsewhere it says "Any errors reported by fs.readFile (returned via callback) will be thrown automatically.", so maybe it converts certain callback error functions to exceptions? But in any case, that's not the same as throwing an exception inside of a callback, and having it "bubble up". Unless I'm misunderstanding (which would be great!).
Re: Kal – a clean JavaScript alternative without callbacks
#55Does anyone know if there is a JS dialect out there that adds support for callback-less async code without also adding a bunch of other coffeescripty syntax changes at the same time?
http://blog.alexmaccaw.com/how-yield-will-transform-node
Definitely not as clean as a whole new language, but you can program like this today, at least in bleeding edge node and some recent browsers.
Re: Kal – a clean JavaScript alternative without callbacks
#56For 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/
I think a useful case would be the trickier stuff where Kal really shines. For example, doing async stuff inside of loops, conditional calls (where some paths need async waits and others don't) and error handling. I also think the Kal syntax might appeal to people who are less experienced with JavaScript and it's more eclectic features.
Re: Kal – a clean JavaScript alternative without callbacks
#57It's remarkable how similar this code looks to the monadic way of doing it. 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} if user.type is 'power user' for parallel friend in friends wait for friendsOfFriend from db.friends.find friend for newFriend in friendsOfFriend friends.push newFriend unless newFriend…
A lot of people prefer symbols over keywords, and I think that's mainly a readability issue. I personally prefer more keywords with good syntax highlighting, so that's what I went with (and why I almost immediately made a .tmbundle).
Re: Kal – a clean JavaScript alternative without callbacks
#58It's remarkable how similar this code looks to the monadic way of doing it. 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} if user.type is 'power user' for parallel friend in friends wait for friendsOfFriend from db.friends.find friend for newFriend in friendsOfFriend friends.push newFriend unless newFriend…
[1] - http://msdn.microsoft.com/en-us/library/vstudio/system.threa...
[2] - http://msdn.microsoft.com/en-us/library/vstudio/hh191443.asp... and http://msdn.microsoft.com/en-us/library/vstudio/hh156528.asp...
Re: Kal – a clean JavaScript alternative without callbacks
#59Earlier quoted context omitted.
Definitely play with the exception handling. Latent bugs aside, asynchronous statements (wait fors) work in any crazy horrible nested combination of ifs, fors (parallel or series), and trys that you can think of. Take a look at the JS output with: kal -o output.js -f beautify input.kal to see the sausages being made. The http server demo is a good example ( https://github.com/rzimmerman/kal/blob/master/examples/async…
A side-by-side line-by-line interactive display would be wonderful in writing Kal. Reading the JS explains what it's doing quite well, except that the Kal compiler uses way too many compound comma-separated statements instead of semicolons.
Re: Kal – a clean JavaScript alternative without callbacks
#60The title is kinda funny to the russian ear because kal means feces in Russian :)
That is really unfortunate... I chose it because it in Hebrew it roughly means something like easy/simple/BASIC. edit: More importantly, does that make you more or less likely to use it?