On Mon, Aug 6, 2012 at 5:07 PM, Matthew Rocklin <
mroc...@gmail.com> wrote:
> Immutability has many virtues. It is nice to create an object, pass it
> around to many functions, and know that it is still the same. Immutability
> is very safe.
>
> Mutability has many virtues. It is fast. People are used to it.
I would argue the exact opposite. Sure, you may be surprised when an
attempt to mutate breaks, but you'll be even more surprised when an
operation that you wouldn't expect to work in place does. The point
is that mutability represents a change in state, which requires a mich
higher cognitive burdon to understand. Some programming languages (in
particular, functional languages) find this concept to be so bad that
they disallow mutability altogether.
>
> I think it is important to support both types. I think that people who like
> immutability are ok with it being a bit slower. Right now the
> Immutable->mutable->computation->mutable->Immutable process works well I
> think. It would be better if, as Aaron suggests, we ensure that the
> transition is very cheap.
>
> There are many interesting discussions to be had however about defaults and
> standards.
>
> Despite being a fan of immutability in symbolic systems I think that we
> should stick to having MutableMatrix the default. I think that many users
> will want to do things like
>
> M = eye(3)
> M[2, 2] = 10
But if they want to do that, then we can just have a __setitem__ that
raises TypeError("ImmutableMatrix does not support item assignment.
Use MutableMatrix instead."), and they user will see immediately that
they just need to do M = MutableMatrix(M), and then they can continue
to do what they want to do. And note that things like
A += B
will work either way (the difference is that the mutable case will be
more memory efficient).
On the other hand, if we make ImmutableMatrix the default, then we can
make MutableMatrix's methods work in place without worrying about them
being too unexpected (because it's assumed that if the user uses
MutableMatrix, that he wants in place operations), and it actually
would be more consistant. For example, MatrixMatrix.row_del works in
place, but MutableMatrix.row_insert does not. Also, many algorithms
can be more efficient if done mutably.
>
> If we stop them from doing this I think that they will be confused.
>
> The unevaluated by default discussion is separate. The next chance I get a
> free 20 minutes I'll put up a pull request to change the behavior. I do
> encourage discussion on the topic. In one of the issues someone did want an
> unevaluated immutable matrix expression. This will still be possible but
> you'll have to use explicit MatAdds/MatMuls.
Right. My only point there was that we can't replace Matrix with
ImmutableMatrix without changing this.
>
> To be clear on the original point. Even if we had a MutableBasic I still
> think we should have an ImmutableMatrix. I do not think we should merge
> Mutable and Immutable.
I agree.
Aaron Meurer