Fun surprising things

Jonathan M Davis newsgroup.d at jmdavisprog.com
Thu Nov 1 05:57:40 UTC 2018


On Wednesday, October 31, 2018 10:58:55 PM MDT Neia Neutuladh via 
Digitalmars-d wrote:
> Except that's only applicable if the spec doesn't define the appropriate
> order of evaluation.

The spec defines left-to-right evaluation, but since _most_ programming
languages don't define the order of evaluation so that the compiler can
efficiently reorder operations, I'd honestly argue that it's just plain bad
practice in general to rely on the order of evaluation of expressions like
this. It's the sort of thing that's just begging for trouble. Sure, if D
defines it, plays by its own rules properly, you understand its rules
properly, and you write your code accordingly, you can theoretically avoid
problems, but if you get in the habit of writing such code, you're just
begging to shoot yourself in the foot as soon as you have to write code in
any other language. And even within D, if the expression is complicated, the
exact order of operations can get hard to understand. So, writing anything
that's even vaguely like foo() + bar() where foo() or bar() depend on one
another at all is just asking for it. It's a code smell, and it should be
avoided.

- Jonathan M Davis





More information about the Digitalmars-d mailing list