FWIW, Python 3 improves case 1 to:
a, b, c, *_ = list
better, you can put the slice at at any point of the left hand, so if you want the first and last elements of your list (and want to ignore everything else) you can write: a, *_, b = listCatch an exception of something that isn't exceptional? isn't that the anti-case for exception handling?
I don't get why strict restructuring is a bad thing... as long as it's consistant, it's just a nuance of the language.
Am I missing side effect of this? What are potential pit-falls of this pattern?
I was arguing that non-strict destructuring is bad, so this code IMHO should throw exception:
a,b,c=[1,2,3,4]
The reason for this is - if you assume array has 3 elements, but it has more, your code will silently ignore the rest. You'll have to write your assertion every time you destructure, to be sure that destructuring don't ignore data. The exceptional case IMHO is when you need to ignore data, and so code for this case should be uglier, not the other way around. You are right that catching exception for regular code path isn't the best way, but at least programmer intention is clear then.You could also do
a,b,c = list.slice(0,3);
which copies the array, but at least it's clear what it assumes about the array. And it can be easily modified to get last 3 values, or 3 values from the middle of list. So no need for 2 idioms depending on which items you want to get from the array.
I like Python solution there:
Also when I do I get "ValueError: too many values to unpack" as it should be - you can always catch the exception and ignore it, if your code really don't care.