View mode: basic / threaded / horizontal-split · Log in · Help
March 02, 2005
$ instead of length
[Starting a new thread on this, because the original is old and wandered off
topic too far]

"Derek Parnell" <derek@psych.ward> wrote in message
news:cu90r1$1e7t$1@digitaldaemon.com...
> Agreed. I have always supported the use of a symbol rather than an English
> word to represent the array's length property. I'm keen to promote the
> readibilty of source code by humans, so an extra 'dot' seems counter
> productive to that aim.


The $ idea for the length is a good one. The reason I didn't adopt it was
because I am trying to save $ for something big. I have a lot of thoughts
(inspired by some emails from Andrei A.) that $ could be very, very useful
in a future metaprogramming feature. Using $ as a length is a minor use, too
minor for such an important symbol!

So the options are:

1) Make it illegal for length within [ ] to hide another length in an outer
scope. This would essentially preclude length being used as a global, or
even as a class member.

2) Same as (1), but only restrict it if length is a variable local to a
function.

3) Make length a keyword. This is not that much different from (1).

4) Change length to another identifier. Nothing stands out as being
obviously right.

5) Invent a token for it that is other than '$'.
March 02, 2005
Re: $ instead of length
Walter wrote:

> 4) Change length to another identifier. Nothing stands out as being
> obviously right.

How about _length ? (Similar to the already used _arguments)

--anders
March 02, 2005
Re: $ instead of length
"Anders F Björklund" <afb@algonet.se> wrote in message 
news:d052rf$gbm$1@digitaldaemon.com...
> Walter wrote:
>
>> 4) Change length to another identifier. Nothing stands out as being
>> obviously right.
>
> How about _length ? (Similar to the already used _arguments)
>
> --anders

I like that. Some pluses and minuses:
+ indicates the identifier is special (prevents people from looking for a 
non-existant variable called "length")
+ precendent for using _identifier (as you mention)
+ is greppable
- looks uglier than length
- _length is more likely to be used in regular code than _arguments and 
_argptr

Given that it isn't *that* much uglier I think the pluses outweight the 
minuses.
March 02, 2005
Re: $ instead of length
Walter wrote:
> [Starting a new thread on this, because the original is old and wandered off
> topic too far]
> 
> "Derek Parnell" <derek@psych.ward> wrote in message
> news:cu90r1$1e7t$1@digitaldaemon.com...
> 
>>Agreed. I have always supported the use of a symbol rather than an English
>>word to represent the array's length property. I'm keen to promote the
>>readibilty of source code by humans, so an extra 'dot' seems counter
>>productive to that aim.
> 
> 
> 
> The $ idea for the length is a good one. The reason I didn't adopt it was
> because I am trying to save $ for something big. I have a lot of thoughts
> (inspired by some emails from Andrei A.) that $ could be very, very useful
> in a future metaprogramming feature. Using $ as a length is a minor use, too
> minor for such an important symbol!
> 
> So the options are:
> 
> 1) Make it illegal for length within [ ] to hide another length in an outer
> scope. This would essentially preclude length being used as a global, or
> even as a class member.
> 
> 2) Same as (1), but only restrict it if length is a variable local to a
> function.
> 
> 3) Make length a keyword. This is not that much different from (1).
> 
> 4) Change length to another identifier. Nothing stands out as being
> obviously right.
> 
> 5) Invent a token for it that is other than '$'.

Using a single-character token for length has worked well in Euphoria, 
where Rob incorporated it recently. The code gets a lot more readable, 
terse, and tends to decrease errors.

I agree that one should not obstruct the way for Serious improvements to 
the laguage with frivolous introductions of minor things.

Is there any single character other than $ that we could use?

....

A throw-in-the-air idea, what if we used minus ("-")?
March 02, 2005
Re: $ instead of length
Im totally for this , so speciying an offest from the end of an array would
look like


mySlice[0 .. -5];

I remember the argument against this being that its legal C to use a
negative offest for an array .  I can't imagine any noble purpose for it in
C/C++ , and I think it works perfect for the length property in D so lets
rally round the minus!

Charlie


