DHH · 2025-07-12 · source ↗ · whole document (17)
Beautiful code
`0:46:10`
Now you're iterating over the code in that bracket five times, that's it. — [Lex] Okay, that's nice. — That's not just nice, that's exceptional. There's literally no other programming language that I know of that has managed to boil away the line noise that almost every other programming language would inject into a five time iteration over a block of code to that extent. — Wow, that's a really nice, well, thank you for giving that example. That's a beautiful example. Wow, I don't think I know what programming language that does that. That's really nice. — Ruby is full of that. So let me dive into a couple of examples. Because I really think it helps paint the picture. And let me preface this by saying I actually, I like the ethos of Python. I think the Ruby and the Python community share a lot of similarities. They're both dynamic interpreted languages. They're both focused on immediacy and productivity and ease of use in a bunch of ways. But then they're also very different in many other ways. And one of the one ways they're very different is aesthetically.
`0:47:11`
Python, to me, I hope I don't offend people too much. I've said this before, it's ugly. And it's ugly in its space, because it's full of superfluous instructions that are necessary for legacy reasons of when Guido made Python back in '87 that are still here in 2025. And my brain can't cope with that. Let me give you a basic example. When you make a class in Python, the initialize a method, the starting method is def. Okay, fair enough. That's actually the same as Ruby, D-E-F, definition of a method. Then it is underscore, not one, underscore, two, init, underscore, underscore, parentheses start, self, comma, and then the first argument. — [Lex] Yeah, the whole self thing. — I look at that and go, I'm sorry I'm out. I can't do it. It's everything about it
`0:48:12`
offends my sensibilities to the core. Here you have the most important method that all new objects or classes have to implement. And it is one of the most aesthetically offensive ways of typing initialized that I've ever seen anywhere. And you guys are okay with this? — Hey, you're making me, you know, where you're like talking about my marriage or something like this, and I'm not realizing I've been in a toxic relationship all along. Yet, I just get used to it. — That to me, by the way, was the magic of Ruby. It opened my eyes to help beautiful program could be. I didn't know I'd been working in ASP. I'd been working in PHP. I didn't even have the concept that aesthetics beautiful code was something we could optimize for that. Something we could pursue. And even more than that, that we could pursue it above other objectives. That Ruby is as beautiful as it is. It's not an accident and it's not easy. Ruby itself is implemented in C. It's very difficult to parse Ruby code,
`0:49:14`
because Ruby is written for humans and humans are messy creatures. They like things in just the right way. I can't fully explain why the __init___ make me repulse, but it does. And when I look at the Ruby alternative, it's really instructive. So it's def, same part, D-E-F, space, initialize, parentheses. Not even parentheses. If you don't need to call it within the arguments, there's not even a parentheses. That in itself is actually also a major part. If the human doesn't need the additional characters, we're not just gonna put them in because it'd be nicer to parse for the computer. We're gonna get rid of the semicolons. We're gonna get rid of the parentheses. We're gonna get rid of the underscores. We're gonna get rid of all that ugliness, all the line noise and boil it down to its pure essentials. And at the same time, we're not gonna abbreviate. This is a key difference in the aesthetics between Ruby and Python as well.
`0:50:14`
init, short of type, it's only five characters. Initialize is a lot longer, but it looks a lot better and you don't type it very often. So you should look at something pretty. If you don't have to do it all the time, it's okay that it's long. Those kinds of aesthetic evaluations are rife all over the Ruby language. But let me give you an even better example. The if conditional. That's the bedrock of all programming languages. They have the if conditional. If you take most programming languages, they all have if. That's basically the same in almost every language. Space, start parentheses, we all do that. And then you have perhaps, let's say you're calling a object called user.isadmin, close parentheses, close parentheses, start brackets, and here's what we're gonna do if the user is an admin, right? That would be a normal programming language. Ruby doesn't do it like that.