On Mon, Oct 18, 2021 at 6:15 PM Matt del Valle <matthew...@gmail.com> wrote:

> I think what's being discussed in this thread is variations on the fluent
> interface design pattern (https://en.wikipedia.org/wiki/Fluent_interface).
>
> with Schedule(...) as schedule:
>     
> schedule.every(3).months.and_(7).days.and_(12).hours.and_(30).minutes.do(some_func)
>     schedule.every.tuesday.at(6).do(some_func)
>     schedule.every.month.on_the(1).and_(7).at(23, 59).do(some_func)
>     
> schedule.every.year.in_.march.and_.august.and_.november.on.saturday.and_.sunday.at(12).and_(20,
>  30).starting(datetime.today()).ending(datetime(2022, 1, 1)).do(some_func)
>
>
I use fluent programming quite often, and have since before I started using
Python in 1998.  I never really did Smalltalk, but a language called
XBase++ (and some related family of language) used this.  Maybe Object
Pascal too (my memories are dimming).

In Pandas, I think the style is very productive and generally clarifies
what I might be trying to express as a data scientist.

In contrast, I find that scheduler example painful and almost unreadable.
Crontab seems completely clear and obvious to me.  Yes, I've used crontab,
it's not a new thing to me.

A key difference between Pandas and the micro-examples is simply HOW MUCH
transformation they do.  In Pandas, I'll use fluent methods, but they
generally completely reshape (or filter, sort, etc) an entire DataFrame.
Moreover, in Pandas, each chained method is usually parameterized with a
variety of arguments, often named arguments.  In examples like the crontab
lines, or like:

insert(x).into.seq(s).at(i)
>>
>
Each new method is just a tiny modification of a single "attribute" of the
operation.  If you want configurations like that, *parameters* are 1000x
better. E.g.:

    insert(seq=s, val=x, pos=i)

I mean, hopefully this is actually a method of the sequence, but supposing
that it's not for some obscure reason on some obscure data structure.  That
explicitly describes what each value is doing, and it does it in a way that
doesn't look awful to Python eyes.

Better still, of course, is just:

    seq.insert(x, pos=i)
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/L47EESKWCW5ARWAZV5KR77WRUHLN7E5V/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to