16 ms·
Ruby 3.0 Preview 1
- riffraff 6y agothe link to the NEWS file is broken, it should be this https://github.com/ruby/ruby/blob/v3_0_0_preview1/NEWS.md https://github.com/ruby/ruby/blob/v3_0_0_preview1/NEWS.md
- desireco42 6y agoThere were times where I would not be able to sleep when such a release was done :). It isn't as much lately, but still, fantastic work by fantastic team. Congratulations! There are some seriously good stuff there.
- Justsignedup 6y agoReactor model. Nice. Very nice. So real ruby multithreading at last. Okay time to upgrade to latest rails and wait for the multithreaded rails release. :P
- sosodev 6y agoI suspect it will be quite a while before we see Ractor being used in Rails. Ractor is very strict about data isolation to prevent race conditions and existing code will need significant refactoring.
- dorianmariefr 6y agopuma, the default webserver when using rails, is most-likely what would be using ractors
- sosodev 6y agoHere's schneems, a Puma maintainer, talking about Ractor, Rails, and Puma https://old.reddit.com/r/ruby/comments/ivasiq/we_made_puma_faster_with_sleep_sort/g5qx59n/ https://old.reddit.com/r/ruby/comments/ivasiq/we_made_puma_f...
- jacobvosmaer 6y ago>The biggest issue with ractor support as it stands today would really be getting ALL the libraries any given app uses to support the ractor design. I wonder if this will create a chicken-egg situation. Without significant Ractor adoption it will be hard to get libraries to adapt. Without essential pieces like Puma supporting (and benefiting from) Ractor there is less reason to for apps to use Ractor. I am reminded of the difficulties faced by Rubinius, which if I understand correctly, was hampered by too many MRI-compatible libraries not working to get people to switch.
- sosodev 6y agoI imagine getting wide support for Ractor will be easier than Rubinius and other async Ruby attempts since it’s actually part of the core language.
- joelbluminator 6y agoI don't understand what you mean by "real multithreading". What I understand from Ractor is that it makes it safer to write concurrent code (e.g there are constructs that keep you from mutating shared data). But there is still a global VM lock, or is that gone in Ractor?
- lucraft 6y agoI believe the VM lock is now per-ractor, so no longer global no. Then there are constraints on what can be shared between ractors to ensure safety.
- juliend2 6y agoHappy to see developments on the pattern matching feature[0]. [0] https://bugs.ruby-lang.org/issues/16828 https://bugs.ruby-lang.org/issues/16828
- stevebmark 6y agoI really wish Ruby would grow up and deprecate method_missing
- whitepoplar 6y agoWhat's wrong with it?
- sigzero 6y agoNothing. There is nothing wrong with it at all except he "doesn't like" it.
- samgranieri 6y agoWhy? method_missing is one of the fun features of the language
- chrisseaton 6y ago> I really wish Ruby would grow up and deprecate method_missing method_missing is a deliberate and principled part of a message-passing approach to object orientated programming that gives you powerful options for composition and delegation. You can say you don't prefer this style of programming, but it's not well-informed to say it's down to immaturity or ignorance of alternatives on their part.
- choward 6y agoWhat do you mean by "powerful". Meaning you can type less code. You can still do delegation by writing it out yourself. Or you can also use the Delegator or Forwardable classes to save some typing. I'm not sure what meta programming they use under the hood. Probably define_method or method_missing. Also, people always forget to throw NotImplemented errors which can lead to some fun to track down bugs if you make a typo sending a message. Which I guess is why you pretty much have to write tests for everything in ruby. This kind of stuff would be caught by a compiler in other languages. Disclaimer: I don't buy into the idea of "message passing" or a lot of OOP. They're the microservices of programming languages.
- Jarred 6y agoDoes message passing mean it copies objects you send between threads / fibers, rather than sharing memory? JavaScript has a similar pattern with Workers, and it makes concurrency for hot code impractical. Serializing/deserializing objects is a lot slower than just not doing that. In JavaScript’s case, you can also use SharedArrayBuffer, but Safari hasn’t re-enabled it.
- kevincox 6y agoIIUC Yes. Although there are some cases where it can share immutable objects or pass ownership. However you can always just open a shared memory region and write bytes back and forth. You don't get ruby types but if you are worried about performance that probably isn't much of a concern.
- shadykiller 6y agoI love Ruby and great to see Ruby love on hacker news. Just curious on how popular it is in the hacker news community ?
- chrisseaton 6y ago> Just curious on how popular it is in the hacker news community ? Seems to be well represented by successful companies here. https://www.ycombinator.com/topcompanies/ https://www.ycombinator.com/topcompanies/
- koffiezet 6y agoI only ever tried out a rails tutorial once, and coming from a C/C++ background, but having used with many languages, too many things felt like magic back then, but no further experience with the language itself, so can’t really judge it. However, now I’m on the operational side of things, and there are 2 types of applications I avoid to deploy/maintain, mainly because of their runtime: Java and Ruby apps. It’s very likely the Ruby runtime has improved, but we actually set up a haproxy with multiple instances of the same ruby app, which we just restarted every 2 hours, just to keep it running properly. Upgrading ruby back-then was a mess, and could break a lot of things. I can’t comment on the language itself, but the runtime left a very bad impression. I since then (4/5 years ago or so) have successfully avoided ruby, so it’s possible things have improved, but first impressions last...
- Glyptodon 6y agoI wouldn't call Ruby a high performance language, but your experience seems weird. Even four or five years ago I would consider Ruby one of the most painless languages for dealing with upgrades and new versions of things: install ruby with a version management tool, install your app from gemfile, run your tests, good to go. I regard it at one of the first languages to have effective tools for dealing with versioning and upgrades. I still find it easier to deal with than Python by a solid amount.
- theonemind 6y agoReminds me of http://harmful.cat-v.org/software/ruby/rails/is-a-ghetto http://harmful.cat-v.org/software/ruby/rails/is-a-ghetto . "The main Rails application that DHH created required restarting ~400 times/day. That’s a production application that can’t stay up for more than 4 minutes on average." Not that Ruby = rails
- d2161 6y agoYou can test your heroku app on the new ruby 3 preview already! (https://devcenter.heroku.com/changelog-items/1889 https://devcenter.heroku.com/changelog-items/1889)
- faitswulff 6y agoI was just looking for this a few days ago. Thanks!
- reader_mode 6y ago>Rightward assignment statement is added. >fib(10) => x This is exactly the kind of stuff I hated when I had to work with ruby in my last gig and why I will never accept a job using it again - soo many pointless and inconsistent ways to do the same thing ... they have method aliases for collection operations like map/filter in standard library ! .NET went with non-standard SQL-like names (select/where) and I'm not a fan but at least they made their choice and stuck with it. And it's inconsistent all over the place - like '!' postfix means "operation mutates the object" in std lib BUT in rails it means the operation will raise an exception and not return an error code. Now they add a pointless operator that means completely different thing in other languages to throw off even more people. It's just a hell of a language to maintain someone else's code in.
- JohnBooty 6y agoI love Ruby, but I agree with you about disliking that kind of thing. I've done Ruby since 2014 or so at a few shops. My general anecdotal experience: - Lone Ruby coders often use a lot of that cutesy/obscure/dense stuff. - Teams of people writing Ruby, with healthy code review practices, tend to value simple, easy-to-read Ruby. - A lot of Popular Ruby gems (and projects at aforementioned Ruby shops) have Rubocop-based style guides. Rubocop has some very strict ideas about Ruby coding style. The defaults are mostly quite sane and it's easy to disable/customize the ones you disagree with. Not making excuses for some of the more florid parts of Ruby's syntax and stdlib, but in practice I do find things are manageable!
- wrp 6y agoRuby has been referred to as Smalltalk meets Perl, and the problem of dealing with other people's code is one of the main things that kept me in the past from using Perl on text processing projects. The problem of collaborating in Perl was lessened a lot by adhering to Damian Conway's Perl Best Practices. Is there anything similar for Ruby?
- burlesona 6y agoRubocop and you're done. It's the first thing I'd add to any team project just because life's too short for an inconsistent codebase.
- zelly 6y agoSo now there are basically no dynamically typed languages left. There's Scheme, JavaScript, what else? All languages nowadays are converging to TypeScript/Rust. It's kind of sad.
- loktarogar 6y agoRBS is optional.
- zelly 6y agoIt won't be optional in Ruby 4, most likely.
- Daishiman 6y agoWhy would you think that? There's no evidence that dynamic typing is going away Type hints are optional precisely because they're not convenient for many cases, and the add-on type systems cannot fully express the capabilities of the language.
- grumple 6y agoSeems unlikely. Ruby is all about options.
- nindalf 6y agoI wish I could predict the future with as much certainty as you.
- joelbluminator 6y agoYeah, I second the opinion that this remains optional. Ruby won't become a java-wannabe , that's a fight it cannot and would not want to win. Ruby is dynamic.
- volkk 6y agowhat do you mean? you can certainly use vanilla javascript if you really want, same with ruby. its not like types are forced down your throat
- sdwolfz 6y agoMy thoughts: - RBS: meh... might get more useful in the future (in 2-5 years maybe). - Ractor: Wohooo! I'm writing a DAG library where I was thinking of implementing something like this, good to know I can use it and get real parallelism on top. - Scheduler: :shrug: don't know about this one, might be relevant with future concurrent ruby code, any ideas? - Rightward assignment: it's a bit awkward but I see the use case, just wish we had the pipe operator too like in Elixir. - Endless method: this one is cute, I love it! - Find pattern: oh boy, code reviews are going to be interesting now! - Hash#except: yes, definitely a welcome one. - Memory view: if this helps with numpy style gems it will be great! - `send(:"do_#{ meth }", ...)`: don't do meth kids! (it's a joke!)... seems like a reasonable feature. - `order of backtrace had been reversed`: good! it was confusing... - Promote default gems to bundled gems (rexml): I like this one, if only nokogiri was a stdlib gem or part of core, imagine how much time would be saved instead of having to compile it every time in a `bundle install`. - `Promote stdlib to default gems`: what does this mean? Do I now have to add `gem "securerandom"` to Gemfiles instead of having it by default and just needing to require it? - Mjit improvements: can't wait to try it! Overall, I'm delighted!
- djur 6y ago"Default gems" means that they're packaged as a gem but always implicitly available, as if you had included them in your Gemfile. "Bundled gems" means the same thing, but you do have to include them in your Gemfile. https://github.com/janlelis/stdgems#about-the-gemified-standard-library https://github.com/janlelis/stdgems#about-the-gemified-stand...
- sdwolfz 6y agoThank you for clarifying this for me. In that case, the rexml gem situation sounds like a demotion...
- UncleOxidant 6y ago> - Endless method: this one is cute, I love it! It's a weird name for it. It should probably be called something like 'equational method definitions'
- eddietejeda 6y agoIf you interested in seeing how the 3x3 initiative* has come along, here are the benchmarks so far: https://github.com/mame/optcarrot#readme https://github.com/mame/optcarrot#readme Personally, I am very excited for this release. * Matz's goal to get Ruby 3 to be 3x faster than Ruby 2. -- @sosodev Thanks for the updated info!
- sosodev 6y agoThat README isn’t up to date. The benchmark has seen significant performance improvements since then. https://benchmark-driver.github.io/benchmarks/optcarrot/commits.html https://benchmark-driver.github.io/benchmarks/optcarrot/comm...
- czbond 6y agoI have been out of the ecosystem for a while, but use Ruby frequently. So the 3x3 is coming along? More up to date places I could see benchmarks or similar? Note: I have been using Roda with Ruby 2 and it is pretty fast. Can't wait to see what it would be with 3x3.
- thatguyagain 6y agoThis might be a bit of a novice question, but will this affect the initializations of ActiveRecord objects in Rails anything? For example, processing a large CSV file and inserting new rows in a database from it has always been extremely slow using Ruby/Rails unless you basically just write raw SQL that copies from the CSV and don't do any initializations of Rails models, #create, etc. I wonder if this will improve these things at all, but my guess is that it has to do with memory usage and not the speed of Ruby?
- jasonhansel 6y agoQuestion: will the nonblocking scheduler start to make Ruby concurrency competitive with e.g. Node.js and Go? Currently Ruby mostly uses heavyweight threading mechanisms that cause trouble for I/O-bound microservices.
- sosodev 6y agoIn theory the scheduler should be similar to NodeJS and Ractor should be similar to Go if they’re both applied correctly.
- cutler 6y agoReally? Can you point me to details supporting this?
- sosodev 6y agoFalcon, an async Ruby webserver, is a good example of scaling Ruby with fiber scheduling https://www.codeotaku.com/journal/2018-06/improving-ruby-concurrency/index#performance https://www.codeotaku.com/journal/2018-06/improving-ruby-con... I'm not sure if Ractor has any real benchmarks yet but it enables genuine parallel Ruby code that communicates through message passing without too much overhead.
- nesarkvechnep 6y agoIsn't Ractor based on the Actor model and not CSP?
- sosodev 6y agoRactor is "actor-like" and looks a bit like a mix of both Elixir/Erlang and Go.
- dmix 6y agoIndeed, anyone who has used actors IRL projects it goes well beyond just isolation and message passing. That’s just the foundation which higher abstractions are built, which is why it’s still comparable to Go/CSP at this level.
- jakearmitage 6y agoEndless Ruby is the best Ruby.
- sickcodebruh 6y agoDidn’t see it linked in the preview announcement, here’s the RBS syntax guide: https://github.com/ruby/rbs/blob/master/docs/syntax.md https://github.com/ruby/rbs/blob/master/docs/syntax.md Glanced at it from my phone but it looks good! I’m looking forward to seeing it in RubyMine. Still sad that we can’t write these in .rb files but I wonder if the plan is to go the other way, eventually permit typed code in .rbs? Does anyone know what the story will be with third-party definitions? Are we headed towards a DefinitelyTyped style repository for Ruby?
- sosodev 6y agoIt seems like the intent is for RBS to be auto generated from other tooling. Sorbet for example lets you write inline type definitions and is planned to fully integrate with RBS. The other good thing about RBS being in separate files is it can be integrated into a library without breaking compatibility with older Ruby versions.
- sandstrom 6y agoI wish they'd allow both external RBS files and inline markup.
- rco8786 6y agoThis is all great stuff. I’m rather meh on RBS, mainly because separating types from code is less than ideal but I like the potential here. But the right hand assignment operator. What on earth. Nobody asked for that and nobody wants it. Why.
- djur 6y agoWhat's strange is that it seems to have been an offshoot of the pipeline operator (|>) work from last year[1], which was originally proposed as having an assignment syntax like foo |> bar(20) |> (x) where x is assigned to. People didn't like that syntax, and there were issues with = being higher precedence than |> [2]. This new right-assignment operator was created in response to that [3]. The weird thing is that the pipeline operator got killed, so the original reason for r-assign no longer exists. It looks to me like there's just some people on the Ruby team who took a shine to it. [1]: https://bugs.ruby-lang.org/issues/15799 https://bugs.ruby-lang.org/issues/15799 [2]: https://bugs.ruby-lang.org/issues/15799#note-22 https://bugs.ruby-lang.org/issues/15799#note-22 [3]: https://bugs.ruby-lang.org/issues/15921 https://bugs.ruby-lang.org/issues/15921
- burlesona 6y agoThe examples given were all things that would be nice to do in the REPL. What I don’t understand is why not just define it in the repl, then, like ‘_’.
- jaynetics 6y agoBecause changing or pre-processing the language syntax is far beyond the scope of any REPL. Assigning the latest return value to a variable named '_' is very straightforward and does not require dealing with the syntax.
- inopinatus 6y agoRuby already had a sort of limited form of rightward assignment, in exception rescue: begin #... do something rescue StandardError => ex #... handle exception end The ex here can be any assignment expression, it's not just a lexical variable. So you could already do this: class Guru def meditate=(exception) puts "caught #{exception.inspect}" end end # later ... rescue OutOfCheeseError => Guru.new.meditate i.e. creating a nice opportunity for passing error handlers around as an argument; or, this worrying idea: rescue TransactionError => Thread.current[:exception] and now I'm afraid you can do this: Cat = Struct.new(:name) do class << self def all() = @all ||= Set.new def adopt=(...) all << new(...) end end end "Astrid" => Cat.adopt
- monadic2 6y agoRuby is a really cool language but I'm dying for an update where features are removed.
- choward 6y agoThen Ruby isn't your language. There are a million ways to do everything by design. It's so you can make your code look pretty (or as they like to say "expressive") for whatever you interpretation of that means. It's one of the things that made me stop using it for most things.
- riffraff 6y ago$SAFE was removed in this one :)
- Lordarminius 6y agoThe language is just becoming needlessly (?) complex. I'll stick to writing my code in --version 2.7 for the foreseeable future
- pw 6y agoWondering how RBS will compete/compare to Sorbet, which seems like a better solution.
- riffraff 6y agosorbet will support RBS as an alternative typing input. https://sorbet.org/blog/2020/07/30/ruby-3-rbs-sorbet https://sorbet.org/blog/2020/07/30/ruby-3-rbs-sorbet
- aryik 6y agoGreat stuff! Does anyone who’s been in the Ruby ecosystem longer than me have a prediction for when Rails will support Ruby 3?
- wbharding 6y agoIt looks like the link they provide for comparing the source of 3.0 and 2.7 is busted on Github, but you can get a sense for the scope of this on GitClear's Open Repos https://www.gitclear.com/open_repos/ruby/ruby/releases https://www.gitclear.com/open_repos/ruby/ruby/releases. Looks like about 4x more repo evolution has gone into this version than previous. See also: list of the biggest tickets tackled in 3.0: https://www.gitclear.com/open_repos/ruby/ruby/release/pending_release https://www.gitclear.com/open_repos/ruby/ruby/release/pendin...
- cutler 6y agoMuch as I would love to believe Ruby 3.0 delivers some kind of speed bump my simple test of doing what Ruby supposedly does best - parsing a log file with a regex - shows Ruby 16% slower than the Python equivalent. Ruby puts IO.foreach('logs1.txt').grep /\b\w{15}\b/ Python from re import compile with open('logs1.txt', 'r') as fh: regex = compile(r'\b\w{15}\b') for line in fh: if regex.search(line): print(line, end='') On my MacBook Pro (2013) running Catalina Ruby averaged 1.49 secs and Python 1.27 secs. The file `logs1.txt` is a 20Mb Apache log file. Pre-compilation with: reg = Regex.compile /\b\w{15}\b/ puts IO.foreach('logs1.txt').grep reg ... slowed Ruby down to 1.57 secs. Using --jit didn't change Ruby's overall time but considering it adds 700ms to Ruby's startup time execution time was faster.
- karmakaze 6y agoThe programs aren't doing the same things. The Ruby one seems to buffer the matches into a huge string then print. Don't know how different it would be but better to compare apples.
- riffraff 6y agoProbably the equivalent thing to test would be regexp = /\b\w{15}\b/ IO.foreach('logs1.txt') do |line| puts line if regexp.match?(line) end I imagine this will in both cases mostly be testing the computer's IO. Regexp.compile doesn't do anything substantially different from Regexp.new or a literal (i.e. it doesn't optimize the regular expression or something) so I think the difference is just random fluctuations.
- deleted 6y ago[deleted]
- cutler 6y agoIO.foreach without a block returns an enumerator.
- cutler 6y ago
- bilekas 6y agoAm I alone in saying; for some damn reason, I don't like Ruby.. I appreciate what it can do, and indeed what it does.. I just feel like I slipped in between that moment to appreciate it more. I will go and spend some time to learn it more but out of a novelty aspect.. And that makes me feel bad.
- Glyptodon 6y agoI find it more productive, intuitive, and painless than the major scripting languages (PHP, JS, Python...), but it's definitely a bit different and less popular (given Python and JS are insanely popular).
- joelbluminator 6y agoNo you're not alone, it's (surprisingly, to me) one of the more controversial languages. I love it. Lot's of people don't. These things are subjective, we don't all have the exact same brains and life experiences, us humans appreciate different things and that's fine.
- justinzollars 6y agoRightward assignment looks gross.
- hexbinencoded 6y agoI left Ruby because the performance and security weren't improving and the community was slowly dying. I delved into Go before that got flooded with newbs, then looked at Crystal and Pony, before settling on Rust and Haskell for most things.
- shawxe 6y agoI see comments like this often and I find them deeply confusing. To me, it seems like most of the different programming/scripting languages you've listed excel at completely different things. I would be curious to hear what type of work you're doing where all of these languages have been, in some form or another, appropriate.
- nurettin 6y agoHow do you choose all this? I haven't been able to make a single decision for what language to use at work for the past 15 years. I thought wouldn't touch C#, ruby, delphi, kotlin and python but it all happened because someone was paying.
- vivab0rg 6y ago> I haven't been able to make a single decision for what language to use at work for the past 15 years. Hello PHP.
- joelbluminator 6y agoIn 5 years I bet you'd "settle" into some other new shiny language with "better" everything. There'll be a more right tool for the job. Nothing wrong with that mentality, I just prefer to settle with my tool of choice and call it a career.
- gorgoiler 6y agoIt feels like RBS is for library writers, so that they can ship type information to help the consumers of their library. It’s not really aimed at the consumers themselves — the long tail of casual Ruby hackers like me. If RBS was for end users, adding types inline with the source code would make more sense compared to the RBS approach: keeping the source file and typedef file in sync. That might actually be a pretty smart move. At first it seemed inconvenient to have to maintain a separate file for the type information, but maybe this focus on type-checking being made easy for the 90% of us who hack scripts is a much smarter one.
- schneems 6y agoI don’t think anyone expects you to maintain two files. The idea is that RBS is an interface that is tooling agnostic. The idea is to have tooling (sorbet, etc.) generate those files for you.
- wildchild 6y agobullshit.
- phaedryx 6y agoI have mixed feelings. I'm not a fan of rightward assignment because I don't see much value and now the => operator has even more meanings. I'm not a fan of endless methods because how lazy do you have to be to not want to type 'end'? My editor does it for me automatically. Now there is even more parsing.
- dmix 6y agoJS has already adopted the endless style and it’s obvious when to use it and where a single line adds needless complexity. It’s really an overrated barrier to entry with a high return value in code simplicity (particularly aesthetically, which goes a long way with Ruby). I have no comment on the rightward bit though. That is more... radical. Until I see how it is adopted generally.
- levi0214 6y agoCompletely unnecessary syntax. It does nothing but add complexity.
- phplovesong 6y agoLook like a great release! Have not used Ruby in years, but i recon the Ractor and Scheduler brings some nice perf improvements.
- sarfraaz 6y agoI don't know why am I writing this, but..
- aitchnyu 6y agoNot a Rubyist. Would Ractor allow one process to use up all CPUs while avoiding copying objects? Can I build shareable objects with immutable lists and maps right now?
- sosodev 6y agoYes, Ractor allows you to share fully immutable objects. So you can freeze an array or hash and share it as long as it doesn’t contain any references to mutable objects.
- crb002 6y agoI wish I had kept maintaining my port of Ruby to the IBM BLue Gene/L, "Blue Ruby". It scaled to millions of cores with MPI. Had distributed versions of familiar Ruby data types. There was no fork() - restriction of the BGL kernel not supporting it - only green threads - making parallel operations truly parallel with independent Ruby VMs and passing code to data instead of data to code.
- nanna 6y agoAnyone got suggestions for resources to learn Ruby and Rails in 2020?