A better way to do this job?

Hi --

···

On Wed, 11 Feb 2009, Ryan Davis wrote:

On Feb 10, 2009, at 04:21 , Julian Leviston wrote:

First doesn't take an argument I'm ruby. It does
If you're using rails enumerable mixin

David showed it in 1.9... but I had to point this out:

% ruby -ve 'puts [1,2,3,4].first(2)'
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
1
2

this goes back to at least 1.7 iirc. #first was introduced in 1.6 and 1.7 gave it an optional length arg.

I've clearly got 1.9 on the brain :slight_smile:

David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2\)

http://www.wishsight.com => Independent, social wishlist management!

David A. Black wrote:

Hi --

> Slices and 'sub-arrays' aren't copies of the objects, they simply refer
> to the identical objects.

The same can be said of any array; the objects inside it exist (in
many cases, at least) already. Still, container objects do take up
memory.

Ruby arrays are copy-on-write though. So subarray = my_array[100...1000100]
does *not* take up any memory except for the additional array object (which
will contain a pointer to the 100th item of my_array and the length 1000000).

HTH,
Sebastian

···

On Tue, 10 Feb 2009, Julian Leviston wrote:

--
Jabber: sepp2k@jabber.org
ICQ: 205544826

Sorry dude. Imust have been having an odd day. I swear my irb said it don't work :slight_smile:

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

···

On 11/02/2009, at 7:06 AM, Ryan Davis <ryand-ruby@zenspider.com> wrote:

On Feb 10, 2009, at 04:21 , Julian Leviston wrote:

First doesn't take an argument I'm ruby. It does
If you're using rails enumerable mixin

David showed it in 1.9... but I had to point this out:

% ruby -ve 'puts [1,2,3,4].first(2)'
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
1
2

this goes back to at least 1.7 iirc. #first was introduced in 1.6 and 1.7 gave it an optional length arg.

Hi --

ruby -e 'a = [:a,:b,:c]; b = ; while true; b << a[0,3]; end'

That's a little bit unfair though. If you pushed an infinite number of
object of whatever class, you'd eventually run out of memory.

I'm just making the point that even though two arrays may contain the
same objects (not copies), arrays are not cost-free, so creating
intermediate arrays may well be an issue.

I personally find #first() rather confusing (BTW [1,2,3].first
(3).class => Array).

Yes, that's right -- I've over-enumeratored my response :slight_smile:

David

···

On Tue, 10 Feb 2009, Tom Link wrote:

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2\)

http://www.wishsight.com => Independent, social wishlist management!

Hi --

David A. Black wrote:

Hi --

Slices and 'sub-arrays' aren't copies of the objects, they simply refer
to the identical objects.

The same can be said of any array; the objects inside it exist (in
many cases, at least) already. Still, container objects do take up
memory.

Ruby arrays are copy-on-write though. So subarray = my_array[100...1000100]
does *not* take up any memory except for the additional array object (which
will contain a pointer to the 100th item of my_array and the length 1000000).

My memory-eating example was probably unrealistic. Maybe I'm too
steeped in the idea that enumerators are good because they don't
create intermediate arrays.... (I have some real issues with some of
what they do, so I tend to cling to that one.)

Ryan's point (it's not a problem until it's a problem) is a key one,
in any case. I definitely would not discourage creation of
intermediate objects unless there's a real reason to avoid them.

David

···

On Wed, 11 Feb 2009, Sebastian Hungerecker wrote:

On Tue, 10 Feb 2009, Julian Leviston wrote:

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2\)

http://www.wishsight.com => Independent, social wishlist management!

What makes it bad manners? I'm simply posting where my cursor appears.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

···

On 11/02/2009, at 7:07 AM, Ryan Davis <ryand-ruby@zenspider.com> wrote:

On Feb 10, 2009, at 05:59 , James Gray wrote:

On Feb 10, 2009, at 6:21 AM, Julian Leviston wrote:

First doesn't take an argument I'm ruby. It does
If you're using rails enumerable mixin

Would you please stop top posting? It's just bad manners.

agreed!

What makes it bad manners?

Many people consider it an annoyance. IIRC the netiquette RFC even has
a section on quoting: http://www.ietf.org/rfc/rfc1855.txt

Hi Julian,

···

Am Donnerstag, 12. Feb 2009, 00:29:38 +0900 schrieb Julian Leviston:

