8 ms·
Respectfully mostly disagree. Ruby is full of sharp knives. Other languages have dull knives. Writing code without thinking will cut you either way. Things li
by RangerScience 3y ago
Respectfully mostly disagree. Ruby is full of sharp knives. Other languages have dull knives.
Writing code without thinking will cut you either way.
Things like method missing are exactly the right solution for a certain set of problems. If used thoughtfully, they’re amazing. If used thoughtlessly, bloody mess. But this is true in every language.
- busterarm 3y agoIf you want to be wowed by how incredible method_missing and define_method are, read through ActiveSupport and ActiveRecord's source code. Early in my career I made my own toy ActiveRecord implementation and it's full of define_method and was literally the first time in my life that programming felt like a real superpower.
- Groxx 3y agoWhere other languages have footguns, I've often described Ruby as offering footchainsaws, while tempting you to juggle them for fun. Far more damaging if you aim it at the wrong thing, but also far better at cutting down things that stand in your way. I think it's the most enjoyable language I've used. With care and feeding it's amazing. I would absolutely not want to use it in a large company, that would be a walking nightmare.
- vlz 3y agoYes, I want to highlight what you say about large companies. ruby really shines, I think, if you are a solo dev or a small team, where everybody is on the same page and the codebase is completely understood. It is also good for libraries with a clear focus. For larger projects, it might work too, but you would need some good culture of "keep it simple" around it. A few ego-trips of supposedly smart devs and things can get hard to understand and hard to work with fast.
- cutler 3y agoHere we go again with the Ruby isn't suitable for large projects nonsense. Github, Shopify and Stripe seem to be managing perfectly fine with Ruby, thank you very much.
- vlz 3y agoSure, but as I said, probably not without establishing some culture around it. Just for fun, let's look at shopify's Ruby Style Guide under "General"[0]: Avoid mutating arguments. Avoid monkeypatching. ... Avoid needless metaprogramming. Prefer public_send over send so as not to circumvent private protected visibility. Write ruby -w safe code. ... [0]: https://ruby-style-guide.shopify.dev/#general https://ruby-style-guide.shopify.dev/#general
- mokkol 3y agoEvery big company has (and if they don't, they should) style guides. In Ruby people tend to use something like Rubocop (which is a static code analyzer/linter) to agree on a style. That will even be added as a default in Rails 8.
- stevebmark 3y agoCalling method_missing a sharp knife is like calling GOTO a sharp knife
- whakim 3y agoBut we’ve learned over the decades that footguns should usually be avoided and discouraged rather than made easy to use like Ruby does. There’s a reason we aren’t writing GOTOs anymore, GC is a thing in all but the most performance-critical situations, and static typing is gradually winning.
- jay-aye-see-key 3y agoI’ve always really disliked the sharp knives metaphor. A chef’s choice of knife doesn’t impact their coworkers, nor does it end up on the plate to a customer. If we were chefs a knife would be your laptop, your editor, your cli tools. Not your programming language. A better metaphor would be the lumber in a building or the soil in a garden. I don’t know what I’d call ruby in this metaphor, maybe “lightweight wood that splinters”…
- tvink 3y agoThe value of metaphors is not their ability to stay relevant at arbitrary inclusion of scope. That being said, the original "Sharp Knives" piece is talking about powerful language features and whether to ban them in your kitchen, so yes, it has plenty of effect on their coworkers. Because it's a shared decision to not ban sharp knives from the kitchen, but trust and educate, and realize that people who're doing harmful things can do so with dull knives too. It's about the techniques you allow in your codebase, it doesn't propose that ruby is one "knife". And programming language features does not, generally, end up on the plate of the customer either. The fact that this site is written in a language that allows even more powerful meta programming than ruby is not bleeding through in the sense that we now have the tools of the language available to us. We haven't been served sharp knives. We've been served the consequences of the engineering that went into it, and the people doing that engineering had the opportunity to leverage or ignore the sharp knives of the language. That language being lisp, I'm pretty sure they had at it.
- chucke 3y agoMost other languages don't have knifes at all. What do you call the interface{} madness in go?
- berkes 3y agoWhen you have small children, you put your sharp knives out of the way. If children get a bit older, you first teach em responsible use of a knife, then give a sharp pocket knife. And some kids not even that. Point being: In Ruby, sharp knives are too accessible, come with no warning or even encouragement. Yet contrary to actual sharp knives (or guns pointed at feet) the feedback loop is slow. When you shoot yourself in the foot, or cut your finger, you feel it right away and (hopefully) adjust before more accidents happen. With Ruby, a footgun is fired today. Or a sharp knife carelessly tossed in the bag yesterday. But you'll feel the pain in months or years only. And probably not even you, but the person who followed your follow up. Sharp knives are cool. But they need education on their dangers and responsibilities.