Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Stephen J. Turnbull
Chris Angelico writes: > Okay, but what is the contract that's being violated when you use > data= ? How would you define the contract that this would track? > That's what I'm asking. The output is input to some other component. In production, that component would not be under your control,

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Stephen J. Turnbull
Paul Moore writes: > With provisos. Figuring out contracts in sufficient detail to use > the code is *in many cases* simple. For harder cases, agreed. But > that's why this is simply a proof that contracts *can* be useful, > not that 100% of code would benefit from them. Note that that is

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Chris Angelico
On Thu, Sep 27, 2018 at 3:31 PM Greg Ewing wrote: > > Chris Angelico wrote: > > if you let your API > > docs rot when you make changes that callers need to be aware of, you > > have failed your callers. > > Yes, I find that documentation auto-generated from code is > usually a poor substitute for

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Greg Ewing
Chris Angelico wrote: if you let your API docs rot when you make changes that callers need to be aware of, you have failed your callers. Yes, I find that documentation auto-generated from code is usually a poor substitute for human-written documentation. Dumping your formally-written contracts

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Stephen J. Turnbull
Robert Collins writes: > I think the underlying problem is that you're treating this as a > logic problem (what does logic say applies here), rather than an > engineering problem (what can we measure and what does it tell us > about whats going on). Pure gold. I'm glad your name is "Robert

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread David Mertz
I'm not sure what to do with the repeated assurance that that various things "are obvious." It really is NOT the case that me, or Paul Moore, or Hugh Fisher, or Greg Ewing are simply too simple minded to understand what DbC is. The off-putting evangelical quality around DbC is something like the

Re: [Python-ideas] "while:" for the loop

2018-09-26 Thread Mike Miller
On 2018-09-25 17:46, Mikhail V wrote: I suggest allowing "while:" syntax for the infinite loop. I.e. instead of "while 1:" and "while True:" notations. I like this idea, and would have use for it. -Mike ___ Python-ideas mailing list

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Greg Ewing
Chris Angelico wrote: For example, matplotlib's plt.show() method guarantees that... a plot will be shown, and the user will have dismissed it, before it returns. Unless you're inside Jupyter/iPython, in which case it's different. Or if you're in certain other environments, in which case it's

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Chris Angelico
On Thu, Sep 27, 2018 at 10:07 AM Robert Collins wrote: > > On 27 September 2018 at 11:50, Chris Angelico wrote: > > > Okay, but what is the contract that's being violated when you use > > data= ? How would you define the contract that this would track? > > That's what I'm asking. > > I don't

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Robert Collins
On 27 September 2018 at 11:50, Chris Angelico wrote: > Okay, but what is the contract that's being violated when you use > data= ? How would you define the contract that this would track? > That's what I'm asking. I don't know :). From a modelling perspective the correctness of the behaviour

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Chris Angelico
On Thu, Sep 27, 2018 at 9:22 AM Robert Collins wrote: > > On Thu., 27 Sep. 2018, 11:00 Chris Angelico, wrote: >> >> On Thu, Sep 27, 2018 at 8:53 AM Robert Collins >> wrote: >> > >> > On Thu, 27 Sep 2018 at 00:44, Marko Ristin-Kaufmann >> > wrote: >> > > >> > > P.S. My offer still stands: I

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Robert Collins
On Thu., 27 Sep. 2018, 11:00 Chris Angelico, wrote: > On Thu, Sep 27, 2018 at 8:53 AM Robert Collins > wrote: > > > > On Thu, 27 Sep 2018 at 00:44, Marko Ristin-Kaufmann > > wrote: > > > > > > P.S. My offer still stands: I would be very glad to annotate with > contracts a set of functions you

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Chris Angelico
On Thu, Sep 27, 2018 at 8:53 AM Robert Collins wrote: > > On Thu, 27 Sep 2018 at 00:44, Marko Ristin-Kaufmann > wrote: > > > > P.S. My offer still stands: I would be very glad to annotate with contracts > > a set of functions you deem representative (e.g., from a standard library > > or from

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Robert Collins
On Thu, 27 Sep 2018 at 00:44, Marko Ristin-Kaufmann wrote: > > P.S. My offer still stands: I would be very glad to annotate with contracts a > set of functions you deem representative (e.g., from a standard library or > from some widely used library). Then we can discuss how these contracts. It

Re: [Python-ideas] "old" values in postconditions

2018-09-26 Thread James Lu
Hi Marko, > Actually, following on #A4, you could also write those as multiple decorators: > @snpashot(lambda _, some_identifier: some_func(_, some_argument.some_attr) > @snpashot(lambda _, other_identifier: other_func(_.self)) Yes, though if we’re talking syntax using kwargs would probably be

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Chris Angelico
On Thu, Sep 27, 2018 at 5:07 AM Chris Barker wrote: > > On Tue, Sep 25, 2018 at 10:10 PM Lee Braiden wrote: >> >> It's the reason why type checking exists, and why bounds checking exists, >> and why unit checking exists too. > > And yet Python has none of those. They all provide safety, but

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Chris Barker via Python-ideas
On Tue, Sep 25, 2018 at 10:10 PM Lee Braiden wrote: > It's the reason why type checking exists, and why bounds checking exists, > and why unit checking exists too. > And yet Python has none of those. They all provide safety, but also place a burden on the developer. So why use Python? I’m not

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Marko Ristin-Kaufmann
Hi David, I'm writing contracts for pathlib as a proof-of-concept. See pypackagery for an example of a project on pypi that uses contracts: https://pypi.org/project/pypackagery/ The docs with contracts are available at: https://pypackagery.readthedocs.io/en/latest/packagery.html Mind that the

Re: [Python-ideas] "while:" for the loop

2018-09-26 Thread Mikhail V
On Wed, Sep 26, 2018 at 4:46 PM Mark E. Haase wrote: > > On Tue, Sep 25, 2018 at 8:47 PM Mikhail V wrote: >> >> As for statistics - IIRC someone gave statistics once, but the only >> thing I can remember [...] "while 1/True" is used quite a lot in the > > This proposal would be a lot stronger if

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread David Stanek
On Wed, Sep 26, 2018 at 12:49 AM Marko Ristin-Kaufmann wrote: > >> An extraordinary claim is like "DbC can improve *every single project* >> on PyPI". That requires a TON of proof. Obviously we won't quibble if >> you can only demonstrate that 99.95% of them can be improved, but you >> have to at

Re: [Python-ideas] "while:" for the loop

2018-09-26 Thread Kirill Balunov
On Wed, Sep 26, 2018, 19:30 David Mertz wrote: > We also have: > > from itertools import count > for i in count(): > ... > > If you want to keep track of how close to infinity you are. :-) > We also have: from itertools import repeat for i in repeat(...): ... with kind regards, -gdg

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread James Lu
> It's easy to say that they're boolean expressions. But that's like > saying that unit tests are just a bunch of boolean expressions too. > Why do we have lots of different forms of test, rather than just a big > fat "assert this and this and this and this and this and this"? > Because the key to

Re: [Python-ideas] "while:" for the loop

2018-09-26 Thread Michael Selik
On Wed, Sep 26, 2018, 9:42 AM Tobias Kohn wrote: > Although I doubt it will really make it into Python's grammar, I am all +1 > for the idea of having "repeat" as a loop keyword in Python. Actually, I > have been using "repeat" as a keyword in Python for quite some time now, > and found it not

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Paul Moore
On Wed, 26 Sep 2018 at 16:04, Rhodri James wrote: > Marko is making some very big assertions about how much of a benefit > Design by Contract is. I flat-out don't believe him. It's up to him to > provide some evidence, since he's the one pressing for change. And to be fair, he's now offered to

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Rhodri James
On 25/09/18 21:09, Lee Braiden wrote: Eh. It's too easy to cry "show me the facts" in any argument. To do that too often is to reduce all discussion to pendantry. I will resist pointing out the spelling mistake... oh damn :-) The trouble with not crying "show me the facts" is that it is very

Re: [Python-ideas] "while:" for the loop

2018-09-26 Thread Mark E. Haase
On Tue, Sep 25, 2018 at 8:47 PM Mikhail V wrote: > As for statistics - IIRC someone gave statistics once, but the only > thing I can remember - > "while 1/True" is used quite a lot in the std lib, so the numbers > exceeded my expectation > (because I expected that it's used mostly in

Re: [Python-ideas] "while:" for the loop

2018-09-26 Thread Tobias Kohn
Hello, Although I doubt it will really make it into Python's grammar, I am all +1 for the idea of having "repeat" as a loop keyword in Python.  Actually, I have been using "repeat" as a keyword in Python for quite some time now, and found it not only convenient, but also a great help in

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Marko Ristin-Kaufmann
Hi Paul, Quite a few people replied on this thread and the previous one before the fork that dbc is either useless in Python or at best useful in avionics/niche applications. I'm really only saying that contracts are a superior (complementary) tool to informal documentation, doctests, reading the

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Paul Moore
On Wed, 26 Sep 2018 at 14:04, Marko Ristin-Kaufmann wrote: > > @Chris Angelico would annotating pathlib convince you that contracts are > useful? Is it general enough to start with? Whoa - be careful here. No-one is saying that "contracts aren't useful" (at least not that I'd heard). We're

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Chris Angelico
On Wed, Sep 26, 2018 at 11:04 PM Marko Ristin-Kaufmann wrote: > @Chris Angelico would annotating pathlib convince you that contracts are > useful? Is it general enough to start with? > I won't promise it'll convince me, but it'll certainly be a starting-point for real discussion. Also, it's a

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Marko Ristin-Kaufmann
Hi Paul, Are we talking here about coding explicit executable contracts in the > source code of the library, or using (formally described in terms of > (pseudo-)code) contract-style descriptions in the documentation, or > simply using the ideas of contract-based thinking in designing and >

Re: [Python-ideas] "while:" for the loop

2018-09-26 Thread James Lu
repeat could be only considered a keyword when it’s used as a loop Sent from my iPhone > On Sep 26, 2018, at 8:46 AM, Brice Parent wrote: > >> Le 26/09/2018 à 14:33, James Lu a écrit : >> what about “repeat:”? >> >> Sent from my iPhone > I'm not sure it was on purpose, but you replied to me

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Paul Moore
On Wed, 26 Sep 2018 at 13:43, Marko Ristin-Kaufmann wrote: > > P.S. My offer still stands: I would be very glad to annotate with contracts a > set of functions you deem representative (e.g., from a standard library or > from some widely used library). Then we can discuss how these contracts. It

Re: [Python-ideas] "old" values in postconditions

2018-09-26 Thread Marko Ristin-Kaufmann
Hi James, Actually, following on #A4, you could also write those as multiple decorators: @snpashot(lambda _, some_identifier: some_func(_, some_argument.some_attr) @snpashot(lambda _, other_identifier: other_func(_.self)) Am I correct? "_" looks a bit hard to read for me (implying ignored

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Paul Moore
On Wed, 26 Sep 2018 at 13:40, Marko Ristin-Kaufmann wrote: > Please mind that I said: any library would benefit from it, as in the users > of any library on pipy would benefit from better, formal and more precise > documentation. That doesn't imply that all the contracts need to be specified

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Marko Ristin-Kaufmann
P.S. My offer still stands: I would be very glad to annotate with contracts a set of functions you deem representative (*e.g., *from a standard library or from some widely used library). Then we can discuss how these contracts. It would be an inaccurate estimate of the benefits of DbC in Python,

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Marko Ristin-Kaufmann
Hi Chris and Paul, Let me please answer your messages in one go as they are related. Paul wrote: > For most single use (or infrequently used) functions, I'd argue that the > trade-off *isn't* worth it. > > Here's a quick example from the pip codebase: > > # Retry every half second for up to 3

Re: [Python-ideas] "old" values in postconditions

2018-09-26 Thread James Lu
I still prefer snapshot, though capture is a good name too. We could use generator syntax and inspect the argument names. Instead of “a”, perhaps use “_”. Or maybe use “A.”, for arguments. Some people might prefer “P” for parameters, since parameters sometimes means the value received while

[Python-ideas] Add .= as a method return value assignment operator

2018-09-26 Thread Jasper Rebane
Hi, When using Python, I find myself often using assignment operators, like 'a += 1' instead of 'a = a + 1', which saves me a lot of time and hassle Unfortunately, this doesn't apply to methods, thus we have to write code like this: text = "foo" text = text.replace("foo","bar") # "bar" I

Re: [Python-ideas] Fwd: Keyword only argument on function call

2018-09-26 Thread Anders Hovmöller
> Oh, I see that you indeed implemented a macropy version at > https://github.com/boxed/macro-kwargs/blob/master/test.py > . > Other than use() vs grab() as the function name, it's the same thing. Well, except that it's import time,

Re: [Python-ideas] Fwd: Keyword only argument on function call

2018-09-26 Thread David Mertz
Oh, I see that you indeed implemented a macropy version at https://github.com/boxed/macro-kwargs/blob/master/test.py. Other than use() vs grab() as the function name, it's the same thing. Is it true that the macro version has no performance cost? So it's now perfectly straightforward to provide

Re: [Python-ideas] Fwd: Keyword only argument on function call

2018-09-26 Thread David Mertz
On Wed, Sep 26, 2018, 5:12 AM Anders Hovmöller wrote: > I saw now that I missed the biggest problem with your proposal: yet again >> you deliberately throw away errors. I'm talking about making Python code >> _less_ error prone, while you seem to want to make it _more_. >> > > Beyond the

Re: [Python-ideas] Fwd: Keyword only argument on function call

2018-09-26 Thread Anders Hovmöller
> I saw now that I missed the biggest problem with your proposal: yet again you > deliberately throw away errors. I'm talking about making Python code _less_ > error prone, while you seem to want to make it _more_. > > Beyond the belligerent tone, is there an actual POINT here? Yes, there is

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Paul Moore
On Wed, 26 Sep 2018 at 09:45, Chris Angelico wrote: > > On Wed, Sep 26, 2018 at 6:36 PM Paul Moore wrote: > > > > On Wed, 26 Sep 2018 at 06:41, Chris Angelico wrote: > > > > > > On Wed, Sep 26, 2018 at 2:47 PM Marko Ristin-Kaufmann > > > wrote: > > > > * The contracts written in documentation

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Chris Angelico
On Wed, Sep 26, 2018 at 6:37 PM Chris Angelico wrote: > > On Wed, Sep 26, 2018 at 5:51 PM Marko Ristin-Kaufmann > wrote: > > > > Hi Chris, > > > >> It's easy to say that they're boolean expressions. But that's like > >> saying that unit tests are just a bunch of boolean expressions too. > >> Why

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Chris Angelico
On Wed, Sep 26, 2018 at 6:36 PM Paul Moore wrote: > > On Wed, 26 Sep 2018 at 06:41, Chris Angelico wrote: > > > > On Wed, Sep 26, 2018 at 2:47 PM Marko Ristin-Kaufmann > > wrote: > > > * The contracts written in documentation as human text inevitably rot and > > > they are much harder to

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Chris Angelico
On Wed, Sep 26, 2018 at 5:51 PM Marko Ristin-Kaufmann wrote: > > Hi Chris, > >> It's easy to say that they're boolean expressions. But that's like >> saying that unit tests are just a bunch of boolean expressions too. >> Why do we have lots of different forms of test, rather than just a big >>

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Paul Moore
On Wed, 26 Sep 2018 at 06:41, Chris Angelico wrote: > > On Wed, Sep 26, 2018 at 2:47 PM Marko Ristin-Kaufmann > wrote: > > > > Hi Chris, > > > >> An extraordinary claim is like "DbC can improve *every single project* > >> on PyPI". That requires a TON of proof. Obviously we won't quibble if > >>

Re: [Python-ideas] Fwd: Keyword only argument on function call

2018-09-26 Thread David Mertz
On Wed, Sep 26, 2018, 3:19 AM Anders Hovmöller wrote: > I saw now that I missed the biggest problem with your proposal: yet again > you deliberately throw away errors. I'm talking about making Python code > _less_ error prone, while you seem to want to make it _more_. > Beyond the belligerent

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Marko Ristin-Kaufmann
Hi Chris, It's easy to say that they're boolean expressions. But that's like > saying that unit tests are just a bunch of boolean expressions too. > Why do we have lots of different forms of test, rather than just a big > fat "assert this and this and this and this and this and this"? > Because

Re: [Python-ideas] "while:" for the loop

2018-09-26 Thread Brice Parent
Le 26/09/2018 à 05:36, Chris Angelico a écrit : On Wed, Sep 26, 2018 at 1:29 PM Mikhail V wrote: On Wed, Sep 26, 2018 at 5:38 AM Chris Angelico wrote: I like saying while "something": where the string describes the loop's real condition. For instance, while "moar data": if reading from a

Re: [Python-ideas] Fwd: Keyword only argument on function call

2018-09-26 Thread Anders Hovmöller
David, I saw now that I missed the biggest problem with your proposal: yet again you deliberately throw away errors. I'm talking about making Python code _less_ error prone, while you seem to want to make it _more_. Anyway, I'll modify your reach() to not have the if in it that has this error

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Chris Angelico
On Wed, Sep 26, 2018 at 5:10 PM Marko Ristin-Kaufmann wrote: > The original objection was that DbC in general is not beneficial; not that > there are lacking tools for it (this probably got lost in the many messages > on this thread). If you assume that there are no suitable tools for DbC, then

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Marko Ristin-Kaufmann
Hi Chris, > * There are always contracts, they can be either implicit or explicit. > You need always to figure them out before you call a function or use its > result. > > Not all code has such contracts. You could argue that code which does > not is inferior to code which does, but not

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-09-26 Thread Robert Collins
On Wed, 26 Sep 2018 at 05:19, Marko Ristin-Kaufmann wrote: > > Hi Robert, ... >> Claiming that DbC annotations will improve the documentation of every >> single library on PyPI is an extraordinary claim, and such claims >> require extraordinary proof. > > > I don't know what you mean by