digitalmars.D - rationale: [] and ()
- Manfred_Nowak (7/7) Dec 10 2010 What is the rationale for having both: normal and square brackets?
- Simen kjaeraas (9/15) Dec 10 2010 Mostly that C has both. Changing this would make the language feel rathe...
- Steven Schveighoffer (4/8) Dec 10 2010 er.. make that O(lg(n)) :) Essentially sub-linear.
- Simen kjaeraas (4/13) Dec 10 2010 Ah, yes. Sorry.
- Manfred_Nowak (6/7) Dec 10 2010 ... and I meant "_constant_ runtime in case of arrays".
What is the rationale for having both: normal and square brackets? I ask because in plain old C I interpreted the lexical difference of funtion calls and accesses to elements of arrays as a permanent hint for linear runtime in case of arrays. But because of `opIndex' this assumption has been invalidated a long time ago. -manfred
Dec 10 2010
Manfred_Nowak <svv1999 hotmail.com> wrote:What is the rationale for having both: normal and square brackets?Mostly that C has both. Changing this would make the language feel rather more different from C/C++ than it already does. It is also syntactic sugar for element lookup. Rather than having to write some function name (that may or may not be the same for all collections), you can use [].I ask because in plain old C I interpreted the lexical difference of funtion calls and accesses to elements of arrays as a permanent hint for linear runtime in case of arrays. But because of `opIndex' this assumption has been invalidated a long time ago.No it hasn't. opIndex should still be O(1), it just can't be enforced. -- Simen
Dec 10 2010
On Fri, 10 Dec 2010 09:42:51 -0500, Simen kjaeraas <simen.kjaras gmail.com> wrote:Manfred_Nowak <svv1999 hotmail.com> wrote:er.. make that O(lg(n)) :) Essentially sub-linear. -SteveBut because of `opIndex' this assumption has been invalidated a long time ago.No it hasn't. opIndex should still be O(1), it just can't be enforced.
Dec 10 2010
Steven Schveighoffer <schveiguy yahoo.com> wrote:On Fri, 10 Dec 2010 09:42:51 -0500, Simen kjaeraas <simen.kjaras gmail.com> wrote:Ah, yes. Sorry. -- SimenManfred_Nowak <svv1999 hotmail.com> wrote:er.. make that O(lg(n)) :) Essentially sub-linear.But because of `opIndex' this assumption has been invalidated a long time ago.No it hasn't. opIndex should still be O(1), it just can't be enforced.
Dec 10 2010
Steven Schveighoffer wrote:Essentially sub-linear.... and I meant "_constant_ runtime in case of arrays". BTW: did you notice, that the modell assumption of an access time independent from the total length of a used slice of memory seems to become wrong? -manfred
Dec 10 2010