digitalmars.D - what was the problem with length prop ?
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (5/5) Mar 04 2005 Maybe I missed it, but what was the problem
- Unknown W. Brackets (13/20) Mar 04 2005 int[] something(int length, int init)
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (8/24) Mar 04 2005 No, not the overloading... What I meant was:
- Unknown W. Brackets (8/19) Mar 04 2005 Forgive me; I indeed misunderstood.
- Ben Hinkle (5/23) Mar 04 2005 Given that C++ and Java have the same issue and neither of those languag...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (3/10) Mar 04 2005 So just use a temp ? Too much sugar is not good for you, anyway :-)
- Regan Heath (17/26) Mar 04 2005 This just occured to me...
- Derek Parnell (10/20) Mar 04 2005 It is not *needed*. It just makes reading and writing code easier and le...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (10/18) Mar 04 2005 I'm not sure that this whole thread and Kris's problems with
- Manfred Nowak (7/8) Mar 04 2005 The start of the discussion on the reason seems to be here:
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (6/10) Mar 04 2005 Ah, the good ole negative string indexes...
- Derek Parnell (9/19) Mar 04 2005 Are you referring to the ability to reference elements relative to the e...
- Manfred Nowak (22/28) Mar 04 2005 No. This needed ability was and is given by the `.length'-property
- Derek Parnell (30/62) Mar 05 2005 They (that is "costs where[sic] introduced as an argument") were not
- Regan Heath (12/16) Mar 04 2005 [foo.d]
- David Medlock (6/29) Mar 04 2005 Its too bad the with statement doesnt work with arrays:
- David L. Davis (13/18) Mar 04 2005 This looks like a pretty good idea to me!! :) It is clean.
- David Medlock (3/31) Mar 04 2005 With the regex discussion and now using adding a '$' character, I think
Maybe I missed it, but what was the problem with just using the .length array property ? Something about templates, or what was it ? Where was the $ / keyword *needed*, examples ? --anders
Mar 04 2005
int[] something(int length, int init) { int[] array; array.length = length; array[0 .. length - 1] = init; return array; } The "length" parameter is hidden within the array... meaning, on this line: array[0 .. length - 1] = init; The "length" could mean two different things. It's only within slices that it's a problem. In this example, it's not a problem... but it could easily be one. -[Unknown]Maybe I missed it, but what was the problem with just using the .length array property ? Something about templates, or what was it ? Where was the $ / keyword *needed*, examples ? --anders
Mar 04 2005
Unknown W. Brackets wrote:int[] something(int length, int init) { int[] array; array.length = length; array[0 .. length - 1] = init; return array; } The "length" parameter is hidden within the array... meaning, on this line: array[0 .. length - 1] = init; The "length" could mean two different things. It's only within slices that it's a problem.No, not the overloading... What I meant was: Why wasn't the above code instead written as: array.length = length; array[0 .. array.length - 1] = init; Where is the name of the array not known ? (in what circumstances, I've heard "templates") --anders
Mar 04 2005
Forgive me; I indeed misunderstood. It's not, as far as I know. Just syntactical sugar... but, it is fairly nice sugar. Consider: Airport.getFromHangar(AIRPLANE_747).optionalComponents["seatbelts"][length - 5 .. length] Okay, strange example, but it's nice to have. That said, you're right: I don't believe there's any specific need for it. -[Unknown]No, not the overloading... What I meant was: Why wasn't the above code instead written as: array.length = length; array[0 .. array.length - 1] = init; Where is the name of the array not known ? (in what circumstances, I've heard "templates") --anders
Mar 04 2005
In article <d0997e$l22$1 digitaldaemon.com>, Unknown W. Brackets says...Forgive me; I indeed misunderstood. It's not, as far as I know. Just syntactical sugar... but, it is fairly nice sugar. Consider: Airport.getFromHangar(AIRPLANE_747).optionalComponents["seatbelts"][length - 5 .. length] Okay, strange example, but it's nice to have. That said, you're right: I don't believe there's any specific need for it.Given that C++ and Java have the same issue and neither of those languages have a special 'length' and I've never heard anyone request one, I don't think this use case will come up enough to make the special 'length' worth it. But that's just me...No, not the overloading... What I meant was: Why wasn't the above code instead written as: array.length = length; array[0 .. array.length - 1] = init; Where is the name of the array not known ? (in what circumstances, I've heard "templates") --anders
Mar 04 2005
Unknown W. Brackets wrote:It's not, as far as I know. Just syntactical sugar... but, it is fairly nice sugar. Consider: Airport.getFromHangar(AIRPLANE_747).optionalComponents["seatbelts"][length - 5 .. length] Okay, strange example, but it's nice to have.So just use a temp ? Too much sugar is not good for you, anyway :-) --anders
Mar 04 2005
On Fri, 04 Mar 2005 14:01:35 +0100, Anders F Björklund <afb algonet.se> wrote:Unknown W. Brackets wrote:This just occured to me... (assuming we remove the special length syntactical sugar) void foo(char[] array) { array.length = array.length + 2; } ... char[] array; ... int length = array.length; if (foo(array) && b = array[0..length]) {} Basically length becomes invalidated when foo is called, and is incorrect (or maybe it's actually correct) in the b = assignment. Sure, the above example is contrived, it may also be rare, not sure. All I know is that it's 'possible'. ReganIt's not, as far as I know. Just syntactical sugar... but, it is fairly nice sugar. Consider: Airport.getFromHangar(AIRPLANE_747).optionalComponents["seatbelts"][length - 5 .. length] Okay, strange example, but it's nice to have.So just use a temp ? Too much sugar is not good for you, anyway :-)
Mar 04 2005
On Fri, 04 Mar 2005 10:14:27 +0100, Anders F Björklund wrote: [snip]No, not the overloading... What I meant was: Why wasn't the above code instead written as: array.length = length; array[0 .. array.length - 1] = init; Where is the name of the array not known ? (in what circumstances, I've heard "templates")It is not *needed*. It just makes reading and writing code easier and less costly. Just as 'for', 'foreach', 'switch', 'while', slices, etc... are not needed, but they sure make code development less troublesome. -- Derek Parnell Melbourne, Australia 4/03/2005 10:44:05 PM
Mar 04 2005
Derek Parnell wrote:It is not *needed*. It just makes reading and writing code easier and less costly.I'm not sure that this whole thread and Kris's problems with "length" variables qualifies as "less costly", but anyway...Just as 'for', 'foreach', 'switch', 'while', slices, etc... are not needed, but they sure make code development less troublesome.Yup, maybe something good can come out of this long debate ? And that the length var hack somehow can disappear from arrays. http://www.digitalmars.com/d/changelog.html#new099:What's New for D 0.99 Aug 19, 2004[...]* Added implicit declaration of length to index and slice expressions. This will break existing code if length is used as a variable within [ ].Until then, array.length sounds like the safe bet. (still waiting for the reason it was introduced ?) --anders
Mar 04 2005
Anders F Björklund <afb algonet.se> wrote: [...](still waiting for the reason it was introduced ?)The start of the discussion on the reason seems to be here: http://www.digitalmars.com/drn-bin/wwwnews?D/24082 And I still think, that this property of arrays is as much needed by us, as bicycles are needed by fish. -manfred
Mar 04 2005
Manfred Nowak wrote:Ah, the good ole negative string indexes... Just like momma Perl used to make them. :-) a = (0..9); b = a[0,1,-2,-1]; print b; Prints: 0189 --anders(still waiting for the reason it was introduced ?)The start of the discussion on the reason seems to be here: http://www.digitalmars.com/drn-bin/wwwnews?D/24082
Mar 04 2005
On Fri, 4 Mar 2005 19:36:01 +0000 (UTC), Manfred Nowak wrote:Anders F Björklund <afb algonet.se> wrote: [...]Are you referring to the ability to reference elements relative to the end of an array? It is not needed in the same sense that we don't need 'for', 'foreach', 'while', 'switch', etc ... There are other ways of achieving the same thing, but at the cost of more obscure code and potentially more bugs. -- Derek Parnell Melbourne, Australia 5/03/2005 8:55:38 AM(still waiting for the reason it was introduced ?)The start of the discussion on the reason seems to be here: http://www.digitalmars.com/drn-bin/wwwnews?D/24082 And I still think, that this property of arrays is as much needed by us, as bicycles are needed by fish.
Mar 04 2005
Derek Parnell <derek psych.ward> wrote: [...]Are you referring to the ability to reference elements relative to the end of an array?No. This needed ability was and is given by the `.length'-property of arrays. I am referring to the shortcut of this property, denoted by the quasi-keyword `length' --- or whatever it will be in the future.It is not needed in the same sense that we don't need 'for', 'foreach', 'while', 'switch', etc ... There are other ways of achieving the same thing, but at the cost of more obscure code and potentially more bugs.I did not follow that discussion to the end. However, if costs where introduced as an argument 1) how have they been defined? 2) why where the cases that led to this new outbreak of the discussion not included? 3) please show, that under that cost measure there is no problem size, i.e. a natural number "n", for which the relative saving of costs becomes neglectable. Where for example "n" is defined to be the dimension of a "n"-dimensional cuboid array, which has to be reduced into the maximal "n"-dimensional cubed array, that fits into the original cuboid array. 4) if you cannot prove number 3), please admit, that your statement is wrong, that those well known and accepted elements of blöck- structured programming, `while' etc., are comparable to the shortcut, which is in question here. -manfed
Mar 04 2005
On Sat, 5 Mar 2005 01:37:09 +0000 (UTC), Manfred Nowak wrote:Derek Parnell <derek psych.ward> wrote: [...]They (that is "costs where[sic] introduced as an argument") were not introduced as an argument, therefore the costs were not defined.Are you referring to the ability to reference elements relative to the end of an array?No. This needed ability was and is given by the `.length'-property of arrays. I am referring to the shortcut of this property, denoted by the quasi-keyword `length' --- or whatever it will be in the future.It is not needed in the same sense that we don't need 'for', 'foreach', 'while', 'switch', etc ... There are other ways of achieving the same thing, but at the cost of more obscure code and potentially more bugs.I did not follow that discussion to the end. However, if costs where introduced as an argument 1) how have they been defined?2) why where the cases that led to this new outbreak of the discussion not included?Just bad luck, I guess. Maybe I'm too lazy. Maybe I'm too arrogant? Maybe I ran out of time 'cos I had to go shopping with my wife to get our weekly groceries, two new shirts, a BNC-RCA adaptor for an old VCR I'm trying to hook up to the new digital TV, a birthday gift for my daughter, ... in short I've got a life.3) please show, that under that cost measure there is no problem size, i.e. a natural number "n", for which the relative saving of costs becomes neglectable. Where for example "n" is defined to be the dimension of a "n"-dimensional cuboid array, which has to be reduced into the maximal "n"-dimensional cubed array, that fits into the original cuboid array.Sure! 42 ;-)4) if you cannot prove number 3), please admit, that your statement is wrong, that those well known and accepted elements of blöck- structured programming, `while' etc., are comparable to the shortcut, which is in question here.I cannot prove (3). Mainly because I can't understand (3). And I do not admit that my statement was wrong. BTW, what was my statement? Was it "There are other ways of achieving the same thing, but at the cost of more obscure code and potentially more bugs."? This was made in the context of the 'for' etc line. These would otherwise be implemented with GOTO statements mainly and I think the literature is generally of the opinion that GOTO is a cause of more costly software. In the same manner, I, me, myself, personally, moi, is of the opinion that a small token of one or two characters, that represents a reference to the end of an array, is easier to write, read and absorb, than longer ways to do the same thing. I'll try to say it clearly this time ... A symbolic reference to the end of an array by a *short* token is better for software developers than a *longer* token. The only 'proof' I have is personal experience. I'm embarrassed that you find that lacking in credibility.-manfedWTFWT? -- Derek Parnell Melbourne, Australia 5/03/2005 8:49:51 PM
Mar 05 2005
On Fri, 04 Mar 2005 09:47:52 +0100, Anders F Björklund <afb algonet.se> wrote:Maybe I missed it, but what was the problem with just using the .length array property ? Something about templates, or what was it ? Where was the $ / keyword *needed*, examples ?[foo.d] int length = 5; void main() { int length = 6; char[] s; s.length = 7; s[0..length-1]; // what is the value of the end index? } Regan
Mar 04 2005
Regan Heath wrote:On Fri, 04 Mar 2005 09:47:52 +0100, Anders F Björklund <afb algonet.se> wrote:Its too bad the with statement doesnt work with arrays: int []a = new int[100]; int []x; with(a) x[0..length] = a[0..length]; Looks pretty clean to me.Maybe I missed it, but what was the problem with just using the .length array property ? Something about templates, or what was it ? Where was the $ / keyword *needed*, examples ?[foo.d] int length = 5; void main() { int length = 6; char[] s; s.length = 7; s[0..length-1]; // what is the value of the end index? } Regan
Mar 04 2005
In article <d09mi9$12o0$1 digitaldaemon.com>, David Medlock says...Its too bad the with statement doesnt work with arrays: int []a = new int[100]; int []x; with(a) x[0..length] = a[0..length]; Looks pretty clean to me.This looks like a pretty good idea to me!! :) It is clean. In fact, up until about a couple of months ago I didn't even know that a[ 0 .. length ] (using length in the array brackets was the same as array.length) was even allowed, so I've always just coded a[ 0 .. a.length ] instead. (Guess my code is pretty safe this area, whether "length" ends up being disallowed, or if we're going to use the "$" as its replacement). But I do feel we should save the "$" symbol / character tho, for something much more important down the road for use in D's future development. I'm not sure at this point what that might be, but I'm very sure something will need it. :) David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
Mar 04 2005
David L. Davis wrote:In article <d09mi9$12o0$1 digitaldaemon.com>, David Medlock says...With the regex discussion and now using adding a '$' character, I think the Perl people have infiltrated this newsgroup...Its too bad the with statement doesnt work with arrays: int []a = new int[100]; int []x; with(a) x[0..length] = a[0..length]; Looks pretty clean to me.This looks like a pretty good idea to me!! :) It is clean. In fact, up until about a couple of months ago I didn't even know that a[ 0 .. length ] (using length in the array brackets was the same as array.length) was even allowed, so I've always just coded a[ 0 .. a.length ] instead. (Guess my code is pretty safe this area, whether "length" ends up being disallowed, or if we're going to use the "$" as its replacement). But I do feel we should save the "$" symbol / character tho, for something much more important down the road for use in D's future development. I'm not sure at this point what that might be, but I'm very sure something will need it. :) David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
Mar 04 2005