RubyGems

Summarized using AI

Standing on the Shoulders of Giants

Zachary Scott • February 19, 2014 • Earth

In the talk titled "Standing on the Shoulders of Giants" presented by Zachary Scott at RubyConf AU 2014, the speaker explores the significance of the Ruby standard library and its historical context. He emphasizes the wealth of knowledge encapsulated in the libraries used in Ruby development, which have been foundational since before the advent of RubyGems.

Key Points Discussed:

  • Historical Context of Ruby: Zach discusses how Ruby libraries evolved over time, mentioning pivotal contributions like setup.rb by Minoru Aoki-san, which simplified library installation and distribution.
  • Ruby Standard Library: The standard library, which comprises around 70MB of code released with Ruby installations, aims to alleviate the once daunting task of finding and verifying libraries. He highlights its crucial role in modern Ruby development.
  • Libraries Highlighted: Three specific libraries from the standard library are showcased:
    • DRb (Distributed Ruby): Introduced for easy distribution of code and commands over a network. Zach demonstrates how to develop a simple chat server using DRb, illustrating its ability to handle user connections and message distribution with concise code.
    • RDoc: A tool for generating documentation in Ruby, which now supports Markdown. The simplicity of parsing Markdown into HTML using RDoc is demonstrated, highlighting its utility in making documentation user-friendly.
    • Fiddle: A library that allows interaction with code written in other languages. Zach explains how Fiddle enables seamless communication between Ruby and other languages like Dylan, showcasing how simple it is to create and wrap functions for cross-language interactions.
  • Community and Evolution: Zach reflects on the Ruby community's growth and the impact of tools like Bundler on developers' productivity, emphasizing the potential for any Rubyist to contribute to the ecosystem.

Conclusions and Takeaways:

  • The evolution of libraries in Ruby has significantly improved development efficiency and accessibility.
  • Understanding and utilizing the standard library is vital for Ruby developers to leverage the foundational tools available to them.
  • The ongoing evolution of these libraries points to an inspiring future for Ruby, driven by community contributions and innovations.

Standing on the Shoulders of Giants
Zachary Scott • February 19, 2014 • Earth

RubyConf AU 2014: http://www.rubyconf.org.au

We take for granted the wealth of knowledge and wisdom that goes into each library we use within our programs. Many of the them we use today are built on top of libraries that have existed much longer than most of us have been programming in Ruby.
Allow me to guide you through some of these unusual and mysterious libraries that are made available in every Ruby installation. I'm talking about the standard library, which has largely been apart of the Ruby ecosystem since before gems were available.
There's around ~70MB of code in every installation, and it's just waiting for those eager to explore and discover what the pioneers of Ruby have provided for us.

RubyConf AU 2014

