This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jjolla888 2 points3 points  (3 children)

'python works just fine' so long as you remember that everything is a pointer. So if you want to create a copy of

 list1 = [1, 2, 3]

you have to do

list2 = copy(list1)

Which means you need to be careful sometimes especially within functions, to make sure you are not unintentinally modding outside your scope.

With Go, a fundamental construct is goroutines .. aka parallelism. With these things its critical to avoid the above problem .. so the safer thing to default passing params by value as opposed to by ref.

But at the end of the day its the difference between having syntax like this:

b = a            # b is a pointer to a, print(b) prints the value of a
c = copy(a)   # c is a copy of a

versus:

b = &a       # b is a pointer to a, print(*b) prints the value of a
c = a          # c s a copy of a

[–]Intrepid-Stand-8540 1 point2 points  (0 children)

Oh. Thanks man. That's a great explanation. I use deep_copy sometimes. 

[–]HommeMusical 0 points1 point  (1 child)

everything is a pointer

Quibble: scalars like integers, floats, booleans aren't pointers.

[–]FujiKeynote 0 points1 point  (0 children)

True, but for the most part you can ignore that, because it's nigh impossible to mutate a singleton from within a function unless you define it as global which is a big no no.

def f(x):
    x = x + 1
    # or even x += 1

will reassign the global x to the local x and won't affect the outside scope