"Georg Wrede" <georg.wrede@nospam.org> wrote in message
news:42261AE9.2080708@nospam.org...
>
>
> Walter wrote:
> > [Starting a new thread on this, because the original is old and wandered
off
> > topic too far]
> >
> > "Derek Parnell" <derek@psych.ward> wrote in message
> > news:cu90r1$1e7t$1@digitaldaemon.com...
> >
> >>Agreed. I have always supported the use of a symbol rather than an
English
> >>word to represent the array's length property. I'm keen to promote the
> >>readibilty of source code by humans, so an extra 'dot' seems counter
> >>productive to that aim.
> >
> >
> >
> > The $ idea for the length is a good one. The reason I didn't adopt it
was
> > because I am trying to save $ for something big. I have a lot of
thoughts
> > (inspired by some emails from Andrei A.) that $ could be very, very
useful
> > in a future metaprogramming feature. Using $ as a length is a minor use,
too
> > minor for such an important symbol!
> >
> > So the options are:
> >
> > 1) Make it illegal for length within [ ] to hide another length in an
outer
> > scope. This would essentially preclude length being used as a global, or
> > even as a class member.
> >
> > 2) Same as (1), but only restrict it if length is a variable local to a
> > function.
> >
> > 3) Make length a keyword. This is not that much different from (1).
> >
> > 4) Change length to another identifier. Nothing stands out as being
> > obviously right.
> >
> > 5) Invent a token for it that is other than '$'.
>
> Using a single-character token for length has worked well in Euphoria,
> where Rob incorporated it recently. The code gets a lot more readable,
> terse, and tends to decrease errors.
>
> I agree that one should not obstruct the way for Serious improvements to
> the laguage with frivolous introductions of minor things.
>
> Is there any single character other than $ that we could use?
>
> ....
>
> A throw-in-the-air idea, what if we used minus ("-")?
March 02, 2005
Re: $ instead of length
On Wed, 2 Mar 2005 10:55:31 -0800, Walter wrote:

> [Starting a new thread on this, because the original is old and wandered off
> topic too far]
> 
> "Derek Parnell" <derek@psych.ward> wrote in message
> news:cu90r1$1e7t$1@digitaldaemon.com...
>> Agreed. I have always supported the use of a symbol rather than an English
>> word to represent the array's length property. I'm keen to promote the
>> readibilty of source code by humans, so an extra 'dot' seems counter
>> productive to that aim.
> 
> 
> The $ idea for the length is a good one. The reason I didn't adopt it was
> because I am trying to save $ for something big. I have a lot of thoughts
> (inspired by some emails from Andrei A.) that $ could be very, very useful
> in a future metaprogramming feature. Using $ as a length is a minor use, too
> minor for such an important symbol!
> 
> So the options are:
> 
> 1) Make it illegal for length within [ ] to hide another length in an outer
> scope. This would essentially preclude length being used as a global, or
> even as a class member.
> 
> 2) Same as (1), but only restrict it if length is a variable local to a
> function.
> 
> 3) Make length a keyword. This is not that much different from (1).
> 
> 4) Change length to another identifier. Nothing stands out as being
> obviously right.
> 
> 5) Invent a token for it that is other than '$'.

I'm still in the '$' camp. Since that symbol was introduced in Euphoria for
this exact purpose, it has become an instant success and has literally
changed the way one thinks about coding things. Using a word to do the same
is always going to clash with something, sometime.

-- 
Derek Parnell
Melbourne, Australia
http://www.dsource.org/projects/build
3/03/2005 7:22:15 AM
March 02, 2005
Re: $ instead of length
Walter wrote:
> [Starting a new thread on this, because the original is old and wandered off
> topic too far]
> 
> "Derek Parnell" <derek@psych.ward> wrote in message
> news:cu90r1$1e7t$1@digitaldaemon.com...
> 
>>Agreed. I have always supported the use of a symbol rather than an English
>>word to represent the array's length property. I'm keen to promote the
>>readibilty of source code by humans, so an extra 'dot' seems counter
>>productive to that aim.
> 
> 
> 
> The $ idea for the length is a good one. The reason I didn't adopt it was
> because I am trying to save $ for something big. I have a lot of thoughts
> (inspired by some emails from Andrei A.) that $ could be very, very useful
> in a future metaprogramming feature. Using $ as a length is a minor use, too
> minor for such an important symbol!
> 
> So the options are:
> 
> 1) Make it illegal for length within [ ] to hide another length in an outer
> scope. This would essentially preclude length being used as a global, or
> even as a class member.
> 
> 2) Same as (1), but only restrict it if length is a variable local to a
> function.
> 
> 3) Make length a keyword. This is not that much different from (1).
> 
> 4) Change length to another identifier. Nothing stands out as being
> obviously right.
> 
> 5) Invent a token for it that is other than '$'.
> 
> 

I think the only other ASCII symbol left not used in D is @, but it 
looks kinda weird for length. Of course, Unicode is very vast...

