April 30, 2012 [Issue 481] Letting compiler determine length for fixed-length arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=481 SomeDude <lovelydear@mailmetrash.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |lovelydear@mailmetrash.com --- Comment #10 from SomeDude <lovelydear@mailmetrash.com> 2012-04-30 14:51:42 PDT --- (In reply to comment #8) > (In reply to comment #7) > > This is a very low priority issue. > > Well, I don't agree. It's a language design issue, so its priority is higher than most implementation matters. I fully agree with Walter Bright. Sorry to be blunt here but this whole discussion is absolutely pointless and should be closed as WONTFIX right now. People have better things to do. If some dude can't count the number of elements he puts in his 10 elements array initializer, he'd better stop programming at all. Introducing some strange Perl-like syntax for that is madness. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 01, 2012 [Issue 481] Letting compiler determine length for fixed-length arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=481 --- Comment #11 from bearophile_hugs@eml.cc 2012-04-30 17:04:35 PDT --- (In reply to comment #10) > Sorry to be blunt here but this whole discussion is absolutely pointless and should be closed as WONTFIX right now. People have better things to do. It's relevant, also because there are 6 votes. > If some dude can't count the number of elements he puts in his 10 elements array initializer, he'd better stop programming at all. Introducing some strange Perl-like syntax for that is madness. Thank you for your note, it allows me to better express why this issue relevant. It's not DRY (http://en.wikipedia.org/wiki/DRY ), and duplicated information tends to get out of sync (and this causes bugs). You write (think of a as a longer array): int[5] arr = [1,2,3,4,5]; void main() {} Later you change the code and your remove on item from the literal, but you forget to update the array size on the left: int[5] arr = [1,2,4,5]; void main() {} The compiler gives you no error nor warning, and arr actually contains [1,2,4,5,0]. This is a source of bugs, it has happened to me too. With a syntax like [$] or []S it can't happen, because the length is not stated twice. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 01, 2012 [Issue 481] Letting compiler determine length for fixed-length arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=481 hsteoh@quickfur.ath.cx changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |hsteoh@quickfur.ath.cx --- Comment #12 from hsteoh@quickfur.ath.cx 2012-04-30 17:21:24 PDT --- (In reply to comment #10) [...] > If some dude can't count the number of elements he puts in his 10 elements array initializer, he'd better stop programming at all. Introducing some strange Perl-like syntax for that is madness. You're totally missing the point. Code like this is very prone to bugs: int[5] x = [1,2,3,4,5]; because as soon as somebody edits the list of elements, the count will be wrong. Restating something that the compiler already knows is a bad idea. (The same problem occurs in C/C++; in the C case, depending on the compiler, you may even get a gratuitous array overrun.) The proposed int[$] = [ ... ]; is a very good solution, because $ already means "length of array" in D, and would fit seamlessly into the existing language. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 01, 2012 [Issue 481] Letting compiler determine length for fixed-length arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=481 --- Comment #13 from thelastmammoth@gmail.com 2012-04-30 17:38:59 PDT --- (In reply to comment #11 and comment #12) I agree with the need for some syntactic sugar for static array literal, but is there any scenario where the postfix literal "auto x=[1,2,3]S" (or [1,2,3]f if you prefer) proposed in [Issue 8008] doesn't advantageously replace int[$]x=[1,2,3]? (more generally to force type T in case of ambiguity we can write [cast(T)1,2,3]S but usually not necessary with 1u,1f etc). The advantage of [1,2,3]S over [$] or the current situation being that: 1) we can directly pass a static array to a function without requiring an intermediate static array declaration (int[$]x=[1,2,3]; fun(x); becomes simply fun([1,2,3]S); 2) from my understanding, there is still an intermediate heap allocation with the current int[3]=[1,2,3]; please correct me if I'm wrong), which should be easier to avoid with [1,2,3]S). (As an optional bonus, would it also be easy to implement implicit casts with [...]S ? eg void fun(in double[3] x){...} fun([1,2,3]S); //should do implicit cast to double[3]; //the implicit casts should follow the same rules as for numeric values. ) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
August 11, 2012 [Issue 481] Letting compiler determine length for fixed-length arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=481 --- Comment #14 from bearophile_hugs@eml.cc 2012-08-10 20:03:23 PDT --- A bug I've just found. Originally I was using 20 points, and I needed them in a fixed-size array. Later I have removed some of them to reduce the testing time, but I have forgotten to update the number of items in P[20]. The compiler gives me no compilation errors (it gives errors only if the number is less than the number of given items), the missing array items are filled with P(0,0) by the compiler, the duplicated zero points produce an almost correct result, but not exactly correct, so I have to spend minutes to spot the problem. This is the minimized code, that shows this simple bug the compiler isn't able to find for me: import std.typecons; alias Tuple!(int, int) P; enum P[20] a = [P(62, -67), P(4, -71), P(-86, 71), P(-25, -53), P(-23, 70), P(46, -34), P(-92, -62), P(-15, 89), P(100, 42), P(-4, 43), P(21, 59), P(86, -25), P(93, -52), P(-41, -48), P(-45, 76), P(85, -43), P(-69, 64)]; void main() {} -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 31, 2013 [Issue 481] Letting compiler determine length for fixed-length arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=481 rswhite4@googlemail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rswhite4@googlemail.com --- Comment #15 from rswhite4@googlemail.com 2013-05-31 08:02:10 PDT --- int arr[$] = [1,2,3,4]; // makes an int[4] Looks pretty nice and I wish something like this often. Any chance that we get this in the near future (maybe with 2.064)? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 31, 2013 [Issue 481] Letting compiler determine length for fixed-length arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=481 Shriramana Sharma <samjnaa@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |samjnaa@gmail.com --- Comment #16 from Shriramana Sharma <samjnaa@gmail.com> 2013-05-31 10:37:21 PDT --- FWIW I vote for using int[$] a = [ 1,2,3,4 ] syntax for this. auto[$] would of course also be valid to allow compile-time type inference. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 02, 2013 [Issue 481] Letting compiler determine length for fixed-length arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=481 --- Comment #17 from bearophile_hugs@eml.cc 2013-10-01 18:35:33 PDT --- See also issue 11156 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation