Others, e.g. Matz, can answer this better, but this is
my attempt.

I think the reason arrays are not used as often as in other
languages is simply that the jobs for which arrays are
sometimes (traditionally) used are better done in other ways.

The hash is the best example. If this were 1985 and I were
programming in Pascal, I would implement a hash as an array
(probably an array of records) and write ugly routines to
add, delete, and search.

Likewise if I were programming in Pascal (or even C), I would
think of my strings as arrays of characters.

I'm not aware of any particular reason to avoid using arrays
in Ruby. They are very useful (and have methods that enable
them to be used as sets, stacks, and queues).

As for the memory issue: We all do things in our "alpha"
versions that might seem silly later. Don't worry overmuch
about that. Get the thing working, then trash the array and
use a file if it turns out memory is a problem. Of course,
execution time might go up then...

Hal Fulton

In article <395B6BF8.F8CDB3D0 / earthlink.net>,
  Charles Hixson <charleshixsn / earthlink.net> wrote:
> This is a multi-part message in MIME format.
> --------------9F3C1C9380176B7D6946853A
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit
>
> I am wondering about the use of arrays in Ruby.  It
> seems rare in the sample code.  Does this mean that
> they should be avoided?
>
> In particular I am contemplating processing a data
> file with > 100 columns & around 14,000 records.
> The first record contains column headers.  I had
> planned on using a pair of arrays, one for the
> titles and a two dimensional one for the records
> (until I figure out random access, and recreate the
> file).
>
> Alternate approaches are: 1) use arrays to map the
> data to the name, 2) use hash tables to associate
> the data with the name, 3) create a special class
> that mimics the data structure.  Approach 1 seems
> the most general purpose.  It seems to me that
> approach 2 would use excessive RAM (this data
> SHOULDN'T all be kept in memory, but this is a
> learning project).  It seems to me that approach 3
> would be inflexible -- I wouldn't be able to build
> one routine and use it to process all files in that
> form, only ones whose column headers matched.
>
> But I really don't know.  And the scarcity of arrays
> in the sample programs causes me to wonder whether
> they should be avoided.
>
> --------------9F3C1C9380176B7D6946853A
> Content-Type: text/x-vcard; charset=us-ascii;
>  name="charleshixsn.vcf"
> Content-Transfer-Encoding: 7bit
> Content-Description: Card for Charles Hixson
> Content-Disposition: attachment;
>  filename="charleshixsn.vcf"
>
> begin:vcard
> n:Hixson;Charles
> x-mozilla-html:FALSE
> adr:;;;;;;
> version:2.1
> email;internet:charleshixson / earthling.net
> fn:Charles Hixson
> end:vcard
>
> --------------9F3C1C9380176B7D6946853A--
>
>

--
Hal Fulton


Sent via Deja.com http://www.deja.com/
Before you buy.