digitalmars.D - Duplicate keys in array literals?
- bearophile (20/20) Nov 28 2013 Is it a good idea to silently statically accept duplicated keys
- Daniel Murphy (3/5) Nov 28 2013 Looks like a bug to me.
- luka8088 (4/31) Nov 28 2013 PHP also allows it:
- Jacob Carlborg (5/8) Nov 28 2013 Arrays are a weird beast in PHP. They're both arrays and associative
- luka8088 (4/15) Nov 28 2013 They are associative array which can emulate array like behavior. But
- Denis Shelomovskij (5/24) Nov 28 2013 File the issue please.
- bearophile (9/10) Nov 28 2013 I have opened an issue, currently it's not an enhancement request:
Is it a good idea to silently statically accept duplicated keys in both dynamic array literals and in associative array literals? void main() { int[] a = [0:10, 0:20]; int[int] aa = [0:10, 0:20]; } I don't remember having ever had the need for this, and on the other hand I have had some mistakes like this in my D code not caught statically by the compiler. ----------------------- Note that in this post I am not discussing about inserting multiple times a key-pair in an associative array, this is normal and useful: void main() { int[int] aa; aa[0] = 10; aa[0] = 20; } Bye, bearophile
Nov 28 2013
"bearophile" <bearophileHUGS lycos.com> wrote in message news:befwnwpitihpcjfbdarl forum.dlang.org...Is it a good idea to silently statically accept duplicated keys in both dynamic array literals and in associative array literals?Looks like a bug to me.
Nov 28 2013
On 28.11.2013. 12:23, bearophile wrote:Is it a good idea to silently statically accept duplicated keys in both dynamic array literals and in associative array literals? void main() { int[] a = [0:10, 0:20]; int[int] aa = [0:10, 0:20]; } I don't remember having ever had the need for this, and on the other hand I have had some mistakes like this in my D code not caught statically by the compiler. ----------------------- Note that in this post I am not discussing about inserting multiple times a key-pair in an associative array, this is normal and useful: void main() { int[int] aa; aa[0] = 10; aa[0] = 20; } Bye, bearophilePHP also allows it: $data = array('a' => 1, 'a' => 2); And I find it to be only a source of bugs.
Nov 28 2013
On 2013-11-28 18:55, luka8088 wrote:PHP also allows it: $data = array('a' => 1, 'a' => 2); And I find it to be only a source of bugs.Arrays are a weird beast in PHP. They're both arrays and associative arrays, at the same time, somehow. -- /Jacob Carlborg
Nov 28 2013
On 28.11.2013. 21:01, Jacob Carlborg wrote:On 2013-11-28 18:55, luka8088 wrote:They are associative array which can emulate array like behavior. But unfortunately that has also in my experience turned out to be just another source of bugs.PHP also allows it: $data = array('a' => 1, 'a' => 2); And I find it to be only a source of bugs.Arrays are a weird beast in PHP. They're both arrays and associative arrays, at the same time, somehow.
Nov 28 2013
28.11.2013 15:23, bearophile пишет:Is it a good idea to silently statically accept duplicated keys in both dynamic array literals and in associative array literals? void main() { int[] a = [0:10, 0:20]; int[int] aa = [0:10, 0:20]; } I don't remember having ever had the need for this, and on the other hand I have had some mistakes like this in my D code not caught statically by the compiler. ----------------------- Note that in this post I am not discussing about inserting multiple times a key-pair in an associative array, this is normal and useful: void main() { int[int] aa; aa[0] = 10; aa[0] = 20; } Bye, bearophileFile the issue please. -- Денис В. Шеломовский Denis V. Shelomovskij
Nov 28 2013
Denis Shelomovskij:File the issue please.I have opened an issue, currently it's not an enhancement request: https://d.puremagic.com/issues/show_bug.cgi?id=11637 In that issue I have also added more explanations and more code examples, with an extra small discussion about arrays with strongly typed indexes, that I have never stopped missing in D, being used to them since Delphi. Bye, bearophile
Nov 28 2013