Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.025 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'interfaces': 0.04; 'oh,': 0.09; 'yeah,': 0.09; 'developer': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'bug': 0.12; "wouldn't": 0.14; '>that': 0.16; 'article.': 0.16; 'expecting': 0.16; 'pythonic': 0.16; 'semantics': 0.16; 'think?': 0.16; 'prevent': 0.16; ':-)': 0.16; 'all,': 0.19; 'trying': 0.19; 'projects,': 0.19; 'not,': 0.20; 'saying': 0.22; 'cc:addr:python.org': 0.22; "haven't": 0.24; '(or': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'concern.': 0.31; 'this.': 0.32; 'probably': 0.32; 'me?': 0.32; 'thanks!': 0.32; 'interface': 0.32; 'another': 0.32; '(e.g.': 0.33; 'alone': 0.33; 'bugs': 0.33; 'guess': 0.33; 'noticed': 0.34; 'could': 0.34; 'point.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'skip:> 10': 0.36; "didn't": 0.36; 'method': 0.36; 'thanks': 0.36; 'should': 0.36; 'wrong': 0.37; 'so,': 0.37; 'too': 0.37; 'needed': 0.38; 'rather': 0.38; 'that,': 0.38; 'read': 0.60; 'catch': 0.60; 'tell': 0.60; 'course': 0.61; "you'll": 0.62; 'more': 0.64; 'here': 0.66; 'believe': 0.68; 'subject': 0.69; 'therefore': 0.72; 'article': 0.77; 'lack': 0.78; 'hassle': 0.84; 'swimming': 0.84; 'items,': 0.91; 'acknowledge': 0.93; 'to:addr:nobody': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=xvXjQtx8l8PVzfox61cTjVw//RTgJmusahlVQPBwy7M=; b=wLa5iCj/QiCqdB928n2VvNOHTVkyoPRFyQv9g1DyIN9ln3IBr/SNj0UuGkZ8eOlSG4 R5nvLrl6rB0Y8+8boQa6ucXnONtrm1A+CddHFWAIQDKR0lNgocPmqAS2nAHZb9+dwMbF jX14yp2Z4ELEO1MfDN/9d1aT2jbYJdLuZ3Hga95clvxTp773cbpiqdrP5G/Kze/0rcwz LcVQ5HBU0V/J7c37zEEGzpiRXx0q3nkftvDLZipboMvIAThZTlMW4v22UasyUfkLGsAM RPHodycrjAz+pYGikIHHqalfufOGcrky36+H+DnnkKcjcovRYh528mItL9MxV9+2Ptx1 ivgg== MIME-Version: 1.0 X-Received: by 10.49.3.131 with SMTP id c3mr3511712qec.33.1377780032179; Thu, 29 Aug 2013 05:40:32 -0700 (PDT) In-Reply-To: References: Date: Thu, 29 Aug 2013 09:40:32 -0300 Subject: Re: Interface and duck typing woes From: Joe Junior To: Nobody Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377780041 news.xs4all.nl 15903 [2001:888:2000:d::a6]:36035 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53242 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 confirmation :-) 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? @Nobody >> 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. wrong number or types of arguments). Yeah, didn't think about that, it's kinda swimming upstream! Definitely it is more hassle than it is worth. @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 will need to cope with them after the >event. So rather than trying to prevent them all, just improve your >means of coping, and you'll accomplish the same end with much less >trouble. Oh, no! I'm not that presumptuous (or naive)! But what do you mean by "improve means of coping"? Do you know any article on the subject you could point me? @Steven >> 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? What is the pythonic way to deal with it? Am I worrying too >> much ;-)? >Yes :-) Well, thanks! :-) And thanks for the article.