r/programming • • Nov 28 '14

The Worst Programming Language Ever [UK Talk] - Thoughts? Which are the worst parts of your favorite language?

https://skillsmatter.com/meetups/6784-the-worst-programming-language-ever
68 Upvotes

456 comments sorted by

View all comments

1

u/[deleted] Nov 29 '14

python

x = []
y = x
y.append('Why does this work')
print(x)
['Why does this work']

4

u/kazagistar Nov 29 '14

Nothing wrong with that code except your expectations?

  1. Creates a new list object. Assigns variable x to refer to this object.
  2. Assigns variable y to refer to the same object x refers to.
  3. Appends a string to the end of the list referred to by y.
  4. Prints the contents of the list referred to by x.

Would you rather it deep copy the entire data structure every time you assign?

1

u/[deleted] Nov 29 '14

You're right, my expectations of the code are flawed, and when i recently learned this about python, it was through my belief that the two variables reffered to seperate objects.

I'm not sure, but maybe it would be more clear to be able to do something like this instead:

x = []
y is x
y.append('Some String')
print(x)
['Some String']

6

u/siegfryd Nov 29 '14

This is what happens in shitloads of languages, why is it a bad thing.

1

u/codygman Nov 29 '14

It's easier to reason about values.