On Feb 10, 2009, at 05:59 , James Gray wrote:

Would you please stop top posting? It's just bad manners.

What makes it bad manners? I'm simply posting where my cursor appears.

That's the point. It's not where the reader's eyes appear. What is
easier to move: Your cursor or some dozens of pairs of eyes?

Bertram

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

Bertram Scharpf wrote:

Hi Julian,

Would you please stop top posting? It's just bad manners.
        

What makes it bad manners? I'm simply posting where my cursor appears.
    
That's the point. It's not where the reader's eyes appear. What is
easier to move: Your cursor or some dozens of pairs of eyes?
  
Agreed. It also makes it that much more difficult to get context. While this is an extreme example, notice how naturally that reads, to someone coming late to the discussion?

It's also a bit irritating how you're spamming your blog (and "learn rails") in something like a signature -- but there's nothing separating it from your post, and it's also right there before whatever you're quoting.

···

Am Donnerstag, 12. Feb 2009, 00:29:38 +0900 schrieb Julian Leviston:

On Feb 10, 2009, at 05:59 , James Gray wrote:

It's not possible to bottom post while maintaining my signatures on the iPhone as far as I can tell. Sorry.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

···

On 12/02/2009, at 3:08 AM, Tom Link <micathom@gmail.com> wrote:

What makes it bad manners?

Many people consider it an annoyance. IIRC the netiquette RFC even has
a section on quoting: http://www.ietf.org/rfc/rfc1855.txt

Hi Julian,

···

Am Donnerstag, 12. Feb 2009, 10:13:31 +0900 schrieb Julian Leviston:

What makes it bad manners?

Many people consider it an annoyance. IIRC the netiquette RFC even has
a section on quoting: http://www.ietf.org/rfc/rfc1855.txt

It's not possible to bottom post while maintaining my signatures on the
iPhone as far as I can tell. Sorry.

It's not possible for - drum roll - you! Make a decision what
should be made easy: writing for you or reading for the people you
like to impress. I case you decide making it easier for yourself,
wait for the audience you comb out by that.

Sorry.

Bertram

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

Doesn't the quoting line indicate enough who wrote what?

I find your english unintelligible.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

···

On 12/02/2009, at 3:25 PM, Bertram Scharpf <lists@bertram-scharpf.de> wrote:

Hi Julian,

Am Donnerstag, 12. Feb 2009, 10:13:31 +0900 schrieb Julian Leviston:

What makes it bad manners?

Many people consider it an annoyance. IIRC the netiquette RFC even has
a section on quoting: http://www.ietf.org/rfc/rfc1855.txt

It's not possible to bottom post while maintaining my signatures on the
iPhone as far as I can tell. Sorry.

It's not possible for - drum roll - you! Make a decision what
should be made easy: writing for you or reading for the people you
like to impress. I case you decide making it easier for yourself,
wait for the audience you comb out by that.

Sorry.

Bertram

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

Hi Julian,

···

Am Donnerstag, 12. Feb 2009, 14:42:42 +0900 schrieb Julian Leviston:

On 12/02/2009, at 3:25 PM, Bertram Scharpf <lists@bertram-scharpf.de> > wrote:

Am Donnerstag, 12. Feb 2009, 10:13:31 +0900 schrieb Julian Leviston:

What makes it bad manners?

Many people consider it an annoyance. IIRC the netiquette RFC even has
a section on quoting: http://www.ietf.org/rfc/rfc1855.txt

It's not possible to bottom post while maintaining my signatures on the
iPhone as far as I can tell. Sorry.

It's not possible for - drum roll - you! Make a decision what
should be made easy: writing for you or reading for the people you
like to impress. I case you decide making it easier for yourself,
wait for the audience you comb out by that.

Doesn't the quoting line indicate enough who wrote what?

I find your english unintelligible.

Sorry, I didn't guess how difficult it is for you to accept such a
simple thing. I won't try to argue any further.

Bertram

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

Please stop feeding the troll.

···

On Feb 12, 2009, at 03:41 , Bertram Scharpf wrote:

Am Donnerstag, 12. Feb 2009, 14:42:42 +0900 schrieb Julian Leviston:

I find your english unintelligible.

Sorry, I didn't guess how difficult it is for you to accept such a
simple thing. I won't try to argue any further.