On Sun, May 5, 2019 at 12:04 AM Zhuoyun Wei <wzy...@wzyboy.org> wrote:

> On Sat, May 4, 2019, at 15:00, Stefano Zacchiroli wrote:
>
> > Python data classes might come in handy here:
> > https://docs.python.org/3/library/dataclasses.html
>
> I like dataclasses. It has the same usage interface and repr as
> namedtuples, but with the flexibility of classes. There will be no more
> awkward `txn = txn._replace(narration='foo')`, just `txn.narration = `foo`.
>

The flexibility you like from dataclasses is specifically that which I'd
want to avoid. The "danger" is to start mutating instances as a side-effect
of calling functions. While it's possible to carefully use the mutable
interface of dataclasses only on brand new instances, the awkward
_replace() interface of namedtuple makes that even clearer. In an ideal
world, all mutation should occur upon construction. In other words, unlike
most Python developers, I am
- utterly uncaring for classes (1)
- terrified of side-effects and mutation
As such, I'd make all dataclasses frozen...

Furthermore, I believe in a kind of "bill of rights" for programmers:
Programmers should feel free to use any subset of a language as they see
fit. A great new tool would be one that programmatically allows one to
enforce such constraints over sections of a codebase (e.g. "under this
directory, no classes are allowed"). I wish for something like that in
Python and C++ and Go. Using a subset of a language doesn't make it
unidiomatic. In particular, avoiding the use of mutation in Python code
doesn't make it any less Pythonic. You have to consider this in the context
of the evolving nature of programming languages, and the many regrets of
their creators. Python has way too many features.



The only problem is that it's in Python 3.7. AFAIK some distros are stuck
> with Python 3.6...


> --
> Zhuoyun Wei
>
> --
> You received this message because you are subscribed to the Google Groups
> "Beancount" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to beancount+unsubscr...@googlegroups.com.
> To post to this group, send email to beancount@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/beancount/cb585c68-84d0-4f3c-be43-f2deb65f5493%40www.fastmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beancount+unsubscr...@googlegroups.com.
To post to this group, send email to beancount@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/CAK21%2BhMArb9BH4AyZTvj8Xc41KXFTgUgwtwpdMj8vFsTB_74kA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to