Hacker News new | past | comments | ask | show | jobs | submit | tr4nslator's comments login

Actually, a bunch of us are working on taking the pain out of async programming. Here's my approach, using (fab)'s chained continuations:

http://www.flickr.com/photos/tr4nslator/4532445014/in/set-72...


While this is cool, when you get to this point with JavaScript syntax why not just write your program in a Lisp like Clojure? People keep saying that JavaScript is good for asynchronous code, but that might not true at all. It's just that we JS hackers become very accustomed to a style of code that works great for simple user-driven events. In my experience this does not scale for much else.

Maybe we can make it work, but I don't like what I've seen thus far. I want people to adopt a syntax that doesn't affect standard JS style: http://mootools.net/shell/q9ASd/28/


Because I'd rather write my programs in a Lisp like Javascript?


"Traditional Chinese characters are widely used, and are the de facto writing standard in Hong Kong."

from http://en.wikipedia.org/wiki/Languages_of_Hong_Kong#Written_...


You can even do that in half the bytes by making use of all unary operators together:

  -~+[]
-~ is a good proxy for ++ when incrementing unassigned variables.


I think this should probably point here:

http://jashkenas.github.com/coffee-script/#scripts

The salient point is that CoffeeScript now automatically compiles any code in a script tag with type text/coffeescript. Pretty cool.


The Japanese government is not unique here. Earmarks and pork are just as big a problem in the United States.


Do you anticipate that the use of WebSockets will improve performance? If so, can you estimate to what degree?


Not to pedal my own wares, but... ;)

http://axod.blogspot.com/2009/12/websocket-some-numbers.html

Also a caveat followup - websocket don't play nice with some proxies/nat/firewall setups. Either need https, or fallback on comet.


I don't want to pry, but I'm really curious - do you work full-time on Mibbit, or is it a side project for you?


Reasonably full-time now, my brother is pretty much full-time on it now also (Not abstractbill, our older bro). Things are going well :)

I think it's always good to have a few things on the go though, so I doubt I'd ever be 'full-time' on any one thing ;)


It will since you don't need to open and close connections all the time. I can't estimate at what degree, but I think the communication will be much faster since currently some time is used to re-create connections.


Also, once the handshake is done, no back-and-forth of TCP/IP headers (which generate a lot of needless bandwidth).


Indeed, CoffeeScript was built on Ruby, and its REPL on Narwhal.


Hey all,

I just launched a dead-simple web framework on top of node.js. It uses (abuses?) a lot of the dynamic nature of javascript to create a jQuery-inspired DSL that's pure javascript, allowing you to create really concise web apps like this:

  ( fab )
    ( "/time", function(){ return "the time is " + (new Date).toTimeString() } )
    ( "/date", function(){ return "the date is " + (new Date).toDateString() } )
  ( fab )
I'd love to hear any feedback from the folks here, so check it out and let me know what you think.


I did a double-take looking at that syntax. I assume that fab (and all of the other bracketed expressions) return functions that chain together? Pretty ingenious. Plus you can detect the end of the chain when one of the methods is passed in "fab" again.

I think I can say that this is the best (ab)use of the syntax I've ever seen, well done. :)


Yeah, a (fab) function just returns itself. It's like jQuery's chaining, but using argument signatures instead of object methods to delegate work. The last (fab) is just a way to indicate the chain is over so that a listener can be returned, and has the additional benefit of making it look declarative.


Thanks for pointing that out, I've been sitting looking at how that could possibly work for a while.


The problem I've had with writing stuff like this is that if you go too far out of your way to hide the fact that this is still just Javascript, you get a lot of people who don't realize that it is just Javascript and you can do what you want.

What if you want to dynamically create stuff? You can take the value of fab, use standard for loops and if statements and whatnot to apply things to it, then call fab again at the end and it'll all work fine. By hiding in a DSL here, you encourage people to not realize that, and take away the ability for these people to use the Javascript they already know to build the system. Another manifestation of this general principle is that you may get people who don't realize that they can define a function elsewhere then include it as an argument.

Please don't laugh or tell me this is impossible. I used to think that too. Experience has bludgeoned me over the head on this, rather against my will.

Magic really ought to be reserved for things that can't be done without magic. Method chaining is becoming a standard JS technique (even though I don't like it, for pretty much this same reason albeit more weakly as it is less of a departure) and I don't see a reason not to just use method chaining here.

If I don't miss my guess, as you develop this you're going to miss having it anyhow and have to switch to it anyhow. You're almost certain to end up having more than one type of thing go in those arguments, and the alternative will be either returning to method chaining, or using the first argument to do nothing other than switch on which method you actually call. (And that is honestly just silly because the language already has perfectly cromulent facilities for doing that.)


I actually think this is less magical than most approaches, since there's no pre-compilation or "with" scoping magic. Sinatra's hello world is awesome, until you realize that a lot of the cool stuff is scoping magic that you have to throw out when your app has to play nicely with others.

My original approach for (fab) was like jQuery:

  fab()
    .find( path )
      .bind( method, handler )
      .find( subpath )
        .bind( method, handler )
      .end()
    .end()
  .end()
but I realized that I could simplify things by getting rid of methods entirely, and reserving methods for HTTP methods and status codes.

As for people not realizing they can define functions outside of the DSL, I'm hoping that the extensibility of middleware will mitigate that, just as the ecosystem of plugins did for jQuery.


The syntax looks cute for one-lined request handler functions. I wonder how it stacks up for larger, multi-line functions. Heck, you're pretty close to sexps (I kid!).


It's vaguely lispy, but without all that nesting.

Multi-line functions work okay, but it's definitely cleaner to name them and put them somewhere else so that your code ends up looking like a site map:

http://gist.github.com/287475#file_hello_middleware.js


I had taken a look at it before, and was wondering: Is there a way we can do long-polling stuff with fab?

(by "long-polling stuff" I mean deferring response.finish())


Indeed you can. (fab) is 100% async:

http://gist.github.com/287475#file_hello_async.js


Ooh, that's pretty cool. I like the way you receive a "respond" function and call it when you're done. Nice work!


Excellent work.


.live() : DOM event handling :: CSS : DOM styling


Server-side Javascript frameworks seem to be in the midst of a Cambrian explosion right now.

I just pushed my own today:

http://github.com/jed/fab/


There is an explosion indeed, with two main directions IMHO: - frameworks like yours on top of Node - frameworks like helma-ng and nitro on top of Google App Engine (via Rhino)

These offer the best scalability guarantees and I'm still torn on what is the best approach for my personal projects.


node.js supports an event driven programming paradigm by default, so in that regard it is a bit different than some of the other server side JS frameworks.


Just checked it out. The ability to chain calls is pretty awesome. I also liked how the route callbacks are called on env, so you can say this.env_var to get at your params and such. Very cool.


The latter was just from my framework of choice until now, Tornado.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: