October 26, 2005
On Wed, 26 Oct 2005 03:24:24 +0000 (UTC), Dan wrote:


[snip]


> Another problem you suddenly run into when using $ for "this array" is correctly and consistently making it obvious what "this array" is.  As you mentioned in your own example, we had two arrays with messy names.  How do you switch the $ to mean one and then the other?

You don't. It always refers to the array being sliced.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
26/10/2005 1:57:26 PM
October 26, 2005
Derek Parnell wrote:
>>It makes it about three keystrokes easier (shift down, pound, shift up), but if
>>you really are in that much of a hurry maybe copy and paste it.  Just double
>>click on length and Ctrl C, Ctrl V.
> 
> 
> SomeClass.Selected_Items[SomeClass.Selected_Items.length-1] &=         AnotherClass.User_Choice[AnotherClass.User_Choice.length-2 ..
>                                  AnotherClass.User_Choice.length-1];
>  SomeClass.Selected_Items[$-1] &= AnotherClass.User_Choice[$-2 .. $-1];
> 
> 

What you speak here is a particular case of a more general issue, which is having several repeated names in a piece of code.
For instance in:
  SomeClass.Selected_Items.SomeMethod( SomeClass.Selected_Items.member,
    AnotherClass.User_Choice.member +
    AnotherClass.User_Choice.member*2);

we have a similar problem. The solution you have (whether with "$" or "length") is particular for arrays only, and it works only for accessing the length of the indexed array, not of other arrays. Why not use the general solution to this issue, that is, use alias and/or intermediate objects to refactor code, as appropriate for the semantics of the code:

  auto selItems = SomeClass.Selected_Items;
  auto member = AnotherClass.User_Choice.member;
  selItems.SomeMethod( selItems.member, member + member*2);

Is it worth it, to have a keyword that works only in a specific case with arrays? I'm not saying yet that it isn't, but I think I'm more inclined to writing verbose code (with or without intermediate objects, depending) which only sometimes, perhaps not very often, will be annoyingly bigger than a "$" keyword version. Also, note that the existence of IDE code auto-completion will soften most of the burden of writing the verbose way.

-- 
Bruno Medeiros - CS/E student
"Certain aspects of D are a pathway to many abilities some consider to be... unnatural."
October 30, 2005
"Derek Parnell" <derek@psych.ward> wrote in message
> SomeClass.Selected_Items[SomeClass.Selected_Items.length-1] &=
>        AnotherClass.User_Choice[AnotherClass.User_Choice.length-2 ..
>                                 AnotherClass.User_Choice.length-1];
>
> SomeClass.Selected_Items[$-1] &= AnotherClass.User_Choice[$-2 .. $-1];
>
>> Unless you care to inform me why it matters?
>
> I still think that code legibility is enhanced by using a small symbol to represent the concept of 'the current array's length'.

True. Yet, is there really such an issue with the following alternate sugar? The benefits are notable:

   SomeClass.Selected_Items  [$len-1] &=
    AnotherClass.User_Choice [$len-2 .. $len-1];



October 30, 2005
On Sun, 30 Oct 2005 13:08:46 -0800, Kris wrote:

> "Derek Parnell" <derek@psych.ward> wrote in message
>> SomeClass.Selected_Items[SomeClass.Selected_Items.length-1] &=
>>        AnotherClass.User_Choice[AnotherClass.User_Choice.length-2 ..
>>                                 AnotherClass.User_Choice.length-1];
>>
>> SomeClass.Selected_Items[$-1] &= AnotherClass.User_Choice[$-2 .. $-1];
>>
>>> Unless you care to inform me why it matters?
>>
>> I still think that code legibility is enhanced by using a small symbol to represent the concept of 'the current array's length'.
> 
> True. Yet, is there really such an issue with the following alternate sugar? The benefits are notable:
> 
>    SomeClass.Selected_Items  [$len-1] &=
>     AnotherClass.User_Choice [$len-2 .. $len-1];

No. I said "small symbol" and "$len" looks small to me.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
31/10/2005 9:30:17 AM
October 31, 2005
"Derek Parnell" <derek@psych.ward> wrote ...
> On Sun, 30 Oct 2005 13:08:46 -0800, Kris wrote:
>>> I still think that code legibility is enhanced by using a small symbol
>>> to
>>> represent the concept of 'the current array's length'.
>>
>> True. Yet, is there really such an issue with the following alternate
>> sugar?
>> The benefits are notable:
>>
>>    SomeClass.Selected_Items  [$len-1] &=
>>     AnotherClass.User_Choice [$len-2 .. $len-1];
>
> No. I said "small symbol" and "$len" looks small to me.

Me too :-)


1 2
Next ›   Last »