And, just as an addendum: IMO, if the result depends on the order of
operations in a statement, prefer to rewrite it. Like, even if you are
satisfied with the behavior you are seeing *and* you can rely on it - it
should be clear by now that anyone looking at it will have to expand new
effort understanding it (and, you know, there might still be bugs in the
future). Rewriting the function call into its own statement gets rid of the
ambiguity and makes clear what's happening either way.

On Wed, Jan 15, 2020 at 8:25 PM Paul Jolly <p...@myitcv.io> wrote:

> >   "when evaluating the operands of an expression, assignment, or return
> statement, all function calls, method calls, and communication operations
> are evaluated in lexical left-to-right order."
>
> My understanding goes as follows: the operands of the return statement
> are i and modify(&i). The comma after "return statement" in the above
> sentence is then important: because the only "function calls, method
> calls, and communication operations" in that list of operands are (is)
> modify(&i).
>
> Hence when i (as in the first operand) is evaluated is not specified.
> And therefore it's dangerous to rely on it being one value or another
> (which it could be given the example you provide).
>
> There was even some discussion at the London Gophers November 2019
> meetup (where the conundrum was very related
>
> https://docs.google.com/presentation/d/e/2PACX-1vQ07uP_ldnSYzpaNb5AlZZ-_tL2mZuoNfQgxvsTKSM4aglYR-nuvyrZ8nK__r3YQTo1vqH-Hmax3aXs/pub?slide=id.g6239d05d0e_0_1
> )
> about whether it would be possible to statically flag potential errors
> like this.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CACoUkn7KA0Z-TDypdvM%3Du%3DyVPHuHFmtD%3DiTV2c98Vm%3Dqn4NcPw%40mail.gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfEFS7WHJn7zftKDkE6%2BatUi19bb8jMFz-A8ONpV5k%3DpvQ%40mail.gmail.com.

Reply via email to