Ruby Programming
mmm..mruby, or why yet another Ruby implementation.

Summarized using AI

mmm..mruby, or why yet another Ruby implementation.

Matt Aimonetti • October 08, 2012 • Earth

In this presentation titled "mmm..mruby, or why yet another Ruby implementation," Matt Aimonetti discusses the MRuby implementation of Ruby at the Aloha RubyConf 2012. He emphasizes that while Ruby is widely known, MRuby provides unique benefits by being modular and embeddable.

Key Points Discussed:

  • Introduction to MRuby: Aimonetti explains that MRuby is an embeddable minimal implementation of Ruby, created to address functionalities that existing Ruby versions do not provide effectively.
  • Different Ruby Implementations: He lists various Ruby implementations, including CRuby, JRuby, Rubinius, and introduces MRuby as a new alternative.
  • Customization: One of the core features of MRuby is its modularity—allowing developers to customize their Ruby implementation according to their specific needs, such as adjusting memory management.
  • Embedded Usage: A key highlight is how MRuby can be embedded into devices, showcased by an example using Ruby to control a Lego Mindstorm robot.
  • Comparison with Lua: Aimonetti compares Ruby with Lua, a popular language in embedded systems and gaming, noting that both languages offer similar embeddable qualities.
  • Use Cases: He encourages the audience to explore MRuby for non-web-related applications, stating it can be useful in various domains, especially where traditional Ruby may not be suitable due to resource constraints.
  • Performance: The speaker addresses performance comparisons among different Ruby implementations, including benchmarks that illustrate MRuby's efficiency.
  • Lack of Documentation: Aimonetti mentions a common concern with Ruby, which includes limited documentation, but reassures the audience that knowing the language negates much of this issue.
  • Encouraging Experimentation: He concludes by urging attendees to take MRuby and experiment with it beyond typical web applications, highlighting the joy found in coding and experimentation.

Conclusion:

Aimonetti's talk ultimately conveys that while MRuby may seem like 'just another Ruby', it provides valuable features for developers looking to expand Ruby's utilization in various embedded scenarios. His insights encourage embracing MRuby's potential for innovation within the Ruby community, sparking curiosity and experimentation.

mmm..mruby, or why yet another Ruby implementation.
Matt Aimonetti • October 08, 2012 • Earth

mruby is Matz’ new Ruby implementation, it’s not cooler than node.js, it doesn’t natively support Hypstermedia, it looks just like the good old Ruby. So why should we, as a community care?

Help us caption & translate this video!

http://amara.org/v/FGfr/

Aloha RubyConf 2012

