ActiveSupport::OrderedHash disappears?

50 views
Skip to first unread message

Alexey

unread,
Jul 14, 2011, 6:47:54 PM7/14/11
to rubyonra...@googlegroups.com
Hello, i have asked this question here: https://www.ruby-forum.com/topic/2140803, but maybe you can answer quickly.

Is ActiveSupport::OrderedHash going to be maintained in Rails?
Its API page disappeared.
I do not want to rely on Hash's being ordered in Ruby 1.9 (mainly because it is not called OrderedHash).

Thank you,

Alexey.

Andrew Kaspick

unread,
Jul 14, 2011, 9:37:20 PM7/14/11
to rubyonra...@googlegroups.com
Why don't you want to rely on it? It's documented behaviour, so you
can totally rely on it.

> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-core/-/FsZLFviGct0J.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-co...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-core?hl=en.
>

Prem Sichanugrist

unread,
Jul 14, 2011, 10:05:31 PM7/14/11
to rubyonra...@googlegroups.com
If your target deployment is Ruby 1.9, you *should* use Hash that come with Ruby. It's guaranteed to be sorted, and it doesn't have the same overhead that AS::OrderedHash has.

Do you know that AS::OrderedHash is an array within array, and it's very slow? Hash in 1.9 is written in C, and doesn't suffer the same slowness.

- Prem

Guillermo Iguaran

unread,
Jul 15, 2011, 12:00:00 AM7/15/11
to rubyonra...@googlegroups.com
Yes, it's going to be maintained, probably until version 4.0 of Rails that will drop Ruby 1.8 support

-- 
Guille
--

Aaron Patterson

unread,
Jul 15, 2011, 12:24:00 AM7/15/11
to rubyonra...@googlegroups.com

We won't remove it until Rails 4. Even then, I'm not sure it will be
removed. It will just == Hash.

--
Aaron Patterson
http://tenderlovemaking.com/

Alexey

unread,
Jul 15, 2011, 4:07:17 AM7/15/11
to rubyonra...@googlegroups.com
Andrew, i read that many disagreed with Hash's being ordered, and i think they have a reason for that.
After all, it is called Hash.
So i was wondering if i could use a more appropriately named structure for an ordered hash (even if it will be identical with Hash in implementation).

Alexey

unread,
Jul 15, 2011, 4:08:32 AM7/15/11
to rubyonra...@googlegroups.com
Thank you all for explanations.

Alexey.

Alexey

unread,
Jul 15, 2011, 6:04:16 AM7/15/11
to rubyonra...@googlegroups.com
I also think that documenting this behavior of Hash could be a mistake, if some day there will exist a better implementation of a pure has than a doubly-circular linked list as in Ruby 1.9 (some kind of a tree?)

Alexey.

Jon Leighton

unread,
Jul 15, 2011, 6:55:31 AM7/15/11
to rubyonra...@googlegroups.com
If you're on 1.9 there is no slowdown with using OrderedHash vs Hash, as
OrderedHash basically just inherits from Hash and does nothing else.

https://github.com/rails/rails/blob/master/activesupport/lib/active_support/ordered_hash.rb#L51

--
http://jonathanleighton.com/

signature.asc

Alexey

unread,
Jul 15, 2011, 7:10:23 AM7/15/11
to Ruby on Rails: Core
Thanks Jon,
this is the kind of a solution i was hoping for.

Alexey.

On Jul 15, 12:55 pm, Jon Leighton <j...@jonathanleighton.com> wrote:
> If you're on 1.9 there is no slowdown with using OrderedHash vs Hash, as
> OrderedHash basically just inherits from Hash and does nothing else.
>
> https://github.com/rails/rails/blob/master/activesupport/lib/active_s...
>
>
>
>
>
> On Thu, 2011-07-14 at 22:05 -0400, Prem Sichanugrist wrote:
> > If your target deployment is Ruby 1.9, you *should* use Hash that come with Ruby. It's guaranteed to be sorted, and it doesn't have the same overhead that AS::OrderedHash has.
>
> > Do you know that AS::OrderedHash is an array within array, and it's very slow? Hash in 1.9 is written in C, and doesn't suffer the same slowness.
>
> > - Prem
>
> > On Jul 14, 2011, at 9:37 PM, Andrew Kaspick wrote:
>
> > > Why don't you want to rely on it?  It's documented behaviour, so you
> > > can totally rely on it.
>
>  signature.asc
> < 1KViewDownload

Prem Sichanugrist

unread,
Jul 15, 2011, 7:54:11 AM7/15/11
to rubyonra...@googlegroups.com
Nice! I didn't know this.

Thanks for sharing :)

Reply all
Reply to author
Forward
0 new messages