00:00:08.480 Welcome! I'm Zach. Thanks for the introduction, Josh. You're amazing.
00:00:14.920 My whole talk is just about Josh. It's a whole lie.
00:00:20.480 So, I'm going to talk a little bit about the history of Ruby, the standard library, and where things might be.
00:00:36.399 My slides are cut off. Starting off with a pain.
00:00:44.399 There we go. Okay, so I'm going to show you three libraries that I've picked from the standard library.
00:00:49.840 One of them is DRb, another one's RDoc, and Fiddle as you can read. I hope you can read this.
00:01:01.280 The title is 'Standing on the Shoulders of Giants'. I decided on this title because it sounds witty.
00:01:07.280 And honestly, I give myself credit for that.
00:01:18.560 So this is my first time in Australia, and I'm pretty excited! There's a lot of amazing Rubyists here.
00:01:25.360 It's kind of shocking to see such a great community here. The core is good.
00:01:31.920 I've met a number of you in other places, but it's nice to now be here on your soil and hang out with you.
00:01:43.119 Um...
00:01:48.479 So, is this going to happen the whole time?
00:01:57.040 What's the problem?
00:02:09.280 Almond, help me out!
00:02:14.959 I mean, you plug it in and it sets it automatically.
00:02:20.480 You did? Yeah, but that's not full screen, bro.
00:02:36.959 Hey, okay. Thank you.
00:02:42.160 So, where the last talk was interesting, it gave me a lot of material because I didn't really prepare this talk very well.
00:02:48.080 I was kind of up late and had a really not-so-great day yesterday.
00:02:53.360 But all that aside, I think it's really important to think about where we might be going in Ruby.
00:02:59.200 That was a great indicator of things that we should work on and areas we need to focus on as a community.
00:03:04.560 He made a really great point that the number of core people influencing these changes is very small.
00:03:10.239 However, as a group, we can make a huge difference.
00:03:17.680 I also liked that he mentioned Bundler, and Andre's here. Bundler's awesome.
00:03:25.280 There are a few other Bundler people here too; this is basically Bundler ZackConf.
00:03:31.360 I've decided Holmen's up next and his mom's here— that's awesome!
00:03:50.319 So, what am I getting at? Right now, literally anyone in here can write a library for Ruby.
00:03:56.640 They can push it to RubyGems, and within seconds, millions can download your code, install it, and have it right on their computer.
00:04:02.400 That's really amazing if you think about how far we've come with Bundler.
00:04:08.400 With literally one command and a Gemfile, you can install hundreds of libraries on your computer with one command.
00:04:16.639 After several hours of resolving, but we're getting there, and it's amazing.
00:04:23.919 I don't know what the point is, or where we're actually going, but I don't think anyone does.
00:04:29.520 We're just going to keep working at it and see where we go.
00:04:34.560 That, in itself, is really inspiring.
00:04:39.680 But with that, we have to think about where we've been.
00:04:45.440 All these tools we have are great and make our lives easier.
00:04:52.240 But there definitely was a time when we didn't have these luxuries.
00:04:57.840 Even before Ruby, when you were just writing C, packaging was a challenge.
00:05:04.320 A lot of this has been solved with Ruby and RubyGems.
00:05:10.880 There was a time when we didn't have RubyGems, and we had to pass libraries around over the Internet.
00:05:17.919 It was similar to what gems do now but far less efficient.
00:05:26.479 We had this guy, Minoru Aoki-san, who is the author of the Ruby Hacking Guide.
00:05:33.039 He also wrote setup.rb.
00:05:38.080 Setup.rb allowed you to have a program or a library with helpful methods.
00:05:41.918 You could easily install a program on your computer.
00:05:47.919 If you know Python, they had a similar process where you used 'python setup.py' or similar.
00:05:54.720 Back then, we had no automation.
00:06:00.320 You had to download the library and run a file manually.
00:06:08.400 Before that, we had RIA, the Ruby Application Archive, which basically functioned like a wiki.
00:06:14.319 You would attach a link to a tarball of your library, and people would download it manually.
00:06:20.640 There were no servers or cloud systems.
00:06:27.280 Everything was done manually.
00:06:33.520 This was like 17 years ago; setup.rb was first released 17 years ago.
00:06:40.000 Ruby Application Archive started 16 years ago shortly after.
00:06:47.199 Once we had an installer, the challenge was how to pass it around.
00:06:52.400 It's sad to see RIA go down because that box was lost.
00:07:00.000 But it's interesting to see where we've come from and where we're going, all because of that guy.
00:07:11.039 The standard library exists because of the huge burden it once was on developers.
00:07:17.520 They struggled to find trustworthy libraries from wikis.
00:07:23.039 Verifying if a tarball worked was difficult; verifying its integrity was done manually.
00:07:28.960 Hence, libraries were included in Ruby to ease development.
00:07:36.560 It's still going strong. Mark Bates mentioned in his talk that Minitest is still included in Ruby.
00:07:44.640 The three libraries I'm going to show you are still included in Ruby and useful today.
00:07:50.640 This isn't going to be a talk about best practice libraries.
00:07:55.840 Some of this stuff is just plain useless, to be frank, but it's cool, and I want to share it.
00:08:11.640 The first library I have is DRb, which was written by this guy about 10 years ago.
00:08:17.200 It started as a plugin for the original Webrick servlet in Ruby.
00:08:23.920 He wanted a way to distribute code and commands over the network.
00:08:30.160 There's a great book on it, I think it's literally called 'The DRb Book'.
00:08:34.880 It's published by Pragmatic Programmers.
00:08:40.159 What I want to build is a chat server using DRb.
00:08:46.640 I thought it would be great if we could all connect and chat.
00:08:52.800 However, you can't do that due to the flaky network here, and ports are blocked.
00:09:09.920 So, I'm going to start by writing my server.
00:09:16.720 This server will accept connections over the network and distribute messages.
00:09:24.000 I'm going to use a class to allow DRb to connect to remote objects.
00:09:29.600 When initializing, we can't misspell 'messages', so we create hashes for both messages and users.
00:09:34.320 When accepting a connection, we'll add a user object to our hash.
00:09:42.560 I’ll show you what the client will look like next.
00:09:50.640 Basically, we want to initialize a new client with this remote connection and store it.
00:09:59.680 We also want to return that so we can call methods on it.
00:10:08.560 This way, we get our client instance back and can call methods once the connection is open.
00:10:15.680 Finally, we want to distribute messages over TCP.
00:10:23.600 We'll pass messages to the remote connection.
00:10:30.920 To set up the username, when we get that connection back, I can just call the username method.
00:10:39.760 The user is a very basic object with just a username and a method to write strings to the screen.
00:10:46.680 That's the basic idea of our server, and with not even 20 lines of code, we can handle connections.
00:10:52.960 Now there's no actual DRb in this class, which is interesting, but that will handle the client connection.
00:11:04.800 So, let's write our client.
00:11:09.920 In the client class, we need to require DRb and the server we just wrote.
00:11:18.240 Our client class will set up our connection.
00:11:24.800 We do this by storing the username here too.
00:11:31.360 The client is the class that initializes the connection to the server.
00:11:36.000 When we want to distribute a message, we also need to pass that back to the class we wrote earlier.
00:11:44.480 The message resembles a chat message.
00:11:51.040 So we take the remote connection and pass in the message.
00:11:56.000 Now we also want to implement a way to take a message— just a string that we pass along.
00:12:02.640 We'll do this with 'server.remote.say(message)'.
00:12:09.840 Now we need to connect the DRb instance.
00:12:15.360 Using 'start_service', we pass it the URI.
00:12:22.480 We want to initialize the server object and then simply join the threads.
00:12:28.240 'Start_service' takes a URI and listens on that address. You can just pass nil.
00:12:35.000 This uses an underlying DRb method to determine the default port and address for running on Linux.
00:12:41.760 But just for sanity’s sake, I'm going to do it this way.
00:12:47.360 User will also be a simple class with a username. We just set that in the initializer.
00:12:52.560 And we just want to include a method to say messages.
00:12:59.760 This isn't exactly the most complicated Ruby I've ever written, but it gets the job done.
00:13:04.080 Here comes the fun part! This is where we write the chat itself.
00:13:11.760 We have all these classes in place and services connected; we now need to initialize the chat.
00:13:19.440 I'll require DRb again and that user class.
00:13:26.560 Basic Ruby now asks, 'what's your name?' We then simply get that input.
00:13:34.560 Now we have the username, and we want to start up DRb again.
00:13:41.920 We initialize the remote connection by calling DRbObject.new, passing in the URI.
00:13:48.080 So this takes two parameters: the first is the local object, and the second is the URI.
00:13:55.680 We're using the main server node for communication.
00:14:01.920 One thing I forgot to add to the client is how these objects are stored on the server.
00:14:08.760 When communicating, we want to pass along only a reference, not the entire object.
00:14:14.400 The user will have to be treated the same as it connects.
00:14:21.600 I’m not sure if I need to pass remote for the user; I must check.
00:14:27.880 So you call 'client.rb' and let’s see what happens.
00:14:34.560 Brother, I know. I just need to see if this works.
00:14:41.440 So let’s figure this out with the functionality.
00:14:48.800 Yay! It is done, and now it’s running on time.
00:14:55.200 The next one is RDoc by this guy, Eric Hodel.
00:15:02.240 He's a maintainer and really knows a lot about Ruby core.
00:15:09.920 What I want to show you with RDoc is that it comes with a markdown parser.
00:15:16.720 With RDoc4, it now supports markdown.
00:15:24.560 I'll write it as if we're using RDoc; it has a similar API.
00:15:31.679 You simply initialize a markdown object and call 'to_html' with some text.
00:15:38.360 So, literally about 15 lines of code gives us a markdown parser.
00:15:44.960 I'm going to read from standard input, convert a markdown file to HTML.
00:15:52.320 To do this, I'll initialize a new markdown instance and pass in standard input.
00:15:59.920 Then, I'll just output the HTML, simple as that.
00:16:07.440 Hey Charlie, is the ruby README in RDoc for markdown yet?
00:16:14.720 Never mind, I'll just use Rails.
00:16:20.720 If I call the README from Rails, and pipe that to RDoc, it outputs HTML.
00:16:27.440 We can save that to an HTML file, open index.html, and see the Rails README formatted.
00:16:35.240 That’s how easy it is!
00:16:41.840 This next one's going to be a trick, but how much time do I have?
00:16:47.440 Great, sorry Homan; love you, Homan's mom.
00:16:54.720 Alright, Fiddle is an amazing library. Originally, it started as an extension.
00:17:02.000 For DL, which is how we used to link libraries in Ruby.
00:17:08.640 DL is an old way to link libraries at a low level.
00:17:15.120 A few years later, FFI came along, which is way more standardized.
00:17:22.240 Aaron wrapped this as Fiddle, bridging the old with the new.
00:17:29.440 The great thing about Fiddle is that you can communicate across languages, libraries, etc.
00:17:37.200 I'd love to show you how to talk to Dylan.
00:17:44.720 Dylan is a statically compiled language, purely object-oriented.
00:17:51.600 Apple started it as an experiment for the Newton platform.
00:17:57.520 After it failed, CMU rewrote the compiler in Unix standard.
00:18:04.960 Now, we have the open Dylan implementation with tons of amazing libraries on GitHub.
00:18:10.960 I’m going to write something basic to show you.
00:18:17.760 It takes two integers and returns their sum, a plus b.
00:18:24.960 To make this callable from C, I’ll load the CFFI extension from Dylan.
00:18:31.520 Now we have to create a wrapper function.
00:18:36.640 This allows us to represent the parameters as types.
00:18:42.480 This represents a, b, and c, which is the result.
00:18:50.080 Now, we’ll give this function a name that we can access— let's call it 'adder'.
00:18:56.800 That’s really basic— defining the function and wrapping it.
00:19:02.240 Now, I'm compiling this quickly. Hope I have a minute.
00:19:08.960 While it's compiling, let's check out the Fiddle implementation in Ruby.
00:19:15.360 I’ll attach the Fiddle function I just wrote and use the adder function.
00:19:22.880 It takes two integers as arguments and returns a single integer.
00:19:30.080 Now, we can call it, 'Dylan.adder(2, 2)'.
00:19:36.400 If this compiled correctly, we should get a result.
00:19:41.920 I'm sure you get the idea without needing the specifics of the output.
00:19:48.720 This is all great, so check out Fiddle, Ruby, and Dylan.
00:19:55.520 And that’s all I have.
00:19:58.160 Although Zach likes to run over, I have time for one question in 140 characters or less.
00:20:04.960 Any questions for Mr. Zach?
00:20:11.599 Well, okay, thank you very much!
00:20:19.520 Oh, when you move into a new neighborhood you have to register the neighbors.
00:20:25.119 Thank you very much, Mark, for that great input! It's good! Thank you, Zach!
Explore all talks recorded at RubyConf AU 2014
+17