digitalmars.D - $ for length?
- Steve Teale (6/6) Feb 20 2014 How difficult would it be to allow the '$' to be used instead of
- bearophile (5/11) Feb 20 2014 You can vote it:
- w0rp (7/13) Feb 20 2014 I don't like it. It's a small difference in the number of
- Chris (2/19) Feb 20 2014 Why not have both?
- Steve Teale (2/3) Feb 20 2014 I was not suggesting otherwise.
- bearophile (5/7) Feb 20 2014 But such new people find code like: a[$ - 1] so they need to
- Mengu (2/19) Feb 20 2014 well, at least it's not len(ta).
- bearophile (9/10) Feb 20 2014 A free function len() is quite useful if you want to use it in
- Frustrated (2/8) Feb 20 2014 it's ugly, how about ta.opLength = $ta = ta.length?
- Kagamin (3/4) Feb 20 2014 Or #ta - what miniD does. See
- Jesse Phillips (4/8) Feb 20 2014 Comes from Lua. It may or may not represent the number of
- Kagamin (6/12) Feb 20 2014 Early versions of D already had the feature: you could write
- Stanislav Blinov (2/4) Feb 20 2014 Errr, what? http://dlang.org/operatoroverloading.html#Dollar
- Kagamin (5/10) Feb 20 2014 It repeats what I said:
- Jesse Phillips (4/10) Feb 20 2014 My first reaction is disgust, second is I'd probably get use to
How difficult would it be to allow the '$' to be used instead of length in something like: Thing[] ta; for (size_t i = 0; i < ta.$; i++) It can be used in slices, and indexes, so it might well be unambiguous here.
Feb 20 2014
Steve Teale:How difficult would it be to allow the '$' to be used instead of length in something like: Thing[] ta; for (size_t i = 0; i < ta.$; i++) It can be used in slices, and indexes, so it might well be unambiguous here.You can vote it: https://d.puremagic.com/issues/show_bug.cgi?id=7840 Bye, bearophile
Feb 20 2014
On Thursday, 20 February 2014 at 10:28:43 UTC, Steve Teale wrote:How difficult would it be to allow the '$' to be used instead of length in something like: Thing[] ta; for (size_t i = 0; i < ta.$; i++) It can be used in slices, and indexes, so it might well be unambiguous here.I don't like it. It's a small difference in the number of characters between the two on a line, and .length is much easier to read, especially for people new to the language. I think given D's smaller userbase, anything which makes a line of code easier to read for people coming from other languages without getting in the way of other things is a bonus.
Feb 20 2014
On Thursday, 20 February 2014 at 13:17:37 UTC, w0rp wrote:On Thursday, 20 February 2014 at 10:28:43 UTC, Steve Teale wrote:Why not have both?How difficult would it be to allow the '$' to be used instead of length in something like: Thing[] ta; for (size_t i = 0; i < ta.$; i++) It can be used in slices, and indexes, so it might well be unambiguous here.I don't like it. It's a small difference in the number of characters between the two on a line, and .length is much easier to read, especially for people new to the language. I think given D's smaller userbase, anything which makes a line of code easier to read for people coming from other languages without getting in the way of other things is a bonus.
Feb 20 2014
On Thursday, 20 February 2014 at 13:52:20 UTC, Chris wrote:Why not have both?I was not suggesting otherwise.
Feb 20 2014
w0rp:length is much easier to read, especially for people new to the language.But such new people find code like: a[$ - 1] so they need to know the meaning of $. Bye, bearophile
Feb 20 2014
On Thursday, 20 February 2014 at 13:17:37 UTC, w0rp wrote:On Thursday, 20 February 2014 at 10:28:43 UTC, Steve Teale wrote:well, at least it's not len(ta).How difficult would it be to allow the '$' to be used instead of length in something like: Thing[] ta; for (size_t i = 0; i < ta.$; i++) It can be used in slices, and indexes, so it might well be unambiguous here.I don't like it. It's a small difference in the number of characters between the two on a line, and .length is much easier to read, especially for people new to the language. I think given D's smaller userbase, anything which makes a line of code easier to read for people coming from other languages without getting in the way of other things is a bonus.
Feb 20 2014
Mengu:well, at least it's not len(ta).A free function len() is quite useful if you want to use it in higher order functions: map(len, ["red", "yo"]) In D: ["red", "yo"].map!(s => s.length) ["red", "yo"].map!walkLength Bye, bearophile
Feb 20 2014
On Thursday, 20 February 2014 at 10:28:43 UTC, Steve Teale wrote:How difficult would it be to allow the '$' to be used instead of length in something like: Thing[] ta; for (size_t i = 0; i < ta.$; i++) It can be used in slices, and indexes, so it might well be unambiguous here.it's ugly, how about ta.opLength = $ta = ta.length?
Feb 20 2014
On Thursday, 20 February 2014 at 18:35:26 UTC, Frustrated wrote:it's ugly, how about ta.opLength = $ta = ta.length?Or #ta - what miniD does. See http://d.puremagic.com/issues/show_bug.cgi?id=2660
Feb 20 2014
On Thursday, 20 February 2014 at 18:45:49 UTC, Kagamin wrote:On Thursday, 20 February 2014 at 18:35:26 UTC, Frustrated wrote:Comes from Lua. It may or may not represent the number of elements in a table, since we don't want to correlate to those semantics it is probably best to stay away from it.it's ugly, how about ta.opLength = $ta = ta.length?Or #ta - what miniD does. See http://d.puremagic.com/issues/show_bug.cgi?id=2660
Feb 20 2014
On Thursday, 20 February 2014 at 10:28:43 UTC, Steve Teale wrote:How difficult would it be to allow the '$' to be used instead of length in something like: Thing[] ta; for (size_t i = 0; i < ta.$; i++) It can be used in slices, and indexes, so it might well be unambiguous here.Early versions of D already had the feature: you could write arr[0..length], but the feature proved to be ambiguous and was removed. $ is meant to be a special indexing syntax (like two dots), it's not a member, not a length.
Feb 20 2014
On Thursday, 20 February 2014 at 18:39:43 UTC, Kagamin wrote:$ is meant to be a special indexing syntax (like two dots), it's not a member, not a length.Errr, what? http://dlang.org/operatoroverloading.html#Dollar
Feb 20 2014
On Thursday, 20 February 2014 at 18:43:29 UTC, Stanislav Blinov wrote:On Thursday, 20 February 2014 at 18:39:43 UTC, Kagamin wrote:It repeats what I said:$ is meant to be a special indexing syntax (like two dots), it's not a member, not a length.Errr, what? http://dlang.org/operatoroverloading.html#DollarWithin the arguments to array index and slicing operatorsWell, you can't write a.+(b) - that's a difference between syntax and member.
Feb 20 2014
On Thursday, 20 February 2014 at 10:28:43 UTC, Steve Teale wrote:How difficult would it be to allow the '$' to be used instead of length in something like: Thing[] ta; for (size_t i = 0; i < ta.$; i++) It can be used in slices, and indexes, so it might well be unambiguous here.My first reaction is disgust, second is I'd probably get use to it, third is wondering if I would actually use it given the option (probably not).
Feb 20 2014