rationale: [] and ()

Simen kjaeraas simen.kjaras at gmail.com
Fri Dec 10 06:42:51 PST 2010


Manfred_Nowak <svv1999 at 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


More information about the Digitalmars-d mailing list