PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Hash insertion order preservation in ruby1.9
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Hash insertion order preservation in ruby1.9

Réponse
 
LinkBack Outils de la discussion
Vieux 31/03/2008, 11h50   #1
Joachim (München)
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Hash insertion order preservation in ruby1.9

I am glad to see that ruby1.9.0 preserves hash insertion order.
It will finally allow me to generate human-readable yaml dumps
without ugly workarounds.

Some questions:

(1) Can I rely upon hash insertion order preservation as an approved
new feature of Ruby, without any risk that it may get lost again in
future releases ?

(2) ri1.9 says:
"The order in which you traverse a hash by either key or value
may seem arbitrary, and will generally not be in the insertion order."
Do I understand correctly that this text is outdated ?

If the answer is two times yes, then read on, please:

(3) Would you agree that the almost undocumented yaml/omap
class is obsolete ? Maybe, one should clearly marked it as such,
or even exclude it from 1.9 ??

(4) Once hashes are ordered, new use cases will be found, and
new methods will become useful. I would like to propose the following
new instance methods
Hash#insert_before( existing_key, other_hash )
Hash#insert_after( existing_key, other_hash )
and possibly also
Hash#insert_before( existing_key, key, value )
Hash#insert_after( existing_key, key, value )
to insert new items at well defined locations. My use case, as I
said before, is a hash which is dumped into human-readable yaml.

Regards, Joachim
  Réponse avec citation
Vieux 31/03/2008, 15h11   #2
Rados³aw Bu³at
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Hash insertion order preservation in ruby1.9

SSB0aGluayB0aGF0IHlvdSBzaG91bGQgYXNrIG9uIHJ1YnktY2 9yZSBsaXN0LgoKLS0gClJhZG9z
s2F3IEJ1s2F0CgpodHRwOi8vcmFkYXJlay5qb2dnZXIucGwgLS Bt82ogYmxvZwo=

  Réponse avec citation
Vieux 31/03/2008, 17h34   #3
Robert Dober
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Hash insertion order preservation in ruby1.9

MjAwOC8zLzMxIFJhZG9zs2F3IEJ1s2F0IDxyYWRlay5idWxhdE BnbWFpbC5jb20+Ogo+IEkgdGhp
bmsgdGhhdCB5b3Ugc2hvdWxkIGFzayBvbiBydWJ5LWNvcmUgbG lzdC4KeWVzIGJ1dCB3aXRoIGNy
b3NzIHBvc3RpbmcgcGxlYXNlIEkgYmVsaWV2ZSB0aGF0IHRoaX Mgb2YgY29tbW9uCmludGVyZXN0
IG9uIHRoaXMgbGlzdCBnaXZlbiBpdHMgaGlzdG9yeS4KClJvYm VydAo+Cj4gIC0tCj4gIFJhZG9z
s2F3IEJ1s2F0Cj4KPiAgaHR0cDovL3JhZGFyZWsuam9nZ2VyLn BsIC0gbfNqIGJsb2cKPgoKCgot
LSAKaHR0cDovL3J1Ynktc21hbGx0YWxrLmJsb2dzcG90LmNvbS 8KCi0tLQpXaGVyZW9mIG9uZSBj
YW5ub3Qgc3BlYWssIHRoZXJlb2Ygb25lIG11c3QgYmUgc2lsZW 50LgpMdWR3aWcgV2l0dGdlbnN0
ZWluCg==

  Réponse avec citation
Vieux 02/04/2008, 02h39   #4
Nobuyoshi Nakada
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Hash insertion order preservation in ruby1.9

Hi,

At Mon, 31 Mar 2008 19:55:12 +0900,
Joachim (M=FCnchen) wrote in [ruby-talk:296442]:
> (4) Once hashes are ordered, new use cases will be found, and
> new methods will become useful. I would like to propose the following
> new instance methods
> Hash#insert_before( existing_key, other_hash )
> Hash#insert_after( existing_key, other_hash )
> and possibly also
> Hash#insert_before( existing_key, key, value )
> Hash#insert_after( existing_key, key, value )
> to insert new items at well defined locations. My use case, as I
> said before, is a hash which is dumped into human-readable yaml.


What do you expect on conflicts?

--=20
Nobu Nakada

  Réponse avec citation
Vieux 10/04/2008, 12h00   #5
Joachim (München)
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Hash insertion order preservation in ruby1.9

On 2 Apr., 03:39, Nobuyoshi Nakada <n...@ruby-lang.org> wrote:
> Hi,
>
> At Mon, 31 Mar 2008 19:55:12 +0900,
> Joachim (München) wrote in [ruby-talk:296442]:
>
> > (4) Once hashes are ordered, new use cases will be found, and
> > new methods will become useful. I would like to propose the following
> > new instance methods
> > Hash#insert_before( existing_key, other_hash )
> > Hash#insert_after( existing_key, other_hash )
> > and possibly also
> > Hash#insert_before( existing_key, key, value )
> > Hash#insert_after( existing_key, key, value )
> > to insert new items at well defined locations. My use case, as I
> > said before, is a hash which is dumped into human-readable yaml.

>
> What do you expect on conflicts?
>
> --
> Nobu Nakada


Sorry Nobu, I saw your question only today.

I see two possible conflicts:
- existing _key does not exist
- key already exists
Right?

I would raise an exception in both cases.

Rationale:
One could imagine several other ways to resolve conflicts.
I do not think one of them will be widely accepted as the obvious
right thing to do.
Therefore not attempting to reconcile conflicts will cause the least
surprise.

Regards, Joachim
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h12.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15771 seconds with 13 queries