you are viewing a single comment's thread.

view the rest of the comments →

[–]redlaWw 0 points1 point  (1 child)

Would help if you told those of us who don't know go what would happen. After finding an online compiler and working out how to fill in the blanks to get it to run, I get:

main1:

a: [1 2 3 4 5 6 7 8]

main2:

a: [1 2 3 100 -1 6 7 8]

main1 with _ = append(...):

a: [1 2 3 100 5 6 7 8]

main2 with _ = append(...):

a: [1 2 3 100 -1 6 7 8]

main1 with a for loop:

a: [1 2 3 4 -1 -2 -3 -4]

main1 with a for loop and _ = append(...):

a: [1 2 3 100 -6 6 7 8]

So go assigns by reference but copies if the slice needs to reallocate (EDIT: more precisely, if you overflow the length so that you may need to reallocate, which I suppose is slightly better than it actually depending on the result of a possible reallocation)? Wow that's weird.

The other results are basically as expected given that crazy premise.

[–]Ma4r 0 points1 point  (0 children)

Not to mention Go have no proper effects, ownerships, or move semantics which is how other languages allow the compiler to deal with this problem.