From: Rafael Crivellari Saliba Schouery Date: 2009-04-15T21:56:37+09:00 Subject: [ruby-core:23214] Re: [Bug #1367] flatten(0) is not consistent with flatten(), flatten(1), etc. --001636163d193cb3150467977a3e Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit I thought about that too. I was think about other functions. sort, of course, is going to give you a new array, but what about functions that already knows that is not going to do anything, like [].reverse ? Ruby gives you a new array, so I think this is really a bug. I want to make a patch for it soon, but I don't know when I will be able to. Bye! Rafael Schouery VidaGeek.net On Wed, Apr 15, 2009 at 7:11 AM, Paul Lewis wrote: > Issue #1367 has been updated by Paul Lewis. > > > As a pro-fix argument consider what happens when the code using flatten has > a dynamic depth value. So rather than: > > x = a.flatten(0) > > It's something like: > > x = a.flatten(depth) > > To ensure that this code behaviour predictably (without this fixed) it > becomes necessary to treat 0 as a special case: > > depth = ??? > x = (depth != 0 ? a.flatten() : a.clone()) > > As it works at the moment I think it violates the principle of least > surprise. > http://en.wikipedia.org/wiki/Principle_of_least_surprise > ---------------------------------------- > http://redmine.ruby-lang.org/issues/show/1367 > > ---------------------------------------- > http://redmine.ruby-lang.org > > --001636163d193cb3150467977a3e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I thought about that too.
I was think about other functions. sort, of co= urse, is going to give you a new array,
but what about functions that al= ready knows that is not going to do anything, like
[].reverse ?
Ruby = gives you a new array, so I think this is really a bug. I want to make a pa= tch
for it soon, but I don't know when I will be able to.
Bye!

Rafael Schouery
VidaGeek.net


On Wed, Apr 15, 2009 at 7:11 AM, Paul Le= wis <redmine@= ruby-lang.org> wrote:
Issue #1367 has been updated by Paul Lewis.


As a pro-fix argument consider what happens when the code using flatten has= a dynamic depth value. =A0So rather than:

x =3D a.flatten(0)

It's something like:

x =3D a.flatten(depth)

To ensure that this code behaviour predictably (without this fixed) it beco= mes necessary to treat 0 as a special case:

depth =3D ???
x =3D (depth !=3D 0 ? a.flatten() : a.clone())

As it works at the moment I think it violates the principle of least surpri= se.
http://en.wikipedia.org/wiki/Principle_of_least_surprise ----------------------------------------
----------------------------------------

--001636163d193cb3150467977a3e--