Talks
Easy Node.js Apps With Lisp
Summarized using AI

Easy Node.js Apps With Lisp

by Giles Bowkett

The video titled "Easy Node.js Apps With Lisp" features Giles Bowkett speaking at the LA RubyConf 2011. The focus of the presentation is on using Node.js along with Sibilant, a Lisp implementation built on top of Node.js, to create web applications and command-line utilities.

Key points discussed include:

  • Introduction to Node.js: Bowkett describes Node.js as a powerful server-side JavaScript library that utilizes an evented I/O model for building servers. He illustrates a simple web server example built with Node.js, emphasizing its asynchronous nature.
  • Evented I/O Model: The speaker uses a coffee shop analogy to explain the asynchronous event-driven programming model of Node.js. He contrasts it with a synchronous model to clarify how Node.js handles multiple requests simultaneously, leading to faster server responses.
  • V8 JavaScript Interpreter: Node.js runs on Google’s V8 engine, which provides exceptional speed and performance, making Node.js popular among developers.
  • Convenience and Community: The presentation highlights Node.js's rapid installation process and its active open-source community, indicating a wealth of resources and libraries available to developers. Bowkett mentions Jasmine Node as an example of a popular library that enhances development.
  • Drawbacks of Node.js: Bowkett touches on some minor criticisms of Node.js, such as its fast-evolving nature leading to frequent API changes and the challenges around error handling in asynchronous callbacks.
  • Practical Applications: He shares examples of applications he developed using Node.js, including a tweet similarity detector for filtering spam and a minimal GitHub dashboard, demonstrating how easy it is to create functional applications. Bowkett also references a project focused on filtering Ruby community tweets, showcasing Node.js’s flexibility in handling real-time data.
  • Conclusion: Ultimately, Bowkett encourages the audience to embrace Node.js and Lisp for programming, discussing how these tools can lead to innovative solutions for modern challenges in software development. He emphasizes the importance of simplicity and creativity in programming and invites further exploration of these technologies.

In summary, the talk seeks to inspire developers to harness the power of Node.js and Lisp in crafting efficient, user-friendly applications while fostering community engagement and creativity in programming.