_______________________
Carlos Santander Bernal
March 02, 2005
Re: $ instead of length
How about changing the identifier to 'len'?
* Easy to read
* Pretty intuitive to understand
* I can't think of anything to mix it up with
* used by other languages already (e.g. Python)
* MUCH EASIER TO TYPE (Ever found yourself typeing "lenght"?)

Question still is, how to handle it. The cleanest idea that I can come 
with is to really make it a keyword. If you leave it an identifier, it 
needs some special handling that makes the language more complex. One 
more keyword does not hurt anyone. If it breaks any code, it will not do 
it silently.

My proposal would be to leave the property of arrays called "length". 
Inside index espressions, it gives the length of the corresponding 
dimension. (has to be worked out more clearly for ND-arrays) Anywhere 
else it mich still serve as prefix operator, allowing to write 
'len(myarray)' (or even 'len myarray') instead of myarray.length

Greetings,
Norbert



Walter schrieb:
> [Starting a new thread on this, because the original is old and wandered off
> topic too far]
> 
> "Derek Parnell" <derek@psych.ward> wrote in message
> news:cu90r1$1e7t$1@digitaldaemon.com...
> 
>>Agreed. I have always supported the use of a symbol rather than an English
>>word to represent the array's length property. I'm keen to promote the
>>readibilty of source code by humans, so an extra 'dot' seems counter
>>productive to that aim.
> 
> 
> 
> The $ idea for the length is a good one. The reason I didn't adopt it was
> because I am trying to save $ for something big. I have a lot of thoughts
> (inspired by some emails from Andrei A.) that $ could be very, very useful
> in a future metaprogramming feature. Using $ as a length is a minor use, too
> minor for such an important symbol!
> 
> So the options are:
> 
> 1) Make it illegal for length within [ ] to hide another length in an outer
> scope. This would essentially preclude length being used as a global, or
> even as a class member.
> 
> 2) Same as (1), but only restrict it if length is a variable local to a
> function.
> 
> 3) Make length a keyword. This is not that much different from (1).
> 
> 4) Change length to another identifier. Nothing stands out as being
> obviously right.

How about 'len'?
* Easy to read
* Pretty intuitive to understand
* I can't think of anything to mix it up with
* used by other languages already (e.g. Python)
* MUCH EASIER TO TYPE (Ever found yourself typeing "lenght"?)
March 02, 2005
Re: $ instead of length
"Georg Wrede" <georg.wrede@nospam.org> wrote in message
news:42261AE9.2080708@nospam.org...
> A throw-in-the-air idea, what if we used minus ("-")?

Because then array[length - 1] becomes array[- - 1].

:-(
March 02, 2005
Re: $ instead of length
Carlos Santander B. wrote:
> Walter wrote:
> 
>> [Starting a new thread on this, because the original is old and 
>> wandered off
>> topic too far]
>>
>> "Derek Parnell" <derek@psych.ward> wrote in message
>> news:cu90r1$1e7t$1@digitaldaemon.com...
>>
>>> Agreed. I have always supported the use of a symbol rather than an 
>>> English
>>> word to represent the array's length property. I'm keen to promote the
>>> readibilty of source code by humans, so an extra 'dot' seems counter
>>> productive to that aim.
>>
>>
>>
>>
>> The $ idea for the length is a good one. The reason I didn't adopt it was
>> because I am trying to save $ for something big. I have a lot of thoughts
>> (inspired by some emails from Andrei A.) that $ could be very, very 
>> useful
>> in a future metaprogramming feature. Using $ as a length is a minor 
>> use, too
>> minor for such an important symbol!
>>
>> So the options are:
>>
>> 1) Make it illegal for length within [ ] to hide another length in an 
>> outer
>> scope. This would essentially preclude length being used as a global, or
>> even as a class member.
>>
>> 2) Same as (1), but only restrict it if length is a variable local to a
>> function.
>>
>> 3) Make length a keyword. This is not that much different from (1).
>>
>> 4) Change length to another identifier. Nothing stands out as being
>> obviously right.
>>
>> 5) Invent a token for it that is other than '$'.
>>
>>
> 
> I think the only other ASCII symbol left not used in D is @, but it 
> looks kinda weird for length. Of course, Unicode is very vast...

Shi-, er, baloney! That _does_ rise specters about us running up the 
creek with context independent lexing! What's gonna happen in two years?

That kind of suggests #3?
« First   ‹ Prev
1 2 3 4 5
Top | Discussion index | About this forum | D home