News for hackers. Stuff that matters.
Re:What's New in Ruby 2.1 [pdf] by dylandrop on Wednesday November 27, 2013 @12:32PM (#6809605)
Can someone explain the "write barrier" stuff? It's hard to glean what the problem is that they're solving here... And what they're saying about Arrays, Strings, Hash, etc, in relation to WB protected vs. WB unprotected.
Re:What's New in Ruby 2.1 [pdf] by matsadler on Wednesday November 27, 2013 @05:14PM (#6811523)
I've not read the code, so someone may have to correct me, but I think this is the gist of it:

Ruby 2.1 introduces a generational garbage collector, this divides all objects into young and old generations. A regular GC run will only look at the young generation, with the old being collected less frequently. An object is promoted to the old generation when it survives a young generation run.

If you have objects in the old generation referring objects in the young generation, but you're only looking at the young generation it may seem like an object doesn't have any references, and you might incorrectly GC an in-use object. Write barriers prevent this by adding old generation objects to a 'remember set' when they are modified to refer to a young generation object (eg old_array.push(young_string)). This 'remember set' is then taken in to account when collecting the young generation.

Most generational garbage collectors need these write barriers on all objects, but with the many 3rd party C extensions available for Ruby this isn't possible, so a workaround was devised whereby objects that aren't write barrier protected won't ever be promoted to the old generation. This isn't ideal as you won't get the full benefit of the generational GC, but it does maximise backwards compatibility.

Re:What's New in Ruby 2.1 [pdf] by danso on Wednesday November 27, 2013 @11:44AM (#6809181)
Everytime I read a Ruby version announcement/explanation, it reminds me that I've been a coder working and thinking exclusively in English, but my current programming language of choice is prominently steered by non-English speakers...and somehow things work pretty peachy. But it always makes me wonder how much more in-depth and richer the discussion of Ruby amongst its Japanese maintainers, before they translate it for us in English?
Re:What's New in Ruby 2.1 [pdf] by steveklabnik on Wednesday November 27, 2013 @04:26PM (#6811256)
You can subscribe to ruby-dev and find out. ;) It's actually much more low-traffic than ruby-core, and someone has volunteered to translate any email if you ask.
Re:What's New in Ruby 2.1 [pdf] by conorh on Wednesday November 27, 2013 @10:24AM (#6808501)
I really like the ObjectSpace.trace_object_allocations addition. I had a quick look at the 2.1 docs for ObjectSpace and there seem to be all sorts of interesting methods in there reachable_objects_from(obj) and memsize_of(obj) for example. It looks like understanding memory usage and tracking down memory leaks will get a lot easier with 2.1.

http://ruby-doc.org/stdlib-2.1.0/libdoc/objspace/rdoc/Object...

Re:What's New in Ruby 2.1 [pdf] by matsadler on Wednesday November 27, 2013 @11:16AM (#6808902)
#reachable_objects_from was added in 2.0, and I think #memsize_of was introduced in one of the 1.9 releases. The documentation is new though.

I wrote a little about them here: http://globaldev.co.uk/2013/03/ruby-2-0-0-in-detail/#id6

Re:What's New in Ruby 2.1 [pdf] by conorh on Wednesday November 27, 2013 @01:54PM (#6810238)
Ah nice, thanks, missed the part about requiring "objspace" to mix them in and assumed they would be on the already existing ObjectSpace module.
Re:What's New in Ruby 2.1 [pdf] by thinkbohemian on Wednesday November 27, 2013 @11:49AM (#6809222)
Koichi is gives some of the best presentations. It is hard enough to be funny in one language, yet to be funny and understandable in two is quite an accomplishment. If you're ever at a Rubyconf, go to his talks. Also love the speed work he's been doing with generational GC. For a primer, Pat Shaughnessy has a great talk you should check out, also Ruby Under a Microscope is a good dive into Ruby.
Re:What's New in Ruby 2.1 [pdf] by Slackwise on Wednesday November 27, 2013 @02:22PM (#6810433)
I'm uncertain why they've added an `f` suffix for frozen string literals/instantiation.

