Re: 2.6 feature request: foreach (off topic)

new topic     » topic index » view thread      » older message » newer message

ags wrote:

> Juergen Luethje wrote:
>> b) A "2-dimensional sequence" in Euphoria could look like this:
>>       s = {
>>            {1},
>>            {7,8,12,-3,12},
>>            {9,5}
>>           }
>>
>>    AFAIK storing these data in a BASIC array would look something like
>>    this:
>>       a = {
>>            {1,0, 0, 0, 0},
>>            {7,8,12,-3,12},
>>            {9,5, 0, 0, 0}
>>           }
>>
>>    IOW, there will have to be several additional elements with value 0
>>    or something, wich are not needed at all, but which waste space of
>>    course.
>
> I don't think that's a fair comparison.  Quite often the reason for having
> a 2D array is if you want to access the array as a[x][y], if this is the
> case then you still need place-holders in Euphoria.

Not necessarily. A typical case is e.g. a table of distances between
several locations (say, in kilometers):


          | MyVillage | NiceTown | CoolCity | FinePlace
----------+-----------+----------+----------+----------
MyVillage |     0     |    12    |    7     |    15
----------+-----------+----------+----------+----------
NiceTown  |    12     |     0    |    9     |     6
----------+-----------+----------+----------+----------
CoolCity  |     7     |     9    |    0     |    14
----------+-----------+----------+----------+----------
FinePlace |    15     |     6    |   14     |     0


Much of the information in this table is redundant, we only need
6 fields instead of 16:


          | MyVillage | NiceTown | CoolCity | FinePlace
----------+-----------+----------+----------+----------
MyVillage |           |          |          |
----------+-----------+----------+----------+----------
NiceTown  |    12     |          |          |
----------+-----------+----------+----------+----------
CoolCity  |     7     |     9    |          |
----------+-----------+----------+----------+----------
FinePlace |    15     |     6    |   14     |


With BASIC, we have to fill the empty fields with a dummy value such
as 0 (first line and last column omitted):

   a = {
        {12, 0, 0},
        { 7, 9, 0},
        {15, 6,14}
       }


With Euphoria, we don't need place-holders. Of course we use something
like a[x][y] to access the data. We just have to take a little more care
of the indexes, when our data have the form of a "triangle" rather than
a "rectangle":

   a = {
        {12},
        { 7, 9},
        {15, 6,14}
       }


When an array with n*n elements is needed in BASIC, we only need n!
elements in Euphoria.

> But who is worried about memory these days, really?  We're talking about a
> language used on 32-bit Windows and *nix.

I am worried about memory these days, and I hope several other
programmers too.

> If we were talking embedded
> applications things might be a bit different, but as long as memory use isn't
> totally abused, you may as well use it; the OS will see to it that you don't
> run out of fast memory.

There are still many old computers running these days, on the one hand
in not-so-rich countries. On the other hand, in so-called industrial
countries there is a considerable amount of poor people (which is
persistently increasing in several countries!!). There are also e.g.
small charity organizations etc. that don't have much money.

Older computers typically don't have much memery, so the OS often has to
write data to and read them from the swap file. And especially on those
older machines, this process is slow.

Don't taking care of memory usage and speed, and thinking "Modern
hardware will do it for me." is certainly not what I would call good
programming style. I have seen "more than enough" bloatware, that runs
unnecessarily slow even on modern computers.

Regards,
   Juergen

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu