News for hackers. Stuff that matters.
Re:Anti-Patterns in Python Programming by jl6 on Wednesday July 09, 2014 @12:45PM (#8010615)
I'm sorry, I don't see clearly what a tuple should be. What would be different about Python tuples if they were true tuples?
Re:Anti-Patterns in Python Programming by alextgordon on Wednesday July 09, 2014 @06:25PM (#8012566)
In most languages you can't usually:

1. Iterate over a tuple

2. Convert a list to a tuple

3. Construct a tuple of a length not known at compile-time

Python allows these because "why not?" but it does break their "one and only one way to do it" rule and confuses beginners a hell of a lot.

There are definitely borderline cases. For instance, should a Vector be a list or a tuple? A Vec3 type is obviously a tuple, but a large Vector destined for BLAS is obviously a list.

Re:Anti-Patterns in Python Programming by dragonwriter on Wednesday July 09, 2014 @07:31PM (#8012791)
> Python allows these because "why not?"

No, it allows them because the distinction that those restrictions are founded on is only useful in a statically-typed languages, and Python isn't statically typed.

> For instance, should a Vector be a list or a tuple?

A real vector/array should be its own data type (probably implemented in a C, or similar low-level, extension) that happens to implement the interface expected of an indexable, iterable collection, neither a list nor a tuple.

Re:Anti-Patterns in Python Programming by dozzie on Thursday July 10, 2014 @04:18AM (#8014136)
> [this] distinction [...] is only useful in a statically-typed languages

...like Erlang.

Re:Anti-Patterns in Python Programming by dragonwriter on Thursday July 10, 2014 @09:56AM (#8014962)
Yeah, while snarkily made its a good point that Erlang does make use of it without being statically typed.

There is a deep difference that goes beyond use of tuples in language approach between Python and Erlang here where it comes to types in which Erlang, while dynamically typed, has a deep concern for types in its pattern matching system to make path decisions while Python is very much centered on using dynamic OO techniques -- how objects respond to messages -- to do that.

So I'd still say its the same kind of deep language approach difference at work.

Re:Anti-Patterns in Python Programming by jl6 on Thursday July 10, 2014 @02:53AM (#8013960)
So why does Python distinguish between a list and a tuple at all?
Re:Anti-Patterns in Python Programming by dragonwriter on Thursday July 10, 2014 @09:48AM (#8014930)
Because the distinction between a mutable list and an immutable list is still meaningful in a dynamic language like python.
Re:Anti-Patterns in Python Programming by hueving on Thursday July 10, 2014 @05:08AM (#8014297)
One is mutable, one is not. Performance. Also, look up namedtuple. Useful for returning multiple values.