I can understand needing to freeze an existing String, but you can do that with Object#freeze, but a literal syntax seems to overlap with the usage of Symbols. The only benefit I can think of is not needing to use Symbol#to_s when working alongside strings.

I'm not saying frozen strings are not useful, because they can be after taking in some input/params to work with/store, but a literal syntax seems extremely edge-case-y. Now instead of "foo".freeze it's "foo"f, but how frequently will that save you time/trouble?

The bigger implication is that slides 23/24 shows that immutable strings and symbols will share their heap locations, if I'm reading the diagrams correctly, but have different object_ids.

This seems a bit bewildering and focused on micro-optimization, which is not the mental model I have in mind when I'm coding in a very high level language. It's also blurring the semantic difference between Symbols and Strings.

Re:What's New in Ruby 2.1 [pdf] by jhawthorn on Wednesday November 27, 2013 @02:59PM (#6810687)
The f suffix has been removed in favour of the existing "foo".freeze (which is now recognized and optimized in the parser)

https://www.ruby-lang.org/en/news/2013/11/22/ruby-2-1-0-prev...

https://bugs.ruby-lang.org/issues/9042

Re:What's New in Ruby 2.1 [pdf] by Slackwise on Wednesday November 27, 2013 @03:22PM (#6810856)
That clears up the semantic similarity issue for me nicely. Having them as a literal was too awkward, and honestly, pretty ugly.

Thanks for the heads-up!

Re:What's New in Ruby 2.1 [pdf] by jamesbritt on Wednesday November 27, 2013 @02:28PM (#6810477)
Now instead of "foo".freeze it's "foo"f, but how frequently will that save you time/trouble?

Worse, it seems to break the model of "interact with objects by sending messages", where you send a message using

    <object>.<message>
Is "foo"f _not_ sending a message? If so, then what is it doing? If yes, then why new syntax?
Re:What's New in Ruby 2.1 [pdf] by bct on Wednesday November 27, 2013 @02:42PM (#6810573)
It's not sending a message - that would defeat the purpose. It's constructing a frozen string, reusing an existing one when possible.

Prior to 2.1:

    def foo
      "bar".freeze
    end
does these things every time `foo` is called:

1. copies the characters 'b', 'a', and 'r' into a mutable string

2. sends the message `freeze` to the new string, which...

3. marks the string as frozen.

In 2.1 `"bar".freeze` is equivalent to `"bar"f`, which will not make a copy every time `foo` is called. See https://bugs.ruby-lang.org/issues/8579 for more discussion.

Re:What's New in Ruby 2.1 [pdf] by jamesbritt on Wednesday November 27, 2013 @07:32PM (#6812290)
I see. Thank you.
Re:What's New in Ruby 2.1 [pdf] by aaronblohowiak on Wednesday November 27, 2013 @02:44PM (#6810588)
it is not sending a message any more than 0b100 is sending a message. this is syntax for a type.
Re:What's New in Ruby 2.1 [pdf] by bct on Wednesday November 27, 2013 @02:59PM (#6810697)
My understanding is that frozen strings (unlike Symbols) are garbage collected. This is useful because symbol construction can be used to DOS an application.

