News for hackers. Stuff that matters.
Re:Where is Ruby Headed in 2021? by sanderjd on Friday November 19, 2021 @01:04AM (#29274309)
The often impossibility of finding the definition of the methods I'm calling is the main thing that soured me on Rails. I think a more explicit style is more common nowadays, which is a good thing.
Re:Where is Ruby Headed in 2021? by grncdr on Friday November 19, 2021 @03:41AM (#29275085)
Maybe you already know it, but I find `something.method(:mystery_method).source_location` points me to the right place more often than not. I only mention it because I have noticed a lot of people work productively in Ruby without leveraging it's dynamic/reflective features[0], but little idioms like the above are absolute lifesavers for me.

[0]: A big disadvantage of the above is it's not statically resolvable, so you couldn't really build an IDE go-to-definition with it.

Re:Where is Ruby Headed in 2021? by Lio on Friday November 19, 2021 @04:38AM (#29275410)
The two tools I'd recommend for navigating ruby code in addition to #source_location are Solargraph[1] and, my favourite, good 'ol exuberant ctags[2].

Solargraph is an amazing project but ctags is still just so fast and low overhead that it's what I mostly use.

ctag support is available for most editors and is built into Vim. You need to first generate a tag file (or have an editor plugin do it for you[3]) and then press Ctrl-] to go to definition.

1. https://solargraph.org/

2. http://ctags.sourceforge.net/

3. https://github.com/tpope/gem-ctags

Re:Where is Ruby Headed in 2021? by nitrogen on Friday November 19, 2021 @06:17AM (#29276054)
And don't forget the option of just calling into pry at the line in question and typing ls and show-doc. Also ripgrep is incredibly useful for navigating new codebases.
Re:Where is Ruby Headed in 2021? by sanderjd on Friday November 19, 2021 @02:53PM (#29281500)
Yes, grep + debugger / pry were how I solved this when I was still writing lots of Ruby. I find it much more productive to be able to get these answers statically, but I was too strong when I said "impossible"; there's always some way to find the right code, or the VM wouldn't be able to run it :)
Re:Where is Ruby Headed in 2021? by Lio on Friday November 19, 2021 @10:36AM (#29278236)
Yes, you’re quite right! Thank you again, I must remember to use pry more.

With ruby 3.1 I think we’re getting a new default debug.rb gem.

It will be interesting to see if pry or the beat ideas from pry can be integrated with that.

Re:Where is Ruby Headed in 2021? by chenmike on Friday November 19, 2021 @03:02AM (#29274890)
This magic is delightful in small codebases I’m familiar with and absolute hell in large codebases I’m not familiar with
Re:Where is Ruby Headed in 2021? by sanderjd on Friday November 19, 2021 @02:54PM (#29281508)
Well put. Totally my view of it.
Re:Where is Ruby Headed in 2021? by rhizome31 on Friday November 19, 2021 @04:17AM (#29275289)
I've worked with Ruby in the past and I currently work with Python and Elixir. This is a caveat that Elixir inherited from Ruby. In Elixir there's the `only` option of `import`, but it doesn't seem idiomatic to use it. In Python there's `import *` but it's an actively discouraged practice whereas in Ruby and Elixir it's the norm. I like all three but on this particular point I think Python got it right.
Re:Where is Ruby Headed in 2021? by sodapopcan on Friday November 19, 2021 @08:08AM (#29276739)
I _much_ prefer Elixir’s way of not using imports much and prefixing most function calls with the module name. That way when I jump to a function definition, I often don’t need to do any further jumping around—I know exactly where everything is coming from right there. I especially hate when language idioms encourage using a shorthand name for the module when importing. Just be explicit!
Re:Where is Ruby Headed in 2021? by MrWiffles on Friday November 19, 2021 @09:16AM (#29277341)
> [...] I especially hate when language idioms encourage using a shorthand name for the module when importing. Just be explicit!

THIS. 100%!

I also think Python seems to do this better with the namespace pattern of `import x.y.z`. Never seen the `import *` pattern before, didn't know Python can do that (never done Python really though either, only browsed some code here or there).

But one addition to your statement I'd like to add: not just idioms, but documentation can spread this antipattern too.

Noobs come to a language, read the documentation for some tool, library, etc., and understandably come away thinking "Oh ok, this is how it's done" when in reality, while they're not doing anything wrong per se, they're being taught a bad habit right off the bat. And that makes the inevitable hard slap across the face that reality (or a co-worker) eventually hits you with all the more shocking, possibly even leading to resentment of others when this happens.

I myself had this problem many years ago; "why the hell do you need all these subclasses and so many layers of abstraction?!" I once asked. "Because those class/method names already exist within other classes loaded at runtime, or will likely be added in future external dependencies, and we don't want to accidentally overwrite those."

Well, I thought that was a stupid idea. In my (very limited at the time) experience, when I had that problem, I just insisted on finding a damn good descriptive name that wasn't going to be used for anything else, even if it was wicked long or a pain to type. Too long? Don't be lazy. Typos more probable with length? Learn to copy/paste. That was the approach I learned at some point from some documentation somewhere on the internet, and it always worked for me, so it was the "one true path" and all others were inferior, making proponents or users/adherents of any other way "wrong" and inferior to me and my superior, non-lazy intellect. You're telling me that you do it differently? You must be stupid or lazy, and I'm neither therefore I'm better than you; thus forcing me to adopt your inferior standard?! Preposterous! Insulting! Offensive! That's how I saw it.

God, was I dumbass.

I developed this attitude by learning my skills in a near total vacuum, other than documentation written by people on the internet back in the 90's. Not official company-published technical docs, mind you, but forum and BBS posts, mailing list discussions, and way too much IRC to be considered "healthy" by any stretch of the imagination.

Those who taught me did so in a way that was efficient and they did no wrong at all of course - this failure was entirely of my own making, from my own arrogance. But it's also true that had I been taught at the same time that "there are other ways in other languages that are totally valid; this is just for simplicity's sake" and then been shown, or better yet required to use other patterns in school/projects/etc., I might have been able to see the short-sightedness of my own arrogance sooner. Instead, it resulted in an antipattern that allowed me to become overconfident, arrogant, and more difficult to work with than I should've been.

----------

In case you're wondering, I can't remember what I read or where that came from so long ago. Sorry. Might have been C, C++, Java, DOS BASIC (non-GUI/non-Windows), Visual Basic (before .NET) or maybe even PHP 3.something, no idea - that was 20+ years ago. I was inexperienced, arrogant, and a fool; none of that was the author's fault whatsoever. We're all young and stupid at some point in life. I'm no longer young, but at least now I know I'm stupid! :-)

Re:Where is Ruby Headed in 2021? by MrWiffles on Friday November 19, 2021 @08:59AM (#29277150)
Yeah that's been a major pain in my ass more than once, totally get where you're coming from there. One tip for you, and anyone else who might be reading this from the future (hi! do we have flying cars yet? what about time machines? can you bring me one of each, in like, 10 minutes?): RubyMine, the IDE from JetBrains (commercial, Java-based desktop app but not nearly as bad/sluggish as you might expect, though not native fluidity) has a feature to show you where a given method ultimately comes from, going all the way up the chain of source code and abstractions to where it's really defined, including within Rails or other libraries/gems/imported files in a given project. It's a really killer feature for this particular pain point, in my opinion.

Short of that, assuming all your dependencies are unpacked under your project's directory (likely .gitignore'd but there nonetheless, instead of in somewhere like /opt/ or /usr/local/lib or something) you could also `grep -ir 'def method_name' | less` or something to try to figure that out, though it's nowhere near as smooth as RubyMine.

Other editors have Ruby and/or Rails plugins that may help ease this pain point as well, though personally I haven't done anything with that on the editor front in a very, very long time. Generally I'm outright militant about keeping my dependencies to an absolute minimum in a project, and doing everything the most "vanilla" (standard, accepted, most widely adopted patterns, naming conventions, etc.) way possible, and therefore I usually know what gem/lib is providing what particular method, so I don't really need that kind of utility most of the time because I can google up some API docs...when there are API docs anyway.

But in cases where you're having a legacy project/monolith dropped in your lap and nobody knows anything because "the business guy" fired the one developer who actually knew how everything worked and now that guy won't answer his calls because working for free is dumb? Yeah, in those cases, RubyMine or a real good editor plugin can be a lifesaver for this.

Re:Where is Ruby Headed in 2021? by sanderjd on Friday November 19, 2021 @02:56PM (#29281547)
If that RubyMine feature works well these days then that's great! In my day it was nice but hit or miss.
Re:Where is Ruby Headed in 2021? by inopinatus on Friday November 19, 2021 @01:32AM (#29274439)
It isn't a good thing. My first advice to all newbie Ruby programmers is to stop thinking about methods and start thinking about messages.
Re:Where is Ruby Headed in 2021? by saagarjha on Friday November 19, 2021 @01:35AM (#29274446)
I don’t see how this helps?
Re:Where is Ruby Headed in 2021? by inopinatus on Friday November 19, 2021 @01:38AM (#29274456)
Ruby's dispatch is Smalltalk-like, not Java-like; it is (very) late-bound. The consequences for interface design are dramatic, the natural style being one in which objects notify each other, rather than telling each other what to do, and the result is loose coupling and ease of composition.

People trying to write Java-like OO in Ruby end up confused and frustrated.

Re:Where is Ruby Headed in 2021? by discreteevent on Friday November 19, 2021 @05:59AM (#29275970)
There's a tradeoff between coupling and cohesion. All the books and talks are about decoupling because that's the interesting part. The problem is that in poor codebases you find everything has been decoupled and the complexity is a nightmare. As Adele Goldberg said: "“In Smalltalk, everything happens somewhere else.” It's better to have a system where you only decouple where and when you want to because you have decided that paying the cost is worth it.
Re:Where is Ruby Headed in 2021? by llamataboot on Friday November 19, 2021 @08:25AM (#29276883)
They used to pay me to turn monoliths into microservices, now they pay me to turn their microservices back into monoliths...
Re:Where is Ruby Headed in 2021? by rhizome31 on Friday November 19, 2021 @04:23AM (#29275328)
I've worked with Java, Ruby and Python but I don't get your point. Can you recommend any resource to help understand what you mean? Or maybe some short examples in Python and Ruby that would highlight how implicit imports allow solving problems in a way that explicit imports prevent?
Re:Where is Ruby Headed in 2021? by stepbeek on Friday November 19, 2021 @09:47AM (#29277679)
Not the parent, but I’ve found Sandi Metz conference talks to be an amazing resource for learning more about this message focused approach.
Re:Where is Ruby Headed in 2021? by sanderjd on Friday November 19, 2021 @05:25PM (#29283398)
But back to the original point, Sandi Metz wouldn't suggest that implicit imports are good.
Re:Where is Ruby Headed in 2021? by inopinatus on Friday November 19, 2021 @02:39PM (#29281332)
Sandi Metz's talks, and Avdi Grimm's MOOM course.
Re:Where is Ruby Headed in 2021? by saagarjha on Friday November 19, 2021 @01:45AM (#29274483)
Ok, but Objective-C also does messages and most of them are defined statically and can be easily searched for in a codebase. I’m not saying Ruby needs header files to send messages to something, but being able to figure out where the code for something is isn’t off the table for languages with dynamic dispatch and it can come in handy.
Re:Where is Ruby Headed in 2021? by inopinatus on Friday November 19, 2021 @01:53AM (#29274508)
For that, there's

    object.method(:name).source
    object.method(:name).source_location
but frankly this is still thinking in a rigid mindset that suits other languages better. Ruby isn't just "dynamic dispatch"; a typical metaprogramming technique handles all incoming calls without named methods, or by dynamically writing the code.

To put it bluntly, assuming there's a method on the other side of your message, is practically the antithesis of Ruby.

It's similar to the category error that leads folks to conflating type with class, and writing type checkers that look for class signatures.

Re:Where is Ruby Headed in 2021? by eximius on Friday November 19, 2021 @02:14AM (#29274624)
While freeing to write, that is horrifying to inherit.
Re:Where is Ruby Headed in 2021? by inopinatus on Sunday November 21, 2021 @05:03PM (#29300193)
That isn’t code you write in an application. The topic was how to find a method’s handler, this is how it’s done in the REPL.

Or if you mean, dynamically instantiated methods, those are found throughout Ruby and its ecosystem, and the reason it isn’t horrifying is that the language has terrific support at the REPL for developers needing reflection.

Re:Where is Ruby Headed in 2021? by sanderjd on Friday November 19, 2021 @05:32PM (#29283468)
Yeah this is pretty much why I decided I didn't want to write Ruby anymore. You may be right that this is the philosophy of the language, but if it introduces a speed bump or cognitive overhead when trying to understand what a snippet of code is doing (and I contend that "there might not even be a method there responding to your message" is a speed bump), then it's not a good thing, even if it's clever and somehow ideologically pure and interesting. I can appreciate programming languages as art pieces, but when I'm at work I want them to just be a tool.
Re:Where is Ruby Headed in 2021? by mypalmike on Friday November 19, 2021 @07:06AM (#29276372)
The best features about this bridge are that it's made out of soap bubbles and it doesn't necessarily span the river at any given time. This flexibility is wonderful.
Re:Where is Ruby Headed in 2021? by inopinatus on Friday November 19, 2021 @02:37PM (#29281311)
That is not a good metaphor for anything, really: no-one was enlightened; at best some reddit-grade snark was conveyed.
Re:Where is Ruby Headed in 2021? by mypalmike on Friday November 19, 2021 @05:20PM (#29283345)
I worked with Ruby for two years. The metaphor is apt when considering software development as an engineering discipline. It was certainly not meant as snark. You disagree, that's fine.
Re:Where is Ruby Headed in 2021? by inopinatus on Saturday November 20, 2021 @01:31PM (#29290594)
Not really sure what you think I disagree with, since the metaphor is so vague and wishy-washy it could apply to anything from theology to stamp collecting, but it sounds like trying to conflate late binding with some manner of bad coding style.

Well, since I have been privileged to work with several really great Ruby teams over the last couple of decades, whose large and well-structured code uses metaprogramming techniques yet remains easy to follow & comprehend (and debug and extend), and who remain splendidly productive to boot, I can say, if this bunch of guesses at the intended meaning of that "soap bubble" metaphor hold water, then yeah, I disagree.

Conversely, shitty code can be (and is) written in explicit import and early-bound languages. The enterprise world, for example, is riddled with massive hairballs of brittle, unmaintainable, boilerplate-heavy Java.

All of which only goes to show that people, not the programming language, are the problem.

Re:Where is Ruby Headed in 2021? by tomc1985 on Friday November 19, 2021 @10:44AM (#29278321)
I can't think of a single point in my RoR career where this has come up. How do you even do Java-like OO when classes are so loosey-goosey anyway?

Though having suffered in a Rails codebase written by Java engineers, I definitely agree that a light touch is needed with OO -- though composition has its own difficulties and together this forms one of my bigger criticisms of Rails.

Re:Where is Ruby Headed in 2021? by chespinoza on Friday November 19, 2021 @08:22AM (#29276854)
There's plenty of people writing java-like code in Python too, just check Amazon SDK for python or GCP SDK, it's a mess, I don't know if they get frustrated but they do get SDK users confused and frustrated.
Re:Where is Ruby Headed in 2021? by t0mbstone on Friday November 19, 2021 @06:48PM (#29284121)
You need to be using RubyMine. Simply command-click on ANYTHING to jump to the definition, even if it's nested deep in a gem that your project uses.

RubyMine, and the "jump to definition" feature in particular, is the primary thing that enabled me to really "get" Ruby and finally understand how everything worked together.

Re:Where is Ruby Headed in 2021? by devoutsalsa on Friday November 19, 2021 @01:08AM (#29274328)
“git grep” is pretty amazing for tracking things down.
Re:Where is Ruby Headed in 2021? by oblio on Friday November 19, 2021 @05:28AM (#29275722)
That's like someone asking for directions and you giving them a shovel and a introduction to archaeology manual.

If someone asks for directions you give them directions or a current map.

Re:Where is Ruby Headed in 2021? by hagbard_c on Friday November 19, 2021 @10:39AM (#29278269)
Well, no, not really. It is more of the equivalent of showing how to read (or where to find) maps instead of pointing out something on one. If the searcher is in a hurry the latter is more helpful, otherwise the former is preferable.
Re:Where is Ruby Headed in 2021? by oblio on Friday November 19, 2021 @11:16AM (#29278744)
Yeah, but you shouldn't need git grep to find out what something is.

I understand using to find out why it's there, but not what it is.

Re:Where is Ruby Headed in 2021? by sanderjd on Friday November 19, 2021 @05:36PM (#29283510)
Yeah the problem is that grep understands lines of text but not the structure of code. But code should be understandable by a computer program (by definition it has to be at some point) so you should be able to use a tool that understands the structure of the code it's reading rather than just seeing a bunch of lines of text.
Re:Where is Ruby Headed in 2021? by devoutsalsa on Friday November 19, 2021 @02:45PM (#29281406)
Personally I find it faster than using an IDE much of the time. It’s super fast and very powerful.
Re:Where is Ruby Headed in 2021? by rhizome31 on Friday November 19, 2021 @04:29AM (#29275364)
Of course that's what we end up doing in practice, using external tools (CLI or IDE) to work around a limitation in expressiveness of the language. This advice is a testimony that there's indeed a problem upfront :) And it comes short when searching from commonly used names...
Re:Where is Ruby Headed in 2021? by nitrogen on Friday November 19, 2021 @06:22AM (#29276082)
This advice is a testimony that there's indeed a problem upfront

Indeed, and the problem is that IDEs have encouraged developers to write convoluted code and to forget how to navigate a filesystem. Reading code and commit history is a much faster path to understanding a system than an IDE's autocomplete. I learned this from Ruby, and it serves me well in C, Kotlin, Scala, PL/SQL, Typescript, etc.

Re:Where is Ruby Headed in 2021? by maccard on Friday November 19, 2021 @08:41AM (#29277000)
> IDEs have encouraged developers to write convoluted code and to forget how to navigate a filesystem.

I would argue the exact opposite. Developers who force tools designed 30 years ago to dictate programming language best practices today are holding back the entire industry. There is no reason for my tooling to depend on my filesystem; imagine if my IDE integrated directly with vcs, and a language server provided both of those tools semantic information about my code, available on any device. Let's not kid ourselves either, utf-8 isn't human readable on disk, it's still a binary-like format.

Re:Where is Ruby Headed in 2021? by rhizome31 on Friday November 19, 2021 @09:48AM (#29277695)
You're right to remind that the filesystem is a metaphor, a model and not the reality of what's going on on the computer. The thing is it's still the common denominator between different IDEs and text editors. IDEs cannot be used in every situation so any professional developer who uses an IDE also knows his way around with a text editor. If we were to come up with a better abstraction than the file system, it would have to be shared between different IDEs for interoperability. My understanding is that Smalltalk was such an attempt but somehow that aspect of it didn't really spread. Are you aware of current progress being made in this area?
Re:Where is Ruby Headed in 2021? by sanderjd on Friday November 19, 2021 @05:33PM (#29283483)
I did that for many years, then I switched to languages with good static analysis and felt really silly about how many years I had wasted wandering around in darkness.
Re:Where is Ruby Headed in 2021? by Raphael on Friday November 19, 2021 @02:11AM (#29274606)
Would a Ruby IDE be able to figure it out?
Re:Where is Ruby Headed in 2021? by t-writescode on Friday November 19, 2021 @02:33AM (#29274739)
In my experience on a IntelliJ with Ruby extensions (so working like RubyMine), no.

Input and output parameters on a program with hundreds of thousands of lines becomes .. rough, to say the least. DryStruct has helped a lot; but several teams working on a single codebase with their own opinions of method calling patterns evolved over several generations all in a single codebase, and it’s … rough.

Re:Where is Ruby Headed in 2021? by sanderjd on Friday November 19, 2021 @05:38PM (#29283534)
RubyMine was impressive (because it's a hard problem) but still hit or miss when I was writing Ruby about 5 years ago. It may very well have improved a lot since then!