6 ms·
Ruby 2.3.0 Released
- dmerrick 11y agoIt's really great to see that with every big release, Ruby is making the language even more pleasant to use in addition to the regular performance improvements. Ruby just keeps getting better and better.
- pwelch 11y agoAgreed. Been using Ruby for a few years now and it never stops being enjoyable. Hoping it keeps going for many more years!
- smegel 11y agoI seriously saw this and thought it might be the reason for the ruby-colored banner. facepalm
- hartator 11y agoWe can say it's for both Christmas and Ruby relesae. :)
- smegel 11y agoThe fact that Christmas is almost over where I am - and I saw the normal banner all day - might explain it :)
- thomasfl 11y agoThe banner is ruby red, so why not.
- steveklabnik 11y agoThis will always work, since Ruby always releases on Christmas. :)
- furfish 11y agoHo ho ho!
- zem 11y agodoh! till I read this I thought hn had simply rolled out a new stylesheet.
- mmahemoff 11y agoNice to see "Did You Mean" suggestions flourishing across various tools now, e.g. Git too. Error messages can be a whole lot more than indecipherable jargon, even for command-line warriors. I'm also looking forward to never writing "if foo && foo.bar" again! Congrats and happy holidays Ruby team :).
- cdcarter 11y agoWell, git's "did you mean" is probably the most frustrating command line experience imaginable, but it's quite nice in a language!
- dmerrick 11y agoIt's the worst when it says something to the effect of "you made a typo, so we already ran this unrelated command for you!" Tip: run the following to add a 1-second pause between the message and the "fixed" command being executed: git config --global help.autocorrect 10
- matthewrudy 11y agoThis is actually a really great release. `&.` removes the really annoying (and slow) `try`. And I think the string literals freezing is going to solve a lot of problems with memory allocations. Check out this PR for Rails that covered a lot of similar performance problems created by too many string allocations. https://github.com/rails/rails/pull/21057/files https://github.com/rails/rails/pull/21057/files I wish Rails 5 could go all in on Ruby 2.3.0 and frozen string literals.
- jrochkind1 11y agoKeep in mind string literal freezing is still off by default. I like that they did it this way, give a chance to see if it actually brings performance improvements in real world scenarios before imposing it on all code.
- matthewrudy 11y agoI've turned it on for all of my projects. But I think the real benefits will always be in framework code.
- anonova 11y agoHow prevalent is `try` in rails/activesupport? My benchmarks show that the lonely operator is ~2x faster than `try`. I'd expect someone to create a gem that monkey patches `try` for those running 2.3.0.
- hueho 11y agoThere isn't really anyway to monkeypatch `try` to use the operator. `try` API is inherently based on metaprogramming (passing a symbol to call), and have different semantics than the operator (by default it won't throw if a non-existent method is called in a non-nil object, while the operator will thrown a NoMethodError) https://github.com/rails/rails/blob/4-2-stable/activesupport/lib/active_support/core_ext/object/try.rb#L62 https://github.com/rails/rails/blob/4-2-stable/activesupport...
- simplyluke 11y ago
- diminish 11y agoDoes lonely operator support safe navigation in case of method calls with params too? obj&.foo(1)&.bar(2)&.zoo
- deleted 11y ago[deleted]
- enkephalin 11y agothis is working just fine: nil&.+(3)&.+(5)&.-(7)
- glasz 11y agonobody noticed the bytecode section?
- nchelluri 11y agoyes. care to elaborate? first thing that came to mind was "APC-style" (https://secure.php.net/manual/en/intro.apc.php https://secure.php.net/manual/en/intro.apc.php) caches. but im not super up on deployment, i thought YARV was already supposed to achieve this.
- cheald 11y agoAPC exists because PHP reloaded source files each time a script was executed through your webserver. No such parallel exists in Ruby; once source files are loaded in a process, they stay loaded for that process. In theory it might allow for faster loading of Ruby code (more analogous to Python's .pyc files), but IIRC early experiments (in the early 2.0 days) showed it to be counterproductive in many cases.
- omarforgotpwd 11y agoAh, YARV finally adds bytecode compilation and loading as an "experimental" feature. It'll be interesting to see what people do with it.
- rubiquity 11y agoI could see it making deployment faster or nicer. Imagine being able to compile all the byte code for a Rails app locally and just shoving that up instead of waiting on bundling and all that. Also I think this would make possible hot code upgrades which are cool but probably more work than their worth. Unless you can build smart hooks into background job and web server libraries that only change the byte code in between jobs and requests. Oh the possibilities!
- rubiquity 11y agoAfter reading the patch that introduced the byte code compilation it seems what I was hoping to use it for are clearly not goals of the project: https://bugs.ruby-lang.org/issues/11788 https://bugs.ruby-lang.org/issues/11788
- pmontra 11y agoI'm not sure the prospects are so bleak. I made some tests and I could run the compiled code on another machine with a different directory structure. See https://ilconnettivo.wordpress.com/2015/12/25/ruby-2-3-0-instructionsequence/ https://ilconnettivo.wordpress.com/2015/12/25/ruby-2-3-0-ins...
- rubiquity 11y agoI was curious just like you and gave this a try too. Seems that while the project is intended for this you can easily build this. Thank you for writing that up!
- MrBra 11y agoAs someone else pointed out, at https://bugs.ruby-lang.org/issues/11788 https://bugs.ruby-lang.org/issues/11788 they explain that: They are not goals of this project: - packing scripts to one package - migrate obfuscate binary to other node to hide source code --- But.. what I don't get is: why wouldn't this works as a cheap way to obfuscate some ruby code? After all, isn't it true that when a script is compiled to byte-code then it is interpreted by the runtime as-is (and without being re-translated to the original script in memory or on disk) ? If so - I understand that rebuilding the original ruby script would not be a big deal for a developer - but wouldn't this still pose a small barrier to the casual prying user?
- waylandsmithers 11y agoInterested to see how people start using safe navigation! I personally tend to avoid `try` in Rails in favor of other `nil` handling patterns.
- hopsoft 11y agoWhy? Genuinely curious.
- chrisseaton 11y ago'try' is relatively slow compared to other control logic, as allowing an exception to be thrown involves constructing an exception stack trace. This is slow in all VMs I know. Theoretically you could detect that the trace isn't used and remove it through escape analysis, but this is not easy, or you could do some crazy thing with lazily creating the stack trace, but that's a research project.
- jrochkind1 11y agoI think you are confused, `try` is not raise/rescue. The ActiveSupport `try` implementation does not involve allowing an exception to be raised. https://github.com/rails/rails/blob/v4.2.5/activesupport/lib/active_support/core_ext/object/try.rb#L69-L80 https://github.com/rails/rails/blob/v4.2.5/activesupport/lib... It should be as performant as other ways of checking for nil/empty.
- chrisseaton 11y agoAh yes you're right - I was confusing this with raise/rescue.
- hopsoft 11y agoI wrote a script to benchmark some of the diff strategies for anyone curious. https://gist.github.com/hopsoft/ae361319c54bbcb4f8e2 https://gist.github.com/hopsoft/ae361319c54bbcb4f8e2
- 11y ago
- shinuza 11y agoFun fact: Ruby 1.0 was released 19 years ago on this day.
- systems 11y agowith the existence of Perl6, Clojure, F#, Rust, Go, and few others ... For someone who doesn’t know Ruby, why learn it today?
- ihsw 11y agoIt's still one of the most terse and transparent languages around, plus there are tons of jobs for working with it. I quite like Go, Python, TypeScript, etc but Ruby is in a league of its own when it comes to short and sweet. It's a pleasure to write.
- jballanc 11y agoFor my money, Ruby comes closest to realizing the "promise" of dynamic languages. That is, it's fast to build with when prototyping, flexible when refactoring, reasonably fast enough and not so memory hungry that it can't handle "web scale". Obviously there are languages that are better in each of these areas, but few that combine so many as well as Ruby. In other words, if you know that you'll be working in a problem domain (e.g. high concurrency) where specific advantages of some other language (e.g. Go/Erlang) are likely to be needed, use that language. If you're just building something, then Ruby's a fine place to start.
- cageface 11y agoThe Rails ecosystem is mature now, which means you can find an off-the-shelf gem to do just about anything you want. So building things in Rails is very very fast. It's hard to beat for MVP-style development.
- deleted 11y ago[deleted]
- nchelluri 11y agoif everything came down to just what you type in the editor (e.g. functionally equivalent programs in any language performed the same everywhere), i would always prefer ruby. it's just a nicer language to use than most, or maybe all others.
- sandstrom 11y ago
- ksec 11y agoAnyone knows if Ruby has accepted IBM's contribution of JIT for Cruby?? https://news.ycombinator.com/item?id=10715610 https://news.ycombinator.com/item?id=10715610 And below is the Presentation from Ko1 on compiling Ruby http://rubykaigi.org/2015/presentations/ko1 http://rubykaigi.org/2015/presentations/ko1
- chrisseaton 11y agoI don't think that will happen for a while, if it does happen. They haven't even released their patch under a compatible licence yet, or their library as open source, for example.
- igravious 11y agoThanks for reposting this. Wonder why it's not making bigger waves. What are the performance numbers of this thing like? I feel this IBM OMR is a reply to MS opening .Net CLR
- magaudet 11y ago(IBMer working on said JIT here) As Chris Seaton points out as well, we're not really open source yet. Working on getting there, but it's going to take time. The important thing now is that we can start talking with the community and making it more likely that when we do get open source, it can happen in a way consumable by the Ruby community.
- edlebert 11y agoI couldn't find any actual examples on how to use the new frozen string literals. Lots of discussion in the link provided, but that's it.
- itafroma 11y agoThe NEWS file defines what the pragma actually is,[1], but you'd use it like so: # frozen_string_literal: true str = 'foo' str << 'bar' This will now produce an error: # main.rb:3:in `<main>': can't modify frozen String (RuntimeError) It's equivalent to Ruby 2.1's String#freeze:[2] str = 'foo'.freeze str << 'bar' # main.rb:2:in `<main>': can't modify frozen String (RuntimeError) Except that it will affect all strings created after the pragma mark. You can also trigger this behavior globally with the --enable=frozen-string-literal option. [1]: https://github.com/ruby/ruby/blob/v2_3_0/NEWS#L17-L26 https://github.com/ruby/ruby/blob/v2_3_0/NEWS#L17-L26 [2]: http://ruby-doc.org/core-2.2.3/Object.html#method-i-freeze http://ruby-doc.org/core-2.2.3/Object.html#method-i-freeze
- r-s 11y agoLooks like some nice additions. I try to limit the use of .try in rails, however when working with legacy codebases it is much nicer then: if @user && @user.address && @user.address.city city = @user.address.city end Even though I write less Ruby then I once did, I still credit it as the language which shaped my career the most. I have worked so many great jobs because of Ruby.
- gkop 11y agoYup. In addition to the general purpose safe navigation operator we also have Hash#dig now which helps with those pesky nested params: params.dig(:user, :address, :city)
- igouy 11y agoruby-2.3.0.tar.bz2 does not seem to have /ruby-2.3.0/bin/ruby ?
- DevKoala 11y agoI love '&.' I really missed this feature from C# 6.0
- singularity2001 11y agoHere are two bash functions so that you can compile and execute the bytecode in the terminal: i.e. rubyc test.rb ruby-do test.rbc in .bashrc: function rubyc() { ruby -e "File.open('$1c', 'wb').write(RubyVM::InstructionSequence.compile_file('$1').to_binary)" } function ruby-do() { ruby -e "RubyVM::InstructionSequence.load_from_binary(File.open('$1', 'rb').read).eval" }