00:00:15.480 Good evening, everybody! Good evening! Are you guys tired? You want to have coffee here before we start? It's the last talk, and I have a surprise for you.
00:00:21.000 So, is everybody ready? You guys good? Yes? All right. You guys had a good conference so far? It was pretty cool, thank you.
00:00:33.760 Maybe we should applaud the organizers for the good job.
00:00:39.680 Okay, so I'm going to give you the last talk of this conference, and it's kind of a dry subject.
00:00:45.920 It's called mRuby, and Ruby is not the most exciting thing ever. Even though I'm personally excited about it, I think some of you might not be. So, I actually did another talk inside my talk. If you feel kind of bored and you're not interested, just hold on with me for a little bit. There's another talk coming in. It’s actually two short talks so you don’t fall asleep.
00:01:09.680 The first talk is on Ruby, and the second talk is on revisiting Ruby. Before I start, I want to give you a quick disclaimer: I actually don’t like cats, and I’m really sorry about that.
00:01:28.400 I know it's bad to admit it. Every time you put a slide of your cat, this is what I see—an evil cat looking at me, ready to attack me. I need to talk to my shrink about it.
00:01:41.119 But I think between Aaron's talk and Cy's talk, I was kind of traumatized. So instead, I'm giving you a cute dog—it's not mine, I just found it on the internet—but it looks cool. And I realized nobody ever put a tapir in their slides, so here's a baby tapir for you guys. I named her Tapa.
00:01:52.399 That was just because I'm also very stressed before I give a talk. I figured a cute animal might help. I used to bring my daughter up front, and people made comments about it that I shouldn't really do that. So you will see my daughter running around, but I'm not going to show her to you.
00:02:22.400 Who am I? I work for LivingSocial. We're now hiring. We've been hiring for a very long time, but we keep on hiring, and we're looking for really good people. I think we have four or five people here from LivingSocial, so if you're looking for a job and you're a very talented person, come and talk to us.
00:02:50.360 As I was preparing this talk, I was getting kind of stressed and thinking I might not do a good job. I was asking my mentor, Chad Fuller, what should I do, and he told me, 'Here are the five rules.' Now, the problem is that because of rule number three, I can't read them to you. Please take a moment to read them, and remember, I'm going to try to follow them.
00:03:11.440 Do you guys get it? Yes? Okay, that was number two. I’m going to try to change a ton with my voice. I quite did not understand what that meant, so I might try to go high-pitched sometimes and kind of lower-pitched other times. We did number five before, so that might help quite a lot. I’m going to try to enjoy myself. I've been enjoying myself in Hawaii now for about a week, and it’s been a lot of fun.
00:03:25.400 All right, let’s talk about Ruby. Ruby has a lot of different implementations. These are the main Ruby implementations: CRuby, Ruby Enterprise Edition, MRuby, IronRuby, Rubinius, and JRuby. I’m reading the slides—I’m doing it wrong, sorry Chad. Please read all that for yourself.
00:03:44.080 You might look at that and think 'Wow, more Ruby.' But I didn’t really know what you guys would think about it. Matt looked at that and thought he was good, but he needed another Ruby, so he came up with MRuby. So, why did he come up with MRuby? Well, that's a good question.
00:04:12.640 From what I gathered in talking with him and reading his code, I realized he wanted to achieve two things that none of the current existing versions of Ruby or implementations really do well. One is being modular. This means that, in Ruby, you can use float instead of double, you can set a maximum number of arguments, and you can disable a bunch of stuff. You can actually change the memory management if you want.
00:04:39.960 You can basically customize your Ruby implementation the way you want it. Anything that's not cross-platform is not available in Ruby, which is interesting because a lot of things really relate to the platform we use, and I'll show that later. The other main value of MRuby is to be embedded.
00:05:06.080 What does that mean? Well, I have a quick example here of some Japanese developers who put Ruby inside a Lego Mindstorm robot. Here's the code—you may not see it very well, but basically, this Ruby code was compiled into bytecode and loaded into that, and hopefully, it's going to start showing the robot soon. I forgot to plug in the music, but here’s the robot running on Ruby.
00:05:41.960 It just started. You can think about putting Ruby in your watch or in your fridge or somewhere else. Do any of you guys use Ruby for something that's not web-related? Can I see some hands? Wow. What do you use it for? Serial port? Somebody else? What do you do? I’m sure I saw a few other hands earlier.
00:06:30.479 That's actually an example of where you can embed Ruby in a device that has different restrictions than the usual Ruby. You might think, 'Well, since it's Matt working on it, it's the same thing as Ruby 2.0.' Well, it's not. It's actually two different projects. MRuby supports and follows the ISO standard for Ruby, but it’s a different implementation.
00:06:55.360 You might wonder why it's called MRuby and why it's so hard to say. Well, the reason is because it comes from Matt’s embeddable minimal implementation of the Ruby language, so you have MRuby—or if you don’t want to say MRuby, you can also say 'minimalistic Ruby,' but that might not be really true in the future, so just stick to MRuby. It’s also very fun to say.
00:07:49.760 In the year 2012, something special happened. After many years of Matt talking about the right VM and getting this implementation of Ruby, he finally released a preliminary version in April of that year.
00:08:03.039 This release was sponsored by the Japanese government. The Regional Innovation Creation R&D program—I’m not really sure what it means. Chad, I think you were there when they announced it. Do you know what they do? No? Nobody knows, but they actually gave money to Matt to develop Ruby.
00:08:27.159 Thank you to the Japanese government; we can now put Ruby on Lego, which is pretty cool. Kind of the two things I really like in my life: my wife and my kid.
00:08:38.039 As far as I know, I only have one, sorry. Okay, so how do you use Ruby? The first use is actually the usual use of Ruby. You can just say Ruby and then execute your Ruby script. That's how it works in Ruby.
00:08:52.440 You also have RB, which is a REPL. You just type mrb, and then you type your code, and it will interpret it in real time. You can also just interpret it like you do normal Ruby, but where it gets interesting is that you can generate bytecode or intermediate representation.
00:09:16.079 So now you can have this bytecode instead of the source code you have; you can use that in your C code and interpret it in real time. What’s more interesting is that you can actually convert Ruby code into C code.
00:09:51.200 You can take your source code in Ruby and generate C code. There are two different formats: a readable format that basically generates real C code or a binary format of it. Here is me generating a Hello World in Ruby—that’s C code. You can see I create an instance of the Ruby interpreter, create an array of characters as my string, print it, execute the source code, and then return zero.
00:10:43.280 So this is the first step—you need to compile it and link it, and it gives you this machine code version, and then you execute it. It actually runs the printed Ruby code.
00:11:05.680 So, what are the use cases of Ruby? I thought a lot about it and could find various use cases, and I found it's basically wherever you use Lua. Lua is really the motivation or the inspiration behind Ruby.
00:11:37.680 Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics.
00:11:58.280 Thank you very much, you did a good job! So, I just didn’t want to break rule number three from Chad’s rules, so that’s why I had to ask somebody else to read it for me.
00:12:08.360 You can see from these two definitions that one really focuses on efficiency and the other one on being explicit and communicating productivity. These are two different concepts when it comes to programming languages.
00:12:44.880 Lua is very popular in the video game industry. Here's a survey from 2019 where we asked video game developers what scripting languages they use when creating games. Most video games are written in C or C++, and within them, they might use a scripting language for AI and configuration, etc.
00:13:49.920 Lua is by far the most popular scripting language. Many people also use custom languages. If we were to rerun this survey, we might see more custom languages because they offer a bit more flexibility.
00:14:01.200 So, why is Lua so popular? First, it's a very simple language, quite close to JavaScript. If you don't know Lua, you can just think about JavaScript. Lua is very easily embeddable because it has a simple and well-documented API. Its memory footprint is small, which is useful when you're limited by the device's memory.
00:14:38.000 Finally, it's very portable. You can move it from one platform to another, and things work well. Ruby has a similar set of qualities.
00:15:00.560 I'm going to read you a description of Ruby as a dynamic programming language with a focus on simplicity and productivity that has an elegant syntax that is natural to read and easy to write.
00:15:44.000 I just couldn’t help but think it would be easier if we could open up a file and have everything be right there instead of going and searching through documentation. This is an aspect we'll keep exploring.
00:16:31.920 Now, if you need to find an example all you have to do is access the source code, so that becomes feasible and practical.
00:16:57.280 I'm also not going to be doing a very academic presentation. I'm going to present you with real examples of where I used Ruby in projects and how they worked and how I set them up.
00:17:50.360 So, what are the goals? Why would you not want to use, or what should you be aware of when you use Ruby? The first thing is, like JRuby and MRuby, you can fork the process, but unlike the other languages, you don’t have any threads.
00:18:19.640 Is it a big deal? It depends on what you do. If you think about embedded programming, you probably don’t want to use threads or forks.
00:18:38.000 There's also no 'require' because everything gets compiled, and you don't have access to the file system. It's not officially released, meaning it's still in development, and things are changing.
00:19:02.320 There has been a problem with Ruby for a long time: very little documentation. You need to go into the source code, Google, and find information. It turns out you don’t need that much documentation because it’s Ruby, and if you know the language, you’ll probably be fine.
00:19:36.439 It doesn’t have a standard library. I was talking with Mark earlier. He was complaining that Ruby is getting too big and that the standard libraries are just too much. In Ruby, you just don’t ask for standard libraries—it’s just the basic of the language.
00:20:16.400 There’s a forum for Ruby that gets synced every night, adding specific things for the Unix platform. You have things like TCP, Unix sockets, exit, sleep, and things like that that don't exist in MRuby.
00:20:45.520 So how fast is it? It seems we care so much about performance. I was writing a lot of really cool benchmarks, and they’re totally useless. The best way of benchmarking a language is by using Mandelbrot.
00:21:33.920 Let me show you that right now. So here I have Ruby, let me see what version I have. Ruby 1.9.3-p194, let me run it. It should run about 10 Mandelbrots and see how long it takes. It took about—hard to see.
00:22:03.440 Let me try that with Ruby, and you can see it's much faster already—almost half of it, not quite, but it’s much faster in a benchmark that doesn’t make any sense.
00:22:44.040 But you can see it's actually really fast to print Mandelbrots. Now, I tried JRuby because Charles really cares about performance, and JRuby was fast, but MacRuby was even faster.
00:23:06.960 But this doesn’t mean much. So Ruby is a hacking language. That’s kind of what we forgot over the years because we’ve been writing apps and making money.
00:24:04.000 It’s nice to remind ourselves to enjoy the coding process. Remember to keep experimenting with Ruby outside of the web.
00:24:30.520 I want to encourage you to go home and take Ruby and do something that’s not web-related with Ruby, and you'll find it’s a lot of fun.
00:25:06.676 I want to switch to the next part, and because you might forget about what I talked about, I want you to ask me questions now.
00:25:29.760 Do you have any questions about MRuby? No? Everybody got it? Sorry, yes, the question is can I give Aon a hug? Of course! Aon, can you come here, please?
Explore all talks recorded at Aloha RubyConf 2012
+13