00:00:29.760 So just before this thing began, they came up and said, 'Hey, you've got 45 minutes.' I was surprised because earlier I didn't realize that my presentation was supposed to be 30 minutes, so I had made a long presentation and then cut it down to size. Since they told me I could do the whole thing, it looks like I'm going to have to go fast.
00:00:35.460 The presentation begins with Node.js; this is part one. So, what is Node.js? Node.js is a server-side JavaScript library for building servers using an evented I/O model, which I'll explain in just a moment. Here’s an example of a web server written in Node. I'm not sure if you can read it, especially from the back, but basically you require the HTTP module. You call createServer on that, give it an anonymous function in JavaScript which takes a request and a response as arguments. Then you say 'response.writeHead(200, { contentType: 'text/plain' })', which is the absolute bare minimum for an OK response with some content coming back from a web server. After that, you do 'response.end(
00:01:05.338 Hello, world!'. Then all you do is tell this server to listen on port 8124, along with the IP address. Okay, so that’s the basics. Is it already time? No? No, I'm good. Okay, so this is a picture of a bad day of employment at a coffee shop. You might wonder why I'm showing you this graphic. This is to explain the evented I/O model I mentioned earlier. There is this asynchronous evented structure in Node.js that is quite bizarre when you first encounter it. The coffee shop is actually the best metaphor I've heard for explaining it. Typically, when you're programming, you might think about how it would go in a coffee shop: you go in, order a drink, let's say a latte. They say, 'Okay, we're going to make your latte,' and then you wait a bit. 'Latte!' And you respond, 'That's me!'
00:02:08.659 That’s asynchronous organization right? Instead, if they were using a threaded model in coffee shops, it would go like this: you go up there and say you want a latte, they take your money, make the latte first, and then only ask what the next person in line wants. That would be really annoying and would cost them a lot of customers because everyone would go to places that use an evented asynchronous organization. So if you talk to people about Node.js, they'll say, 'My God, the asynchronous model is so strange,' and you can respond, 'No, it's easy. It's like a coffee shop.'
00:02:33.480 Node runs on the V8 interpreter from Google, and it is blazingly fast. If I understand the lineage correctly, the strong top guys whose son was hired to make the Java VMS got hired away by Google to create V8. Long story short, it’s fast and comes from Google. This is a little bit of self-promotion, I have been known to indulge in self-promotion from time to time. Imagine how cool it would be if Google was useful for JavaScript documentation; this website is like a Google that is useful for JavaScript documentation. Now, to install it, this installation is really straightforward. You just go here: 'make install.'
00:04:06.039 A lot of things on Linux or OS X are similar. The big thing that is making it popular is that it is ridiculously fast. Here they have some benchmarks for it serving 10,000 requests per second. Here’s a blog post by a guy who had Python going faster until he started optimizing and got it pretty fast. Another thing that I think is actually even bigger is that it is mega convenient. One of the reasons it’s convenient is this: Jasmine Node, I'm not sure where Evan is, but Jasmine is a library for JavaScript DDD or specs from Pivotal Labs. This is a fork that’s altered slightly to run with Node.
00:05:10.380 What makes it so convenient is that it has a high number of followers and a high number of forks. You’d see that one out of every three people who follow this project has forked it. This is indicator that in an open-source project is doing well when you have high ratios like that. Now, minuses of Node? I haven’t actually had any real issues community-wise, but I've heard gripes that their social skills are, you know, let's say not the best. The guy on the screen with a machine gun is there to represent a less friendly attitude in the world. You might not want to file support tickets with him. However, if you look very closely, he has a guitar, maybe he does have a sweet side.
00:05:47.399 Another downside of Node is that it is fast-changing. If you write something in Node, three weeks later you might have to change some API, like util becoming utilities—little things like that. There’s a picture of a guy saying, 'I'm on the Node.js list and I love this asynchronous model, but I just can't code like this.' He mentions that he understands the execution model and doesn't want to change it but feels that JavaScript is missing macros. He is looking for someone to talk him down, concluding that certain sorts of programs are unwritable without language extensions. I initially thought this was a serious concern when I found it, but it’s really more of a drama queen moment.
00:07:05.400 What he does raise, which is interesting, is that in a typical synchronous JavaScript pattern, you would have chaining that looks quite straightforward. In Node, due to its asynchronous nature, you have to throw in error checks with every callback, which he finds frustrating. There is, however, a solution to this issue. With such an error handling model, some people say the creators of Node.js must have been coding drunk. This has been a controversial point for some, but I really like being able to use JavaScript on the command line in a fast way, which does not involve Java.
00:08:11.220 One of the first things I did was create a blog comment similarity detector using Node.js. The idea behind it was to filter highly similar tweets. People would post numerous Twitter links in retweets, and if you could filter those, you'd free blog posts from spam. For the implementation, I used something called underscore.js, but I don't have time to explain it here. The code defines tweets that find semantically related terms over a vocabulary of over one million words.
00:09:35.019 Discus reported every link back to the blog post as part of the discussion on Twitter. However, these discussions were almost entirely made up of retweets, one exception being my link with a request to 'please filter highly similar tweets.' This showcased how easy it was to fill a blog with spam by simply linking back to a controlled post. I wrote this thing using Node.js and created a GitHub page for it. Here you can see some legacy code I worked on, which included spreadsheets of settings to streamline the codebase.
00:11:21.660 What I ultimately did was compress legacy code into fewer lines, and I managed to remove a significant number of lines automatically. This would typically be painful to do with client-side JavaScript, but Node makes it much easier. I also created a system called Taudi that I built in 2008, which uses Node.js to find similar functions along with Ruby and Sibilant.js for very simple wrapper functions.
00:12:25.541 I'll quickly go through the features I developed, including unit testing capabilities, allowing you to test JavaScript on the command line without needing a browser. Jasmine is a tool I use for that. Here’s an example of using 'require' in Node.js, which is a packaging system where you add objects to existing exports to create namespaces. The mathinator example showcases how to set up a basic function, including spec tests.
00:13:39.434 Node.js is great for creating mini apps. The first thing I built was a minimal GitHub dashboard that takes your repos and shows them. The server setup is straightforward, allowing you to get repo information in JSON format. You add listeners for when data is complete, which can be rendered using Jade, another templating library.
00:14:35.919 Minimal Bitly is another mini-app I developed. It focuses on compressing URLs that I use on platforms like Twitter. Unlike Bitly's complicated user interface, my app is straightforward. You put in your link, click shorten, and it’s done. This focuses on simplicity similar to popular Apple products, highlighting that sometimes design simplicity is more user-friendly.
00:15:59.040 As I was developing a few projects, I found that sharing simple code with my peers led to interesting discussions about the simplification of tasks. It's essential to recognize that keeping things simple and intuitive can improve user experience immensely. Please find the code for all these projects on GitHub, and I encourage you to check it out.
00:17:48.300 Node.js provides the ability to create servers quickly and efficiently. I was working on another application called 'missing RubyConf,' to filter tweets around the Ruby community while I missed the conference. The application listens to Twitter feeds, filtering for specific keywords. The full script is available on GitHub; it's exceptionally simple and easy to follow.
00:19:30.340 Now, why should you care? What's the point of using this technology? It all boils down to enjoying programming in a way that eliminates frustration. I was brainwashed with powerful ideas that this kind of work can provide the flexibility to build unique applications without constraints. Though some may argue against it, Node.js offers liberating experiences through efficient coding practices that match developer needs.
00:21:43.520 Following the trends and evolution of programming languages, I keep discovering that modern needs require modern solutions. Macro powers allow writing repetitive structures in concise ways, streamlining your projects. Thus, embracing flexibility through something like macros can help free developers from tedious tasks and enhance creativity with programming.
00:23:12.040 Node.js offers creative avenues for interaction with the user around dynamic programming. If you struggle with repetitive coding or keeping up with asynchronous behaviors, learning and implementing Node can help mitigate these issues. New projects can stand as testimonies to the potential of this tool. I urge you to find out more about how it works and what it can do for your creative projects.
00:24:55.840 In conclusion, the knowledge within this community about Node.js, Lisp, and the programming approaches makes these languages worthy of exploration. The fifth series of code and creativity that surfaces from these discussions can open up new paradigms. Whether building applications or prototypes, the concepts and structures help reduce complexity and lead to a greater understanding of programming itself.
00:27:10.800 Thank you for your attention. If you have any questions or need assistance regarding projects, feel free to reach out either after the talk or at any time. I appreciate your engagement and look forward to seeing what great projects you’ll create using these ideas.
Explore all talks recorded at LA RubyConf 2011
+5