Re: Interface and duck typing woes

2013-08-31 Thread Joshua Landau
On 31 August 2013 01:13, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info 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 steve+comp.lang.pyt...@pearwood.info wrote: These days, it would be

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 steve+comp.lang.pyt...@pearwood.info 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

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 steve+comp.lang.pyt...@pearwood.info 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

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 steve+comp.lang.pyt...@pearwood.info wrote: These days, it would be relatively simple to implement pre- and post- condition checking using decorators, and

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 steve+comp.lang.pyt...@pearwood.info wrote: These days, it would be relatively simple to implement pre- and post-

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 situation

Re: Interface and duck typing woes

2013-08-29 Thread Chris Angelico
On Thu, Aug 29, 2013 at 4:31 PM, Fabrice POMBET fp2...@gmail.com 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

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 of

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.

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

Re: Interface and duck typing woes

2013-08-29 Thread Chris Angelico
On Thu, Aug 29, 2013 at 10:40 PM, Joe Junior joe.fbs.jun...@gmail.com 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;

Re: Interface and duck typing woes

2013-08-29 Thread Joe Junior
On 29 August 2013 10:07, Chris Angelico ros...@gmail.com 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

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

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 We're

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 Python,

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):

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:

Re: Interface and duck typing woes

2013-08-28 Thread Chris Angelico
On Thu, Aug 29, 2013 at 7:54 AM, Terry Reedy tjre...@udel.edu 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

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 Cameron Simpson
On 29Aug2013 09:17, Chris Angelico ros...@gmail.com wrote: | On Thu, Aug 29, 2013 at 7:54 AM, Terry Reedy tjre...@udel.edu 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

Re: Interface and duck typing woes

2013-08-28 Thread Roy Smith
In article mailman.339.1377739246.19984.python-l...@python.org, Cameron Simpson c...@zip.com.au 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

Re: Interface and duck typing woes

2013-08-28 Thread Chris Angelico
On Thu, Aug 29, 2013 at 11:20 AM, Cameron Simpson c...@zip.com.au 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

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