00:00:12.799
Okay, so I was told we're a little behind schedule, so I’m going to try to start quickly.
00:00:26.080
That was my way of avoiding rehearsal. So, thank you for being cool about that. My name is Thma, and this is my heterosexual life partner, Ruiz. We are originally known as web architects and internet experts.
00:00:38.360
You may have heard of us. We work for ATBT Interactive, which is awesome. We live in a place that is sometimes rainy, but awesome in its own way.
00:00:50.520
We are here today to talk to you about a couple of different programming languages. The first one we will discuss is JavaScript. Most of you probably know about JavaScript; it went through a bunch of different names and was invented by one guy who was highly stressed and hacked it up in just a few weeks.
00:01:09.920
We've been living with his mistakes ever since. It actually started out as a much more scheme-like language than the C-like syntax that we are familiar with now.
00:01:23.159
JavaScript objects function as both hashes and objects simultaneously. You can access them through an indexer, just like we're used to, and also through what looks like a method, which is quite interesting.
00:01:34.479
JavaScript functions are first-class citizens in the language; you can create them anywhere, assign them to variables, and call them through those variables. Unlike lambdas, except under certain circumstances, you can also bind them into an object, so they have a reference to 'this'.
00:01:47.079
Furthermore, JavaScript doesn't really have classes. You can take a function and make it act like a constructor, creating new instances with their prototypes, but it lacks class inheritance semantics that we might expect.
00:01:55.960
So, that was a very quick introduction to a strange little language that's actually much more popular than we might have expected based on its origins.
00:02:04.840
JavaScript is extremely significant because it is ubiquitous. It has the widest penetration of any programming language regarding consumer devices. It runs in your browsers, on many of your phones, and interestingly enough, there's a lot of JavaScript even on the moon.
00:02:30.080
It's in most web applications, which call for some level of JavaScript, but I'm not the best when it comes to cooking up JavaScript everyday applications.
00:03:11.799
The other language we want to talk about today is Ruby. I'd imagine most of you are familiar with the basics of Ruby, so I won't go over the basic facts about it.
00:03:22.920
What we’re interested in discussing is the importance of using both languages together and why you would care. Most of us work on the internet, especially on the World Wide Web.
00:03:49.280
There's a vast chasm between client-side behavior and libraries written in JavaScript on one side and frameworks dealing with Ruby on the other side. We are constantly switching between coding in one and coding in the other.
00:04:02.239
JavaScript is tightly coupled to the browser, which unfortunately limits its reach outside of the web environment. That can be frustrating. However, one of the benefits of JavaScript is that we get a great standard library.
00:04:24.520
When working with JavaScript, we have access to various tools, including excellent package management and command line testing frameworks, although ultimately everything depends on the browser.
00:05:08.440
This leads us to wish for freedom from the browser environment, enabling browser-less testing, file system access, and experimentation. And this is where Johnson comes in.
00:05:35.520
Johnson is a way of embedding a JavaScript runtime in Ruby or a Ruby runtime in JavaScript. It bridges the gap between these two languages, allowing you to use JavaScript in your Ruby applications and vice versa.
00:06:13.280
For instance, with Johnson, you can write snippets of JavaScript that return anonymous JS functions that act like lambdas in Ruby. You can also call Ruby functions from JavaScript directly.
00:06:35.560
In terms of execution environments, when you use JavaScript in Ruby, you can set up an interactive shell that allows you to switch between JavaScript and Ruby seamlessly.
00:06:54.560
For example, you can create lambdas in Ruby and call them from JavaScript or pass JavaScript objects back to Ruby without needing to marshal them. Everything is passed by reference.
00:07:30.000
This magic happens through Johnson proxies, as both Ruby and JavaScript treat everything as an object for the most part. However, the two languages cannot communicate directly because they don’t understand each other’s structure.
00:08:04.800
So we have wrappers in place to enable communication between Ruby objects and JavaScript objects. When you call methods on JavaScript objects from Ruby, they operate using the Ruby interface and vice versa.
00:08:33.120
This proxying is done transparently, which means you can interact with Ruby objects in JavaScript without needing to know the underlying implementation.
00:08:57.760
However, there are complexities involved, especially with garbage collection. Both Ruby and JavaScript have separate garbage collectors that can pose challenges when objects are passed back and forth.
00:09:40.760
Additionally, threading models differ significantly, with Ruby traditionally using green threads and JavaScript generally utilizing native threads. This can lead to issues when trying to run concurrent operations across these two environments.
00:10:30.440
Some of the most challenging components of Johnson stem from these differences, but they are necessary for the integration we hope to achieve.
00:10:55.560
Let's demonstrate the potential of Johnson. Consider the Fibonacci sequence—typically demonstrated in Ruby and JavaScript. Using Johnson, both implementations are handled seamlessly, and you wouldn't know which language manages which part from an end-user perspective.
00:11:21.800
The function from one implementation could return the same results as the other, and you could be surprised at the speed of execution.
00:11:51.320
Moreover, we've added a few utility functions to Johnson that enhance the experience of utilizing both languages together. For instance, we’ve provided a require function in Johnson that allows you to load both Ruby and JavaScript files.
00:12:20.360
This is beneficial since it lets you access Ruby objects from JavaScript, enabling deeper integration. Additionally, we provided methods to symbolize strings automatically when crossing the language boundary.
00:12:51.280
When we initially implemented this, we considered turning strings that started with a colon into symbols, but we realized that we needed a more explicit approach to make it function correctly.
00:13:24.360
On another note, executing JavaScript in a Ruby context opens up unique possibilities, such as accessing a database directly with JavaScript and performing queries without needing to switch environments.
00:13:55.440
We can confirm that you can write views in JavaScript within a Rails project while keeping everything well-integrated. This means you could maintain JavaScript code for your web applications effectively, reducing duplication of efforts in the process.
00:14:33.560
Finally, the ability to debug by setting breakpoints in JavaScript while using Ruby is a fantastic feature of Johnson, allowing developers to inspect their code execution without needing any browser interface.
00:15:16.200
Similarly, the concept of a 'hot Ruby' environment allows executing Ruby code compiled into bytecode. This allows an unusual integration where one processes Ruby on JavaScript for developing Ruby on Rails applications.
00:15:53.760
We have made considerable strides in making Johnson functional, and we've pushed our initial release to RubyForge. Despite its infancy and ongoing stability issues, we believe this evolution presents incredible potential to improve software development productivity.
00:16:32.440
We encourage the community to engage, test, and provide feedback to help us refine this tool. In essence, Johnson aims to bridge a significant divide and enable better integration between Ruby and JavaScript.
00:17:21.920
Now, we have a few minutes left for questions—so should we open the floor for them? Yes?
00:17:46.360
The first question is whether with hot Ruby you could execute Ruby programs in the browser. The answer is yes, although you still need Ruby to parse and emit the bytecode, and the implementation doesn't fully embrace the standard libraries at this point.
00:18:25.040
The second question raised was if we considered integrating with other languages beyond JavaScript. While JavaScript was our primary focus due to its immediate relevance, we are also keeping an eye on possibilities for integrating other languages in the future.
00:18:53.360
Additionally, we are looking into the possibility of running multiple JavaScript runtimes simultaneously using different engines.
00:19:30.080
We also expressed interest in potentially working on integration with Cucumber, primarily aimed at improving integration tests within JavaScript and Ruby combinations.
00:20:39.920
As we wrap up our Q&A, I want to thank you all for joining us. We've made substantial progress, though much work remains to be done. We hope you enjoyed our presentation.
00:21:02.560
Thank you for your time!