Tail Call Optimization

Summarized using AI

Standing on the Shoulders of Giants

Ryan Davis • March 29, 2015 • Earth

The video "Standing on the Shoulders of Giants" by Ryan Davis at the MountainWest RubyConf 2015 discusses the importance of learning from the innovations of foundational programming languages to enhance Ruby. Davis emphasizes that while Ruby is a capable language, it has not sufficiently incorporated ideas from other influential programming languages. He surveys innovative concepts from languages such as Smalltalk, Self, Racket, and Cola, presenting their potential contributions to the evolution of Ruby.

Key points discussed include:
- Historical Context: Davis refers to the quote, "If I've seen further, it is by standing on the shoulders of giants," to illustrate how innovation builds on past knowledge.
- Overview of Ruby: Ruby, created by Matz in 1993, is noted for its complexity and focus on developer happiness, with features that have mostly stabilized since version 1.0.
- Borrowing Innovations: Davis advocates for Ruby to adopt advanced principles from other languages:
- Smalltalk: Highlights its fully immersive development environment and simple syntax, along with its emphasis on object orientation.
- Self: Introduced concepts like prototype-based design and Just-In-Time (JIT) compilation, which can improve performance.
- Racket: Known for its extensive libraries, efficient design for both beginners and experts, and structural pattern matching which surpasses Ruby's capabilities.
- Cola: Emphasizes simplification of complex systems through a combined object and lambda architecture that promotes efficient programming.
- Execution Performance: Davis underscores the performance gaps between Ruby and these languages, particularly in method calls and dynamic features.
- Conclusion: He calls for Ruby to embrace innovative ideas and concepts from other programming languages to prevent stagnation and to keep advancing in complexity and functionality, ultimately positioning it alongside its more evolved counterparts.

Davis' talk is both a critique and a rallying call for the Ruby community to tap into the rich history of programming language development, leveraging foundational ideas to enrich Ruby's future. He believes that Ruby can restore its status as a powerful language if it learns from and stands on the shoulders of the giants who have come before.

In summary, this discussion is a critical exploration of Ruby's potential trajectory, urging developers to integrate and innovate based upon the successes of past programming paradigms.

Standing on the Shoulders of Giants
Ryan Davis • March 29, 2015 • Earth

by Ryan Davis
Ruby is a fantastic language, but it could be better. While it has done a terrific job of taking ideas from languages like smalltalk, lisp, and (to an extent) perl, it hasn’t done nearly enough of it.
Big thinkers like Alan Kay & Dan Ingalls (smalltalk), David Ungar (self), Guy Steele & Gerald Sussman (scheme), and Matthias Felleisen (racket) have paved the way for so many programming language ideas that we should plunder the treasures that they’ve thought up. You might not know their names, but you’ve certainly used their technology.
I will survey a vast minority of these ideas and how they could help ruby. Ideas including: self-bootstrapping implementations and extensive collection and magnitude hierarchies from smalltalk, instance-based inheritance and JIT compilation from self, TCO and the overarching importance of lambdas from racket/scheme, and finally object level pattern matching and the combined object/lambda architecture from the View Points Research Institute.
Ruby is at its best when borrowing great ideas from other languages, but lately it has fallen behind in this. It’s time for ruby to step up and do more with these ideas, to keep pushing forward, to stand upon the shoulders of giants.

Help us caption & translate this video!

http://amara.org/v/GVgj/

MountainWest RubyConf 2015

