Live data from Hacker News

What's New in Ruby 2.1 [pdf]

atdot.net

31–36 of 36 posts

Re: What's New in Ruby 2.1 [pdf]

#31

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 ta…

[deleted]

Re: What's New in Ruby 2.1 [pdf]

#32
post #22

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.

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?

Yesss - that worked. Tip of the day - thanks a ton !!

Re: What's New in Ruby 2.1 [pdf]

#33
post #16

Earlier quoted context omitted.

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?

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`…

I see. Thank you.

Re: What's New in Ruby 2.1 [pdf]

#34
post #28
post #21

Earlier quoted context omitted.

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.)

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?

> 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]

#35
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!
Post reply on HN