Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'one?': 0.05; 'args': 0.07; 'defaults': 0.07; 'none,': 0.07; 'plenty': 0.07; 'referring': 0.07; 'arguments,': 0.09; 'i\xe2\x80\x99ve': 0.09; 'method,': 0.09; 'parameter': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'accepting': 0.14; 'args,': 0.16; 'args.': 0.16; 'closure,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'imo,': 0.16; 'i\xe2\x80\x99m': 0.16; 'opposite': 0.16; 'otoh,': 0.16; 'parameter.': 0.16; 'subject: \n ': 0.16; 'subject:More': 0.16; 'sys.stdout': 0.16; 'text",': 0.16; 'travis': 0.16; 'when,': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'wed,': 0.18; 'feb': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'certainly': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'define': 0.26; 'pass': 0.26; 'somewhere': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; '[1]': 0.29; 'am,': 0.29; 'generally': 0.29; 'to?': 0.30; 'message-id:@mail.gmail.com': 0.30; '(which': 0.31; 'code': 0.31; 'that.': 0.31; 'usually': 0.31; 'implicit': 0.31; 'subject:other': 0.31; 'lists': 0.32; 'quite': 0.32; 'text': 0.33; 'maybe': 0.34; "i'd": 0.34; 'could': 0.34; "can't": 0.35; 'common': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'described': 0.36; 'object,': 0.36; 'opposed': 0.36; 'method': 0.36; 'sometimes': 0.38; 'desirable': 0.38; 'does': 0.39; '12,': 0.39; 'heard': 0.39; 'sure': 0.39; 'either': 0.39; 'skip:p 20': 0.39; 'called': 0.40; 'even': 0.60; 'read': 0.60; 'blank': 0.60; 'tell': 0.60; 'providing': 0.61; 'times': 0.62; 'making': 0.63; 'different': 0.65; 'taking': 0.65; 'direct': 0.67; 'between': 0.67; '8bit%:21': 0.69; 'fact,': 0.69; 'loose': 0.84; 'subject:!)': 0.84; 'subject:via': 0.84; 'convenience,': 0.91; 'you\xe2\x80\x99re': 0.91; 'to:none': 0.92 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:cc :content-type:content-transfer-encoding; bh=dStB9r86MSfrO5URzI1EXbSZahMSeWKVhulVAcOxR4s=; b=AMWxCWuMVWoWzQNTNG86z1JpiOjLk8zxkaxyaoUQGZoe8KlHsWw1GMmrarLNR+ytX1 65WPDit9KkqyWm3zUfiQt18bDkrJ46RlK3zy+qow4NEGyXZ9KGhr2iIA7KVAKcejB2Na 1K2hyTHaxjzp5RXlTUDe7yusfttVgMfgqwT8VpbmeEYzJ2bF2YtrFmyKkHXv1MPvJwav Z3MHCyMnmTmFDxRN0xk0hDBo3+tudQASA6PxUb/nuWhGsvh2a18QXRFV3c4cCM3A04mQ u7s2/lM3I2TU+bWVIhxycMP6fl7Jmnx/jtgrCT53TtNWaHGeaJ4GuZQ9F+1S8ht8Q+c+ 2tgQ== MIME-Version: 1.0 X-Received: by 10.68.247.6 with SMTP id ya6mr44959004pbc.45.1392133949114; Tue, 11 Feb 2014 07:52:29 -0800 (PST) In-Reply-To: <4E8B29DC-F3A3-44A4-B912-9438CE56B3F2@gmail.com> References: <85c2698c-d681-4511-b111-bb1e549ece93@googlegroups.com> <52f9c392$0$11128$c3e8da3@news.astraweb.com> <4E8B29DC-F3A3-44A4-B912-9438CE56B3F2@gmail.com> Date: Wed, 12 Feb 2014 02:52:29 +1100 Subject: Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392133959 news.xs4all.nl 2956 [2001:888:2000:d::a6]:44889 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65921 On Wed, Feb 12, 2014 at 2:36 AM, Travis Griggs wro= te: > OTOH, I=E2=80=99m not sure I=E2=80=99ve heard the parameters-less functio= ns are a code one? Is it just loose functions that you=E2=80=99re referring= to? As opposed to methods (which are just bound functions)? I could maybe = accept that. But methods with fewer arguments, and even none, are a desirab= le thing. There are code smells that are the opposite in fact, methods with= long parameter lists are generally seen as code smell (=E2=80=9Cpassing a = paragraph=E2=80=9D). > 'self' is, imo, a parameter. When you call a parameter-less method on an object, it's usually an imperative with a direct object (or sometimes a subject): some_file.close() # "Close some_file" some_list.shuffle() # "Shuffle some_list" some_file.readline() # "Some_file, read in a line" There are times when, for convenience, the object is implicit. print("some text", file=3Dsome_file) # Print that text print(file=3Dsome_file) # Print a blank line print("some text") # Print that text to sys.stdout print() # Print a blank line to sys.stdout So in that situation, the no-args call does make sense. Of course, this is a call to a function that does take args, but it's accepting all the defaults and providing no additional content. It's quite different to actually define a function that mandates exactly zero arguments, and isn't making use of some form of implicit state (eg a closure, or maybe a module-level function that manipulates module-level state - random.random() would be an example of the latter). Syntactically, Python can't tell the difference between "print()" and "foo()" where foo can never take args. I'd say that a function taking no args is code smell, unless it's obviously taking its state from somewhere else (callbacks, for instance - maybe you pass a bound method, or maybe a closure, but in either case it has implicit state that's not described by function args); but _calling_ with no args isn't as smelly. It's certainly less common than using args, but there are plenty of times when a type is called without args, for instance[1]. ChrisA [1] Okay, that was a really abysmal pun.