[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

newb question about @property

On 4 October 2017 at 16:03, bartc <bc at freeuk.com> wrote:
> No error. Some would perceive all this as an advantage, but it means you
> can't just declare a lightweight struct or record 'Point' with exactly two
> fields x and y. You have to use other solutions ('namedtuples' or whatever,
> which probably are immutable so that don't work the same way).
> This is another example of neglecting the basics, but going for more
> advanced, perhaps more sexy features instead.

It's another example of a consistent design philosophy (highly dynamic
classes) that you might not like - possibly even enough that Python
isn't the best language for you.

It's not an advantage or a disadvantage, just an approach. Many people
like it, you may not. Specifically, yes you can't "just declare a
lightweight struct or record with exactly two fields". Python doesn't
enforce things like that, but leaves it to the programmer(s) to agree
on (and follow) conventions in the code. This means that certain
classes of error (e.g. mistyping an attribute name) can go unnoticed
until later than in other languages, but conversely it means that
things like monkeypatching of 3rd party code are possible. The
popularity of Python is evidence that the flexibility this allows is
useful to many people.

Expecting Python to have the same design as other languages does a
disservice to both Python and those other languages. There are
trade-offs in these things, and Python's choices won't be the best in
all circumstances. All we can really say is that they have turned out
to be pretty useful and popular in many situations...