Re: Interface and duck typing woes

2013-08-31 Thread Roy Smith
In article <5221352b$0$6599$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > Heh, everybody has one of two reactions: > > "This is awesome!" [[i.e. what I said]] > > "You'll add type checking to my Python code over my dead body!!!" Duck typing is a funny thing. Sure, I don't ha

Re: Interface and duck typing woes

2013-08-31 Thread Joshua Landau
On 31 August 2013 01:13, Steven D'Aprano wrote: > On Fri, 30 Aug 2013 06:35:47 -0400, Roy Smith wrote: > >> In article <52200699$0$6599$c3e8da3$54964...@news.astraweb.com>, >> Steven D'Aprano wrote: >> >>> These days, it would be relatively simple to implement pre- and post- >>> condition checki

Re: Interface and duck typing woes

2013-08-30 Thread Ned Batchelder
On 8/30/13 8:13 PM, Steven D'Aprano wrote: On Fri, 30 Aug 2013 06:35:47 -0400, Roy Smith wrote: In article <52200699$0$6599$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: These days, it would be relatively simple to implement pre- and post- condition checking using decorators,

Re: Interface and duck typing woes

2013-08-30 Thread Steven D'Aprano
On Fri, 30 Aug 2013 06:35:47 -0400, Roy Smith wrote: > In article <52200699$0$6599$c3e8da3$54964...@news.astraweb.com>, > Steven D'Aprano wrote: > >> These days, it would be relatively simple to implement pre- and post- >> condition checking using decorators, and indeed one of the motivating >>

Re: Interface and duck typing woes

2013-08-30 Thread Roy Smith
In article <52200699$0$6599$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > These days, it would be relatively simple to implement pre- and post- > condition checking using decorators, and indeed one of the motivating use- > cases for function annotations in Python 3 is to allow su

Re: Interface and duck typing woes

2013-08-29 Thread jussi . santti
On Thursday, August 29, 2013 12:09:22 AM UTC+3, Joe Junior wrote: > While designing a simple library, I found myself asking a > > philosophical question: to check or not to check the parameter's > > interface? > Design by contract discipline says: do not. > > > I think that, considering it is

Re: Interface and duck typing woes

2013-08-29 Thread Steven D'Aprano
On Thu, 29 Aug 2013 09:40:32 -0300, Joe Junior wrote: > Well, the main reason for me asking this question here was because of > the Java/C#/Whatever developer in me craving for an Interface for the > container's items, and I noticed that I'm not alone in this. But I was > actually expecting the "W

Re: Interface and duck typing woes

2013-08-29 Thread alex23
On 29/08/2013 10:40 PM, Joe Junior wrote: Another reason for this question is that I read some people saying they wouldn't use python for large projects, and they always point at the lack of Interfaces as a concern. I actually disagree, but I can see their point. What do you think? Having worke

Re: Interface and duck typing woes

2013-08-29 Thread Joe Junior
On 29 August 2013 10:07, Chris Angelico wrote: > Hmm. l don't know of any good articles off-hand. But what I'm talking > about is simply developing the skill of reading exceptions, plus a few > simple things like knowing where it's appropriate to catch-and-log; > sometimes, what that means is actu

Re: Interface and duck typing woes

2013-08-29 Thread Chris Angelico
On Thu, Aug 29, 2013 at 10:40 PM, Joe Junior wrote: > @ChrisA >>Do you believe that you can write code to catch every bug you might >>make? If so, you are naive and probably haven't spent much time >>programming yet :) And if not, then you must acknowledge that bugs >>WILL happen; therefore you wi

Re: Interface and duck typing woes

2013-08-29 Thread Joe Junior
Well, the main reason for me asking this question here was because of the Java/C#/Whatever developer in me craving for an Interface for the container's items, and I noticed that I'm not alone in this. But I was actually expecting the "We're all consenting adults, here", I guess I just needed the co

Re: Interface and duck typing woes

