Re: Making immutable instances



Steven D'Aprano <steve@xxxxxxxxxxxxxxxxxxxxxx> writes:
> On Fri, 25 Nov 2005 23:20:05 -0500, Mike Meyer wrote:
>> If you've got a use case, I'd be interested in hearing it.
> frozenset perhaps? If it were needed once, it could be needed again.

That's not a use case, that's an example. And not a very good one, as
it's not at all clear that the restriction is intentional in that
case. After all, the same restriction applies to every builtin type,
including the mutable version of frozenset.

> The obvious case would be for a class where distinct instances that
> compare equal but not identical map to the same value in a dict.

How does the ability to add attributes to the instances of the class
change that behavior?

> In any case, I'm not the one claiming that I need custom immutable
> classes. I'm just suggesting that there is nothing non-Pythonic about
> them. If Ben thinks he needs them, I'm sure he has put *far* more thought
> into it than I have. I know Ben in RL, and he is not someone to make snap
> judgements about turning Python into Some Other Language Just Because.

I claim that the dynamic natture of Python - which is exemplified by
things like duck typing and the ability to add attributes to nearly
everything on the fly - is a fundamental part of what makes Python
Python. The best reason Ben could come up with is that it makes
finding bugs a bit easier. But so do type declarations, static
namespaces, private and protected attributes, and a slew of similar
B&D features that are pretty much anathema to dynamic languages. This
feature fits *very* well in languages that have those features, and
poorly in languages that reject them, which includes Python.

Of course, that a feature has a lot in common with features from
un-Pythonic languages doesn't make it ipso facto unPythonic. After
all, practicality beats purity. So what's the practical application
for such a feature? What's the use case?

<mike
--
Mike Meyer <mwm@xxxxxxxxx> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
.



Relevant Pages

  • Re: Making immutable instances
    ... >> judgements about turning Python into Some Other Language Just Because. ... > B&D features that are pretty much anathema to dynamic languages. ... Class instances match by identity when used as keys, ...
    (comp.lang.python)
  • Re: private variables/methods
    ... I can't think of ANY "feechur" from other popular languages that hasn't ... requesting these features are typically NOT experienced with Python: ... writing globals is a delicate decision that is well worth ...
    (comp.lang.python)
  • Re: Python becoming less Lisp-like
    ... For one thing, I doubt the Python ... hold (as they are in many other languages). ... Metaclasses weren't something that Python just threw in because it was ... > with some double features. ...
    (comp.lang.python)
  • Is there no end to Python?
    ... I have been programming in Python for years, ... features about the language. ... In other languages, ...
    (comp.lang.python)
  • Re: Basic inheritance question
    ... Old Java habits die slowly. ... No, seriously it isn't Java habits only, most other languages wouldn't ... That's not very far from what a Python method object does - ... reference to the current instance is to pass it as an argument to the ...
    (comp.lang.python)