View mode: basic / threaded / horizontal-split · Log in · Help
October 22, 2005
It's time to deprecate "array [length]" in favour of "array [$]"
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.
October 22, 2005
Re: It's time to deprecate "array [length]" in favour of "array [$]"
Wow.  I haven't heard any discussion of this in a long time.

I second that movement.

~John Demme


On Fri, 21 Oct 2005 22:30:25 +0000, 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.
October 22, 2005
Re: It's time to deprecate "array [length]" in favour of "array [$]"
John Demme wrote:

> Wow.  I haven't heard any discussion of this in a long time.
> 
> I second that movement.
> 
> ~John Demme
> 
> 
> On Fri, 21 Oct 2005 22:30:25 +0000, 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.

I'm not sure I agree. I can't help finding the contextual binding of length
elegant, and I think it opens the door to making something more general.
Random snippets:

Image image = readImage();
Image upperLeftImage = image[upperLeft..center];
Image centerImage = image[center-3..center+3];

Tree tree = createTree();
doSomething(tree[left..right]);
doSomethingElse(tree[root..right]);

and why not:

char[] string = someText();
char[] args = string[indexOf('(')+1..indexOf(')')];

IMHO, $ feels artificial, and it certainly isn't as self-explanatory as
length to someone that doesn't know D. How many other attributes than
array.length have their own symbol? Or any symbol at all in any context? I
can't think of any right now... (I personally find it ugly too, but that is
a rather weak argument) :)

In the end, I would prefer $ to be depreciated. D doesn't have to become a
new Perl. A programming language should have as few and general features as
possible to become powerful. $ doesn't make the language more powerful. It
merely saves a few keystrokes.

/Oskar
October 22, 2005
Re: It's time to deprecate
In article <djcipj$ilp$1@digitaldaemon.com>, Burton Radons says...
>
>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.

I'm just the opposite.  I'd completely forgotten '$' exists because I've never
used it.  I mich prefer the 'length' convention.


Sean
October 22, 2005
Re: It's time to deprecate "array [length]" in favour of "array [$]"
"Burton Radons" <burton-radons@smocky.com> wrote in message 
news:djcipj$ilp$1@digitaldaemon.com...
> 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.

I hate $.  It doesn't say "length" to me.  You know what does?  "length."  $ 
says "string,"  or maybe "money."  $ doesn't even look pretty enough to be 
in D.

What's wrong with "length" anyway?  So you have to make sure you don't try 
to use a variable named "length" in the same scope.  Oh well.  "length" is 
almost a D standard, that it might as well be a reserved identifier anyway.
October 22, 2005
Re: It's time to deprecate "array [length]" in favour of "array [$]"
Oskar Linde wrote:
> John Demme wrote:
> 
> 
>>Wow.  I haven't heard any discussion of this in a long time.
>>
>>I second that movement.
>>
>>~John Demme
>>
>>
>>On Fri, 21 Oct 2005 22:30:25 +0000, 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.
> 
> 
> I'm not sure I agree. I can't help finding the contextual binding of length
> elegant, and I think it opens the door to making something more general.
> Random snippets:
> 
> Image image = readImage();
> Image upperLeftImage = image[upperLeft..center];
> Image centerImage = image[center-3..center+3];

That leaves code fragile to changes in the class, or even in a base 
class which you're not under control of.  No error will be reported, but 
the meaning of the code will be altered.  This problem also exists in 
member functions, of course, but everything is centralised there.

This is why I never use "with" anymore; at some point it always seems to 
produce fragile base class problems.  And I'm one person!  I can't 
imagine how problematic that would get with a team, or with multiple 
teams working together, or with a program over five years old.

> Tree tree = createTree();
> doSomething(tree[left..right]);
> doSomethingElse(tree[root..right]);
> 
> and why not:
> 
> char[] string = someText();
> char[] args = string[indexOf('(')+1..indexOf(')')];

And now it's fragile to what you've imported, great!  What do I do if 
there are suddenly conflicts?  Do I have to retcon what may be hundreds 
or thousands of function calls?  Can you guarantee that the sad sack 
maintainer having to do that will do it right each and every time?

