[OT] The Usual Arithmetic Confusions
Nick Treleaven
nick at geany.org
Sun Jan 30 17:53:17 UTC 2022
On Saturday, 29 January 2022 at 12:23:28 UTC, Siarhei Siamashka
wrote:
> So that `a[i % a.length]` has no performance disadvantages
> compared to `a[i]`. My guess is that the D language design in
> this alternative reality would define arrays indexing as a
> modular operation and consider the "memory safety" goal
> perfectly achieved (no out of bounds accesses, yay!). Ignoring
> the fact that landing on a wrong array index is a source of all
> kind of hard to debug problems, leading to wrong computations
> or even security vulnerabilities.
I doubt that. There are many things in the design of D and Phobos
that prevent bugs that aren't related to memory safety, sometimes
even at the expense of efficiency. E.g. initializing integers by
default is not necessary for @safe, even though in certain
unoptimizable cases initialization is unnecessary and slower.
Override the default when necessary. As with bound checks by
default, this is the best design.
More information about the Digitalmars-d
mailing list