7 ms·
Unveiling the big leap in Ruby 3.3's IRB
- heads 3y agoIt’s cool to see code in an interpreted language being edited at the repl. Ruby’s style of building everything at runtime using the language itself has always felt delightfully consistent, but also very hard to reason about with static analysis — the usually tool for helping developers in their IDEa and LSP clients. Far nicer to just execute the program and put a breakpoint at the cursor… COLORS.each{ |c| define_sheep_class(c) } sheep1 = Sheep::Bl| This feels like the only way my editor stands a chance of completing this to Sheep::Black. Is this how Ruby IDE support works (e.g. in the JetBrains product.)
- djur 3y agoIt's too dangerous to execute the code to provide completion support. IDE support has to rely on static analysis.
- heads 3y agoI suppose you could run the unit test suite?
- dpassens 3y agoNo, you couldn't. If running the code is too dangerous, then so is running the unit test suite. You'd have to prove that it doesn't do anything observable, like accidentally deleting your home directory, or, if the code is actively malicious, uploading your SSH key somewhere. And if you can do that, you probably also have enough information to provide good completion without running the code.
- vidarh 3y agoYou can get quite far by symbolic evaluation of a fairly small subset of Ruby - the most common patterns used use a fairly small number of methods. Frankly I think not going further is a good thing in that it'll discourage people from going unnecessarily far with the dynamic features.
- deleted 3y ago[deleted]
- lbrito 3y agoSeems like this could replace pry and byebug very well. Nice!
- vr46 3y agoI’m a version away from current events and playing catch up, hoping that these new improvements can replace pry!
- awwaiid 3y agoI love pry+byebug so much that I'm having a hard time wrapping my head around why I might want to replace them with this. I guess for a marginally more out-of-the-box and universally available tool, eh? I'll have to look into the extensibility aspects.
- chucke 3y agoPry and byebug paved the way in a lot of ways for this work, but they break in fundamental ways across a range of use cases, such as multithreading, multifiber, or quirk around exception handling. While these are all fixable, so we're the lack of standard quality tooling , which is quietly being addressed by irb and debug gems.
- lbrito 3y agoByebug and pry are pretty much the first gems I add to any gemfile. But like the other comment said, they break in a few ways that this new irb seems not to. One thing I can think of is multi line statements (on Byebug). Really annoying to test longer method chains. Would love a debugger that supports it out of the box, as the new irb seems to do.
- block_dagger 3y agoRemoving two external dependencies from your project is a nice win. I switched a while back. Get used to "binding.irb" and you'll thank yourself later.
- ryanseys 3y agoIRB type completion comes as a result of a chain of events which starts from the incredible work done by Kevin Newton (et al) to write a new canonical Ruby parser called Prism in C99 with no dependencies [1]. With Prism, you can then create tool suites like syntax_tree [2], which then leads Prettier formatters [3], a new Ruby LSP [4], which unlocks a new Ruby LSP VS Code extension [5], not to mention a laundry list of other gems like Rubocop and of course Ruby itself that will benefit from a faster and more maintainable Ruby parser. It's a beautiful illustration of the power of questioning conventions, going back to first principles to uncover better solutions to previously solved problems, whose new solutions create new capabilities which unlocks the ability to solve new problems. [1]: https://github.com/ruby/prism https://github.com/ruby/prism [2]: https://github.com/ruby-syntax-tree/syntax_tree https://github.com/ruby-syntax-tree/syntax_tree [3]: https://github.com/prettier/plugin-ruby https://github.com/prettier/plugin-ruby [4]: https://github.com/Shopify/ruby-lsp https://github.com/Shopify/ruby-lsp [5]: https://marketplace.visualstudio.com/items?itemName=Shopify.ruby-lsp https://marketplace.visualstudio.com/items?itemName=Shopify....
- boundlessdreamz 3y agoDidn't syntax_tree come before Prism?
- st0012 3y agosyntax_tree was actually created before Prism. Ruby LSP also adopted syntax_tree first, and then switched to Prism (then called YARP) when it was mature enough. But indeed, the type completor would've been much harder to build and maintain if without Prism.
- ryanseys 3y agoGood correction! My apologies.
- stjohnswarts 3y agoI really wish ruby would have become the biggest scripting language rather than python.
- nickhodge 3y ago... and JavaScript
- Falmarri 3y agoGross. Python is a million times better than ruby to read and write
- qup 3y agoI believe that'll be a minority opinion. I'm a fan of both languages.
- nurettin 3y agoThe opinion is blown out of proportion, but there is a hint of truth. Large python projects are indeed easier to follow simply because of type annotations and signatures. Of course a lot of projects don't follow type conventions and try to invent their own optional parameter syntax using dictionaries and keyword expansion syntax, so the problem still exists everywhere.
- mwgalloway 3y agoRuby has RBS and sorbet to support using type annotations. They are each relatively new and aren’t as clean and well integrated as Python’s implementation, but it’s not as if type annotations in Ruby don’t exist.
- bhaak 3y agoIt does exist but they are not embraced by the majority of the Ruby community. Unless type annotations are treated like first class citizen in the language, it won't be good enough. My theory is that those in the community wanting static types went to Go or Rust.
- buf 3y agoAm I the only one who never actually types in IRB? I edit directly inside my code and use tmux's send-to-pane to send my current line(s) to IRB. Ex: https://cln.sh/xXNlf51m https://cln.sh/xXNlf51m
- w-ll 3y agoYea im confused. I use IRB all the time to test some one off stuff, and !reload. but im not editing in the IRB or docker container on the proxmox vm for locacl dev.
- freedomben 3y agoSame although vim with vim-slime
- whateveracct 3y agoYou're missing out on the real REPL experience if so!
- nomilk 3y ago> In Ruby 3.1, IRB introduced the autocompletion feature. While it has proven to be a useful feature for many users, it also came with some issues that were hard to overlook <lists several> Really appreciate the attention to detail. I know little of ruby's internals, so usability flaws like those mentioned are difficult to put into google and try to fix (some usability hiccups are not due to bugs but due to misconfigurations - i.e. something I've set up incorrectly). These little quality of life improvements make a world of difference when using IRB for hours to get stuff done. Thank you to all those that make ruby awesome!
- block_dagger 3y ago> we plan to provide official APIs and relevant documentation to help libraries and applications extend IRB Bravo Ruby team!
- aviandnuskii 3y agoThis is so cool. I have been trying to replace the default history lookup in irb with fzf but have not found a clear path to do so. Maybe the irb team can also make it easier to do this.
- dasl 3y agoThis allows you to use fzf with IRB. It works with anything that uses readline, which IRB uses. https://github.com/lincheney/rl_custom_isearch https://github.com/lincheney/rl_custom_isearch it works for me on linux, not sure about other OS's. Although I'm now noticing that the article linked in the original post says that Ruby has a pure Ruby replacement for readline: Reline. So I wonder if it will not work with more recent versions of Ruby that use Reline?
- aviandnuskii 3y agoThanks. I'll check this out
- codesnik 3y agoI still wonder what are the reasons to steal some features from "pry" instead of just adopting pry itself.
- vr46 3y agoI think Pry is EOL, last time I checked, and wasn’t getting much help either.
- vitiral 3y agoReading "big features" like "multi line input" makes me feel more than ever that we really need an ultra light weight embeddedable text editor. I wrote one, and while it's not yet complete I can say it's really _not that hard_ https://github.com/civboot/civlua/blob/main/ele/README.md https://github.com/civboot/civlua/blob/main/ele/README.md
- vidarh 3y agoYou can use whichever editor you prefer from irb with an extension (might be builtin now? I mostly use pry, which respects $EDITOR) - the last thing I'd want would be an editor forced on me. The multi line input is for the really trivial stuff.
- cdcarter 3y agoI spent many hours (back in the 1.8 days) in a Ruby focused irc chat room with some guys, many who went on to found relatively interesting companies (hey Evan and Chris :) ). I was just a teen, Rails was huge, and _why was writing some of the most inspiring code of all time. At the time, to inspect what you could do with an instance, I wrote `my_thing.methods.sort - Object.new.methods.sort` many a time. It's great to see features making IRB even better after all these years.