> IMHO, $ feels artificial, and it certainly isn't as self-explanatory as
> length to someone that doesn't know D. How many other attributes than
> array.length have their own symbol? Or any symbol at all in any context? I
> can't think of any right now... (I personally find it ugly too, but that is
> a rather weak argument) :)

What a person learning D thinks is irrelevant, all that's important is 
what a person using D thinks.

> In the end, I would prefer $ to be depreciated. D doesn't have to become a
> new Perl. A programming language should have as few and general features as
> possible to become powerful. $ doesn't make the language more powerful. It
> merely saves a few keystrokes.

Do not put words in my mouth.  I don't prefer $ because it's shorter (I 
never use abbreviations in my function names, for example), I prefer it 
because it has one single meaning and the alternative has been a 
consistent cause of bugs over the last year.  I don't really care what 
the symbol is.  Making length an actual keyword would also be fine.

Having one additional symbol to C doesn't make a language a Perl.  Don't 
use stupid arguments.
October 22, 2005
Re: It's time to deprecate
Sean Kelly wrote:
> In article <djcipj$ilp$1@digitaldaemon.com>, Burton Radons says...
> 
>>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.
> 
> 
> I'm just the opposite.  I'd completely forgotten '$' exists because I've never
> used it.  I mich prefer the 'length' convention.
> 
> 
> Sean
> 
> 
Ditto. I've didn't like '$' when it was first proposed and I don't like 
it now. Making 'length' a keyword is a much nicer solution, IMO.
October 22, 2005
Re: It's time to deprecate
Mike Parker wrote:
> Sean Kelly wrote:
> 
>> In article <djcipj$ilp$1@digitaldaemon.com>, Burton Radons says...
>>
>>> 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.
>>
>>
>>
>> I'm just the opposite.  I'd completely forgotten '$' exists because 
>> I've never
>> used it.  I mich prefer the 'length' convention.
>>
>>
>> Sean
>>
>>
> Ditto. I've didn't like '$' when it was first proposed and I don't like 
> it now. Making 'length' a keyword is a much nicer solution, IMO.

A consequence of that would be the need for special handling of "length" 
member functions and variables for array structures.

I've argued before that all the C type languages have it wrong - 
keywords should be distinct from identifiers.  The way it is now just 
causes problems, such as, say, changing a common identifier into a 
keyword and breaking five years of code.  Languages, like software, 
should be designed with the expectation of change.
October 22, 2005
Re: It's time to deprecate "array [length]" in favour of "array [$]"
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.

How is "length" any different than "sizeof" "ptr" "dup" "reverse" and 
"sort" ?

Here's what I suggest:

1) While 'length' is good, I wouldn't mind subsituting it for 'len'

2) I don't think we should waste the '$' symbol just for length, why not 
spread it across all properties to be consistent?

array.$len
array.$ptr
array.$reverse
array.$sort

Here's a good thread so we don't repeat too much previous discussions.
http://www.digitalmars.com/d/archives/digitalmars/D/17942.html
October 22, 2005
Re: It's time to deprecate "array [length]" in favour of "array [$]"
Jarrett Billingsley wrote:
> "Burton Radons" <burton-radons@smocky.com> wrote in message 
> news:djcipj$ilp$1@digitaldaemon.com...
> 
>>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.
> 
> 
> I hate $.  It doesn't say "length" to me.  You know what does?  "length."  $ 
> says "string,"  or maybe "money."  $ doesn't even look pretty enough to be 
> in D.
> 
> What's wrong with "length" anyway?  So you have to make sure you don't try 
> to use a variable named "length" in the same scope.  Oh well.  "length" is 
> almost a D standard, that it might as well be a reserved identifier anyway. 
> 
> 

I must be a freak, because for me the '$' absolutely screams 'length'.  But maybe that's 
from too much time spent on White-descendant platforms, such as Tiny, Lambda, and ColdC, 
where the expression:
# someList[1..$]

Is identical to D's:
# someList[0..$]

-- Chris Sauls
« First   ‹ Prev
1 2 3 4
Top | Discussion index | About this forum | D home