00:00:00.000 Foreign
00:00:23.199 So, as I said before, I'm Ryan Davis, the founder of Seattle RB. We celebrated our 13-year anniversary last week.
00:00:30.960 I just want to say that this is one of my favorite conferences and I'm really glad to be back again.
00:00:36.320 Thanks to Mike, all the volunteers, everyone—can we please give them a round of applause?
00:00:50.000 Okay, setting expectations. I hate this mic; it's going to kill me.
00:00:58.640 This is a bit of a history talk, which is not really the type of talk I like to give. It has very little code and is more of a survey of the ideas that inspire me and what I want to bring into Ruby. I have 109 slides, or about 3.6 slides per minute, so we should be good to go.
00:01:17.680 About 900 years ago, this guy named Bernard said the following: 'We, meaning the moderns, are like dwarves perched upon the shoulders of giants—the ancients—and thus we are able to see and move farther than they did. This is not because of the acuteness of our sight or our stature, but because we are carried aloft and elevated by the magnitude of the giants.'
00:01:33.280 About 500 years later, this thought was simplified to, 'If I've seen further, it is by standing on the shoulders of giants.' In other words, this concept is not a new one at all. Newton was simply iterating on the idea that every innovation builds upon the ideas that came before it.
00:02:07.119 This begs the question: when we create a language, why do we build it anew more often than not? But what does this have to do with Ruby? Well, everything, right? Otherwise, this talk would have been rejected. While this may be unnecessary for all of you, here's a brief overview of Ruby's features for later comparison.
00:02:26.640 Ruby was created by Matz in 1993. It is interpreted and file-based scripting, and I put quotes around 'scripting' because it’s purely object-oriented and has a class-based runtime. Its syntax and semantics are complex, which is a big part of why we love it. It offers an extensive class library, a numeric tower, and more—a very rich language, designed and optimized for what Matz calls 'developer happiness.'
00:03:04.560 Here’s a basic example of Ruby for comparison later. This is a simple recursive Fibonacci function, optimized for line count, not readability: 'If self is less than two, return self; otherwise, return self minus one Fibonacci plus self minus two Fibonacci.' We can also see the release history of Ruby, with a four-year gap between versions 1.8 and 1.9, and another five years to 2.0.
00:04:09.519 I consider Ruby 1.8 the golden age, while 1.9 was very different. That gap represents something significant; we could have had more from the language in terms of features. Ruby 1.0 shipped with almost everything we use today, and not much has been added since.
00:04:29.919 Almost immediately after its release, Ruby introduced private and protected methods. Class variables were added in 1.6, encodings came in 1.9 and were revamped in 2.0, with a lot of syntactic sugar across versions 1.9 and above. Nearly everything but the encodings and some syntactic sugars predates nearly everyone in this room.
00:05:12.720 If Akira is in the room, I believe he predates 1.6 as well. So, Ruby is a fantastic language, but in my opinion, it could be better. I love the language, but it has done a terrific job of borrowing ideas from languages like Smalltalk, Lisp, and to an extent, Perl. However, I hope to see Ruby borrow more from Lisp and Smalltalk, and introduce fresh ideas from Self and Cola, potentially de-emphasizing Perl in the process.
00:05:48.639 Let’s talk about our giants: we have Smalltalk from Alan Kay, Self from David Ungar, Scheme and Racket by Guy Steele, Gerald Sussman, and Matthias Felleisen, and Fonk/Cola again from Alan Kay. To be fair, I do not imply that any of these individuals worked alone; they are the figureheads of these projects.
00:06:12.000 First up is Smalltalk, one of the first languages I truly loved. How many people here have coded in Smalltalk in the past? About six? Anyone at the top? Nope. Smalltalk was created by Alan Kay and Dan Ingalls at Xerox PARC in 1972, but it wasn't released to the public until 1980.
00:06:27.280 It's bytecode compiled and based on an image rather than a file system. It's purely object-oriented and uses a class-based runtime. Ruby's runtime heavily draws from what Smalltalk provided, as it has an incredibly simple and clean syntax with only six keywords and four precedence levels.
00:06:56.160 Smalltalk is known for its fully immersive development environment that includes a GUI. This environment acts as a true incubator for ideas, where object orientation began to take off, and many of the programming patterns we now use were born here.
00:07:20.319 For example, Fibonacci in Smalltalk is quite readable for Rubyists. The method signature is straightforward, and the control flow is clear. 'If self is less than two, return self; otherwise, we recurse and return the rest of the algorithm.'
00:08:10.960 Next up is Self, which many of you may not have heard of. Has anyone here used Self? A brief summary: David Ungar and Randall Smith started this project at Xerox PARC and completed it at Sun in 1987. It's bytecode compiled and includes just-in-time (JIT) compilation.
00:08:30.720 Like Smalltalk, Self is also image-based and strictly object-oriented, except it is classless or prototype-based. The syntax is very clean and similar to Smalltalk's. Self's runtime comprises just eight bytecodes, managing object-oriented principles using remarkably few components.
00:09:06.800 Self offers a rich interactive development environment akin to Smalltalk's but focuses more on the objects themselves. Here again, the Fibonacci example highlights the main difference: in Self, the 'self' keyword is optional, meaning the code can appear cleaner and more straightforward.
00:09:38.480 Now let’s discuss Racket, which is my current non-Ruby love language. Racket is a descendant of Scheme, which was created by Gerald Sussman and Guy Steele in 1975. They continued development through the early 80s; Scheme flourished as a minimal variant of lexically scoped Lisp. It introduced tail call optimization, the numeric tower, hygienic macros, first class continuations, among many innovations.
00:10:24.560 Racket is considered a maximal Scheme, boasting a vast and diverse library that's enjoyable to work with. You can perform a plethora of tasks; it’s genuinely a pleasure to code in. Created by Matthias Felleisen and the PLT group in the mid-'90s, Racket is bytecode compiled, file-based, mostly functional, and features a multi-language runtime.
00:10:57.839 Racket includes a simple syntax, extensive macros, and expressions, making development enjoyable, particularly when comparing it to Common Lisp. It offers a unique editor, but unlike Smalltalk's immersive systems, it isn’t as integrated. Racket uses prefix notation, which means function operators precede their arguments.
00:12:02.959 Finally, let’s talk about Cola, which I refer to as a beautiful tiny kernel. Cola is part of Alan Kay’s Viewpoints Research Institute (VPRI), a think tank they established through a five-year NSF grant. The main focus is a project called 'Funk' which stands for 'Foundations of New Computing.'
00:12:19.040 The primary project, Steps, aims to move toward expressive programming systems with a straightforward goal: recompute so that entire systems can be understood by one person’s brain. They aspire to create functional productivity applications with just 20,000 lines of code.
00:12:49.680 One sub-project of Steps is Cola, an incarnation of their underlying runtime. Although VPRI is a rapidly evolving target, Cola is something I’ve fallen in love with, and I believe it deserves more attention. Cola embodies the combined object and lambda architecture that I will explain shortly.
00:13:23.680 So, let's look at Fibonacci again, with a slight twist. We start with the signature on the integer class simply called 'fib.' Depending on whether you employ curly braces or square brackets, you choose between a Lispy or Smalltalk implementation. Both implementations are identical in terms of functionality.
00:13:54.080 From these four systems, it’s crucial to amalgamate their ideas, especially from Smalltalk, Self, Racket, and Cola. This is where I cut my object-oriented teeth, long before the concept gained popularity, as object-oriented programming was not as common.
00:14:20.800 In the past, Allen Kay and his team left Xerox PARC—known for innovation but poor at selling. They transitioned to Apple to develop what is now Squeak Smalltalk. Squeak is currently open-source and maintained; you can download it from their website.
00:14:46.960 The team, dissatisfied with coding in C, opted to rewrite the Squeak runtime in Smalltalk itself, using a static analyzable subset. They subsequently created a translator for that subset to compile it back to C, allowing them to bootstrap their progress.
00:15:24.800 This approach not only made developers happier but simplified understanding what the runtime was doing by writing it in the language being used, thus expanding the contributor base and enhancing runtime development.
00:15:49.280 Smalltalk possesses a wealth of class libraries, including 66 classes for collections and 32 separate classes for numeric hierarchies. In contrast, Ruby's core library comprises 93 core classes once stripped of less relevant constants. This juxtaposition highlights the significant resources available to Smalltalk developers over Ruby developers.
00:16:12.960 What truly sets Smalltalk apart is its outstanding developer tools that enhance productivity. Smalltalk was one of the earliest GUI systems, leading to the Xerox Star—another innovative concept that struggled to sell. The development environment features a workspace, akin to an REPL, with a class browser and a test runner that keeps track of code functionality.
00:17:04.320 In Smalltalk, editing and writing happens per method, not per file or class. This approach helps focus on specific tasks. The integrated debugger allows Smalltalkers to define tests which invoke the debugger on failures; you resolve issues right within the context of the test.
00:17:39.920 Introspection facilities offer users a comprehensive view of the code base, allowing for easy refactoring. This underscores a fundamental difference—Smalltalk promoted unit testing quite early, paving the way for innovative development practices.
00:18:08.640 Smalltalk's reflection capabilities, like introspection for implementers and senders, streamline the process of analyzing code structure. This proves significantly beneficial in refactoring and enhances developers’ understanding of their code.
00:18:41.680 Methods in Smalltalk offer inspect functionalities, revealing object structures that are entirely usable. This contrasts with Ruby's default inspect output, which is often considered unusable for practical programming because it doesn’t provide the necessary clarity for developers.
00:19:12.960 Self places a stronger emphasis on runtime versus language syntax. Language-wise, it resembles Smalltalk, but Self was instrumental in developing JIT compilation techniques, leading to more efficient execution models that have influenced languages like Java and JavaScript.
00:19:55.440 Prototyping, which found its roots in Self, emerged as a critical feature in modern languages. Since Ruby 1.9, dynamic method addition has become a significant feature, albeit with cumbersome code requirements. Self enhances object handling and offers better tools potential as its GUI includes various elements to facilitate interaction and enhance productivity.
00:20:44.800 Racket, as my current non-Ruby favorite, provides a polished coding environment with strong documentation. Whenever I encounter a problem, the responsive development team is quick to offer assistance. The extensive documentation surpasses Ruby's improvements since version 1.9, showing a commitment to educating newcomers and helping developers leverage the language efficiently.
00:21:17.440 Racket is built with beginners in mind yet remains useful for advanced developers. It has built-in features that allow for real-time experimentation, enabling enjoyable interaction programming. Additionally, Racket's integrated development environment (IDE) and learning curve make it accessible and flexible to developers of all levels.
00:22:04.720 Racket incorporates structural pattern matching, offering more powerful decomposition than Ruby's existing destructuring capabilities. Its language system supports various data manipulation features that surpass Ruby's current implementations in terms of performance and manageability.
00:22:51.600 In conclusion, the Racket environment begins each file declaration with a specific syntax, detailing the language used. It promotes organization and scoping; one can declare various languages in a single schema through simple annotations. What is crucial is the way Racket allows for new languages to flourish while ensuring efficient organization and language management.
00:23:28.000 The speed differences between Racket and Ruby implementations are stark, illustrating the practical performance gap we must address. We need to accelerate Ruby's method calls significantly, optimizing our language to compete effectively against other dynamically typed languages.
00:24:05.200 Tail call optimization is an invaluable tool, effective in speeding up Ruby's performance. While it can complicate debugging, pragmatic solutions exist to mitigate these challenges, making the arguments against optimization less compelling.
00:24:35.440 As I wrap up, I realize I may have taken on more than I can handle, but I genuinely admire the innovations these individuals are working on. VPRI's vision for computing is both powerful and challenging, as it seeks to simplify complex systems into understandable forms, all within the ambition of reducing code complexity.
00:25:19.760 To contextualize this, consider that modern operating systems run on millions of lines of code. In comparison, VPRI expects to create products that maintain clarity and efficiency in an astonishingly smaller codebase.
00:25:54.560 Their approach to computing prioritizes simple axioms over extensive library implementations, yielding maintainable and comprehensible systems. Such clarity allows for rapid prototyping, debugging, and system changes. In this aspect, they’ve demonstrated how simplicity can lead to powerful results.
00:26:38.960 Cola embodies the combined object and lambda architecture whereby the execution of functions and organization of data structures become highly efficient. This structure is crucial for understanding programming fundamentals along with the overall architecture, encouraging cleaner systems and promoting elegant coding practices to tackle complex problems.
00:28:03.760 I've surveyed only a minority of exciting ideas today, but they reinforce that Ruby excels when it borrows powerful concepts from other languages. Yet it has recently fallen behind, losing direction. It's time for Ruby to embrace new ideas and keep progressing, standing tall on the shoulders of giants.
00:29:06.880 Thank you!
Explore all talks recorded at MountainWest RubyConf 2015
+13