2013-08-29 Thread Nobody
On Wed, 28 Aug 2013 18:09:22 -0300, Joe Junior wrote: > Of course I don't want to check isistance(), I like duck typing, but > should I check if hasattr() and callable() before adding to the container? That won't tell you if the object has a quack() method but with incompatible semantics (e.g. wr

Re: Interface and duck typing woes

2013-08-29 Thread Steven D'Aprano
On Thu, 29 Aug 2013 08:31:25 +0200, Fabrice POMBET wrote: > I am no depository of the pythonic way to think(tm) but I would create > flock and inherit Duck from flock, or possibly set Flock as a method of > ducks. Neither of those are good design. Donald is an individual Duck, he is not a flock

Re: Interface and duck typing woes

2013-08-29 Thread Chris Angelico
On Thu, Aug 29, 2013 at 4:31 PM, Fabrice POMBET wrote: > I am no depository of the pythonic way to think(tm) but I would create flock > and inherit Duck from flock, or possibly set Flock as a method of ducks. > Why should a Duck _be_ a Flock? They are quite different. No, a flock _has_ a duck (o

Re: Interface and duck typing woes

2013-08-29 Thread Fabrice POMBET
Le 29 août 2013 à 00:56, python-list-requ...@python.org a écrit : """While designing a simple library, I found myself asking a philosophical question: to check or not to check the parameter's interface? I think that, considering it is Python, the usual answer would be "no", but here is the situa

Re: Interface and duck typing woes

2013-08-28 Thread Steven D'Aprano
On Thu, 29 Aug 2013 11:39:25 +1000, Chris Angelico wrote: > The novice thinks his primary job is to stop the program from crashing. > The expert knows that a crash is just another way for things to go > wrong, and one of the easiest to deal with. "I find it amusing when novice programmers believe

Re: Interface and duck typing woes

2013-08-28 Thread Chris Angelico
On Thu, Aug 29, 2013 at 11:20 AM, Cameron Simpson wrote: > However, when working in Java its type strictness caught a great > many simple brainfart logic errors by checking function signatures; > typically calling the wrong function/method or mangling arguments. > Getting this stuff up front was h

Re: Interface and duck typing woes

2013-08-28 Thread Roy Smith
In article , Cameron Simpson wrote: > Anyway, I digress. My point is that there are plusses to having > signature/type checking at coding time. It is not the Python Way, > but I surely cannot be alone in sometimes being frustrated chasing > a deeply nested runtime error that static type checking

Re: Interface and duck typing woes

2013-08-28 Thread Cameron Simpson
On 29Aug2013 09:17, Chris Angelico wrote: | On Thu, Aug 29, 2013 at 7:54 AM, Terry Reedy wrote: | > Depending on who the users will be, I might just not worry about it until an | > exception is raised. If you try to protect against everything that you might | > do wrong, you are on the road to ma

Re: Interface and duck typing woes

2013-08-28 Thread Steven D'Aprano
On Wed, 28 Aug 2013 18:09:22 -0300, Joe Junior wrote: > While designing a simple library, I found myself asking a philosophical > question: to check or not to check the parameter's interface? The only correct answer to that is, "Yes no maybe". :-) > I think that, considering it is Python, the

Re: Interface and duck typing woes

2013-08-28 Thread Chris Angelico
On Thu, Aug 29, 2013 at 7:54 AM, Terry Reedy wrote: > Depending on who the users will be, I might just not worry about it until an > exception is raised. If you try to protect against everything that you might > do wrong, you are on the road to madness, as the protection code might also > be buggy

Re: Interface and duck typing woes

2013-08-28 Thread Terry Reedy
On 8/28/2013 5:09 PM, Joe Junior wrote: While designing a simple library, I found myself asking a philosophical question: to check or not to check the parameter's interface? I think that, considering it is Python, the usual answer would be "no", but here is the situation that got me thinking: c

Interface and duck typing woes

2013-08-28 Thread Joe Junior
While designing a simple library, I found myself asking a philosophical question: to check or not to check the parameter's interface? I think that, considering it is Python, the usual answer would be "no", but here is the situation that got me thinking: class Flock: def __init__(self):