(I agree that it's a weird, low level detail to have to think about.)

Re:What's New in Ruby 2.1 [pdf] by derefr on Wednesday November 27, 2013 @04:34PM (#6811295)
Wait, so Ruby has the same problem with symbols that Erlang does with atoms? Why don't I constantly see warnings against using String#intern the way I do about list_to_atom/1?
Re:What's New in Ruby 2.1 [pdf] by brandonbloom on Wednesday November 27, 2013 @08:43PM (#6812545)
> Wait, so Ruby has the same problem with symbols that Erlang does with atoms?

Yes.

> Why don't I constantly see warnings against using String#intern the way I do about list_to_atom/1?

Because leaking memory over time is pretty much the natural state of being for Ruby apps. Periodic process restarts are culturally A-OK. Leaking symbols are likely to be the least of your perf problems.

But even in Erlang, the issue is only calling an interning operation on untrusted user data. In most real word use cases, you'll leak until a constant limit, which is probably no big deal. However, I've seen many Rails vulnerable to trivial DOS attacks by sending 1MB of random nonsense in a field known to be .to_sym-ed

Re:What's New in Ruby 2.1 [pdf] by taylorfausak on Wednesday November 27, 2013 @11:12AM (#6808881)
I'm looking forward to `def` returning a symbol (page 11).

    private static void def main(args) ...; end
Re:What's New in Ruby 2.1 [pdf] by ngcazz on Wednesday November 27, 2013 @11:59AM (#6809313)
That slide was a bit confusing for my underslept mind. Is that meant as an example of calling methods which work over the result of defining main (in this case static and void)?
Re:What's New in Ruby 2.1 [pdf] by lectrick on Wednesday November 27, 2013 @02:07PM (#6810335)
If you say "private def methodname(args); end",

the "private" keyword already takes a symbol for a method name to privatize, so in this case the return of "def methodname(args); end" is ":methodname" which then gets passed to "private" and everything magically works.

Re:What's New in Ruby 2.1 [pdf] by hderms on Wednesday November 27, 2013 @02:42PM (#6810576)
yeah it's an example of how you could implement higher-level language features much easier if def returns a symbol rather than nil
Re:What's New in Ruby 2.1 [pdf] by diminish on Wednesday November 27, 2013 @03:09PM (#6810775)
I wish they dedicate 2.2 and 2.3 only to performance improvements of the core and std lib.
Re:What's New in Ruby 2.1 [pdf] by ksec on Thursday November 28, 2013 @11:01PM (#6817832)
Yes, JIT to Native Code, Better GC. We have yet to see any "substantial" improvement.
Re:What's New in Ruby 2.1 [pdf] by cmaggard on Wednesday November 27, 2013 @11:15AM (#6808897)
It's unclear from the intro summary, but I'm assuming from the lack of further explanation that refinements are just GONE, and not just "no longer experimental"?
Re:What's New in Ruby 2.1 [pdf] by jameskilton on Wednesday November 27, 2013 @11:19AM (#6808937)
Nope, by "no longer experimental" they are now officially in the core language. More information here: http://rkh.im/ruby-2.1
Re:What's New in Ruby 2.1 [pdf] by cmaggard on Wednesday November 27, 2013 @11:26AM (#6808987)
Ah, well that's something then. Thanks for the clarification.
Re:What's New in Ruby 2.1 [pdf] by venus on Wednesday November 27, 2013 @10:18PM (#6812819)
The most important feature for me is mandatory named args:

  def foo(bar:)
Named args with defaults solved one half of the problem we'd been solving with the "options hash"; now that's the second half. Can't wait!
Re:What's New in Ruby 2.1 [pdf] by dgregd on Wednesday November 27, 2013 @03:57PM (#6811082)
Is it possible to add optional typing to Ruby? Something similar to what Dart has.

Optional typing would be very useful for big Ruby apps.

Re:What's New in Ruby 2.1 [pdf] by rev_null on Wednesday November 27, 2013 @03:59PM (#6811100)
I'd be intrigued to see how a ruby type checker would handle boolean expressions.
Re:What's New in Ruby 2.1 [pdf] by andyl on Wednesday November 27, 2013 @03:00PM (#6810701)
I've upgraded one of my Rails4 apps to 2.1.0-preview2. Everything seems to be working fine except pry-debugger.

What is it with the ruby debugger? It has always been problematic for me.

Re:What's New in Ruby 2.1 [pdf] by thedevelopment on Wednesday November 27, 2013 @04:53PM (#6811403)
I believe the debugger is broken in Ruby-2.0, and you should use byebug instead.

There are pry wrappers for byebug - https://github.com/deivid-rodriguez/pry-byebug - maybe that'll work?

Re:What's New in Ruby 2.1 [pdf] by andyl on Wednesday November 27, 2013 @07:00PM (#6812152)
Yesss - that worked. Tip of the day - thanks a ton !!