October 24, 2005
In article <djj2o5$14u4$1@digitaldaemon.com>, sai says...
>
>I vote for '$' being a short form of 'with' for all objects including arrays like this:
>
>--------------------------
>Instead of array[ length - 2 ]
>
>Use:
>array[ $length - 2 ]

I don't like it and I don't think I'll use it.

less offencive to me would be "$."
array[ $.length - 2 ]

Ant


October 24, 2005
In article <djj7lk$19fr$1@digitaldaemon.com>, Ant says...
>
>In article <djj2o5$14u4$1@digitaldaemon.com>, sai says...
>>
>>I vote for '$' being a short form of 'with' for all objects including arrays like this:
>>
>>--------------------------
>>Instead of array[ length - 2 ]
>>
>>Use:
>>array[ $length - 2 ]
>
>I don't like it and I don't think I'll use it.
>
>less offencive to me would be "$."
>array[ $.length - 2 ]

that could also be used on the with block
(I don't know about nested with - maybe it's not allowed)

Ant


October 24, 2005
Burton Radons wrote:

> The contextual identifier "length" has been a problem ever since it was introduced (I can never seem to stop naming an identifier I'm going to use in an array "length", and any time I use it intentionally it looks odd), and we've had the superior "$" for a long time now.  As a result, "length" is becoming even more of a problem because I forget it even exists, and I'm sure there are people who don't know of the superior alternative.  I think it's now time to go to the next step and deprecate and eventually remove this bad thing.

Why is a symbol necessary at all? What's wrong with:

arr[3..] // from 3 to arr.length
arr[..3] // from 0 to 3
arr[..]  // from 0 to arr.length (instead of arr.dup)

James McComb
October 24, 2005
On Mon, 24 Oct 2005 19:23:49 -0400, James McComb <ned@jamesmccomb.id.au> wrote:

> Why is a symbol necessary at all? What's wrong with:
>
> arr[3..] // from 3 to arr.length
> arr[..3] // from 0 to 3

then people want arr[3 .. -1]

> arr[..]  // from 0 to arr.length (instead of arr.dup)

why would that dup, other slices don't dup
October 24, 2005
On Tue, 25 Oct 2005 09:23:49 +1000, James McComb wrote:

> Burton Radons wrote:
> 
>> The contextual identifier "length" has been a problem ever since it was introduced (I can never seem to stop naming an identifier I'm going to use in an array "length", and any time I use it intentionally it looks odd), and we've had the superior "$" for a long time now.  As a result, "length" is becoming even more of a problem because I forget it even exists, and I'm sure there are people who don't know of the superior alternative.  I think it's now time to go to the next step and deprecate and eventually remove this bad thing.
> 
> Why is a symbol necessary at all? What's wrong with:
> 
> arr[3..] // from 3 to arr.length
> arr[..3] // from 0 to 3
> arr[..]  // from 0 to arr.length (instead of arr.dup)
> 
> James McComb

The absence of a 'length'-type token in the text of your source can be lost in the surrounding 'clutter' and thus reduce the reader's understanding of your code.

   SomeFunc(Found.Files[Last.FoundIndex+1..],Some.Other,Useful.Parameters);

whereas the inclusion of a positive visual signal can improve the legibility of your code and thus reduce maintenance costs.

The argument is mostly concerned with what is the most appropriate positive visual signal we should use to represent the array length concept in this context.

Current contenders seem to be ...

 length
 arr.length
 .length
 len
 $
 $length
 $.length
 #
 #length

Of these, I favour all those that have a no possibility of being mistaken
for a reserved word, an identifier, or an existing token in other contexts.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
25/10/2005 9:37:20 AM
October 25, 2005
In article <djjhv8$1ici$1@digitaldaemon.com>, Ant says...
>
>In article <djj7lk$19fr$1@digitaldaemon.com>, Ant says...
>>
>>In article <djj2o5$14u4$1@digitaldaemon.com>, sai says...
>>>
>>>I vote for '$' being a short form of 'with' for all objects including arrays like this:
>>>
>>>--------------------------
>>>Instead of array[ length - 2 ]
>>>
>>>Use:
>>>array[ $length - 2 ]
>>
>>I don't like it and I don't think I'll use it.
>>
>>less offencive to me would be "$."
>>array[ $.length - 2 ]
>
>that could also be used on the with block
>(I don't know about nested with - maybe it's not allowed)

A reference to the outer with block would be .$.length ;)

/Oskar


October 25, 2005
Ant wrote:
> In article <djj2o5$14u4$1@digitaldaemon.com>, sai says...
> 
>>I vote for '$' being a short form of 'with' for all objects including arrays
>>like this:
>>
>>--------------------------
>>Instead of array[ length - 2 ] 
>>
>>Use:
>>array[ $length - 2 ]
> 
> 
> I don't like it and I don't think I'll use it.
> 
> less offencive to me would be "$."
> array[ $.length - 2 ]
> 
> Ant

I agree, and was thinking the same thing.
Then you could also use $.typeof, etc -- it does seem to me that length is not the only case that is useful.
This would also mean that the syntax like $abc is still available.
October 25, 2005
It would be reasonable to use it as a variable, but I mean, then why not use "a"?  Seriously, if you have problems typing out length, or don't like the variable, then use a different one.

The syntax doesn't matter in the grand scheme beyond it being readable and consistent.  We want it to be regular and effective at expressing the concept.  "arr.length" expresses exactly what we want and is consistent.

"$" is not.  I have no idea what it means, and it takes just as long to type cause of the shift key.

I used to think it might be a powerful thing in JavaScript to override the "." so if you went:

"Matrix.
multiply(x){...};
divide(x){...   .inverse() ...}
"

It seems to be able to very tersely eliminate with/this.  In JavaScript, where code size is very important, it matters.  In D it has no significance and makes code impossible to read.


October 25, 2005
Vathix wrote:

>> arr[..]  // from 0 to arr.length (instead of arr.dup)

> why would that dup, other slices don't dup

My mistake.

James McComb
Next ›   Last »
1 2 3 4
Top | Discussion index | About this forum | D home