What's New in Ruby 2.1 [pdf]
11–20 of 36 posts
Re: What's New in Ruby 2.1 [pdf]
#12I 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...
#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]
#13I'm looking forward to `def` returning a symbol (page 11). private static void def main(args) ...; end
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)?
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]
#14I 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]
#15I'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 ta…
Worse, it seems to break the model of "interact with objects by sending messages", where you send a message using
.
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]
#16I'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 ta…
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 . Is "foo"f _not_ sending a message? If so, then what is it doing? If yes, then why new syntax?
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]
#17I'm looking forward to `def` returning a symbol (page 11). private static void def main(args) ...; end
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]
#18I'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 ta…
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 . 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]
#19I'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 ta…
https://www.ruby-lang.org/en/news/2013/11/22/ruby-2-1-0-prev...
Re: What's New in Ruby 2.1 [pdf]
#20I'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 ta…