{"id":1869,"date":"2009-02-05T11:58:31","date_gmt":"2009-02-05T15:58:31","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=1869"},"modified":"2009-02-05T11:58:35","modified_gmt":"2009-02-05T15:58:35","slug":"ordered-hashes-in-ruby-19","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2009\/02\/05\/ordered-hashes-in-ruby-19\/","title":{"rendered":"Ordered Hashes in Ruby 1.9"},"content":{"rendered":"<p>In Ruby 1.9, hash tables <a href=\"http:\/\/www.igvita.com\/2009\/02\/04\/ruby-19-internals-ordered-hash\/\">preserve insertion order<\/a> by maintaining a doubly-linked list. This seems like a dubious feature. It only accords with the principle of least surprise if you don&rsquo;t know how a hash table works. I don&rsquo;t think I&rsquo;ve ever needed a hash to do this, and I worry that making the order mostly predictable will lead to fragile code that accidentally relies on the ordering where it shouldn&rsquo;t. All of this comes at the cost of increased memory use. Overall, it&rsquo;s faster than Ruby&rsquo;s previous hash implementation, but presumably it would be even faster without the ordering feature.\n<\/p>","protected":false},"excerpt":{"rendered":"<p>In Ruby 1.9, hash tables preserve insertion order by maintaining a doubly-linked list. This seems like a dubious feature. It only accords with the principle of least surprise if you don&rsquo;t know how a hash table works. I don&rsquo;t think I&rsquo;ve ever needed a hash to do this, and I worry that making the order [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1869","post","type-post","status-publish","format-standard","hentry","category-programming-category"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/1869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=1869"}],"version-history":[{"count":0,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/1869\/revisions"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=1869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=1869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=1869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}