Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65925

Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!)

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <travisgriggs@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'algorithm': 0.04; 'explicitly': 0.05; 'one?': 0.05; 'args': 0.07; 'defaults': 0.07; 'none,': 0.07; 'plenty': 0.07; 'referring': 0.07; 'arguments,': 0.09; 'escape': 0.09; 'method,': 0.09; 'parameter': 0.09; 'python': 0.11; 'accepting': 0.14; 'arg': 0.16; 'args,': 0.16; 'args.': 0.16; 'clause,': 0.16; 'closure,': 0.16; 'imo,': 0.16; 'opposite': 0.16; 'otoh,': 0.16; 'parameter.': 0.16; 'subject:More': 0.16; 'sys.stdout': 0.16; 'text",': 0.16; 'then?': 0.16; 'travis': 0.16; 'when,': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'wed,': 0.18; 'module': 0.19; 'seems': 0.21; 'feb': 0.22; 'example': 0.22; 'to:name:python-list@python.org': 0.22; 'print': 0.22; 'certainly': 0.24; 'mind.': 0.24; '(or': 0.24; 'define': 0.26; 'pass': 0.26; 'somewhere': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'generally': 0.29; 'to?': 0.30; '(which': 0.31; 'code': 0.31; 'that.': 0.31; 'usually': 0.31; 'implicit': 0.31; 'parameters.': 0.31; 'subject:other': 0.31; 'you\x92re': 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; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'described': 0.36; 'object,': 0.36; 'opposed': 0.36; 'method': 0.36; 'sometimes': 0.38; 'message-id:@gmail.com': 0.38; 'desirable': 0.38; 'to:addr :python-list': 0.38; 'does': 0.39; '12,': 0.39; 'heard': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'skip:p 20': 0.39; 'called': 0.40; 'how': 0.40; 'even': 0.60; 'read': 0.60; 'blank': 0.60; 'tell': 0.60; 'providing': 0.61; 'times': 0.62; 'making': 0.63; 'header:Message-Id:1': 0.63; 'different': 0.65; 'taking': 0.65; 'charset:windows-1252': 0.65; 'direct': 0.67; 'between': 0.67; 'fact,': 0.69; '2014,': 0.84; 'doesn\x92t': 0.84; 'it\x92s': 0.84; 'i\x92ve': 0.84; 'loose': 0.84; 'subject:!)': 0.84; 'subject:via': 0.84; 'widen': 0.84; 'convenience,': 0.91; 'difficult,': 0.91; 'tied': 0.93; 'state.': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=AVnZgImCLExwzXeOfg+MaBUYMd3Q63Q68FjF4aZ+uYk=; b=VE7yIvf9/IfD5F0LiWwzpQkoqMFeYPEneHbU1eSXvU9mYJspKSr6vsk0OPb5QGGdu+ xc+2+T+3O5MhSQu27pWGfzzVABqLOB+Wkwf+2uwAl8BAwN6djZa/aGtZkhAf0A4teURL UsH64RrSw3LeXQqjCjF7ogKfcxbra2ZdxT2sH6PyBy3KTrmnNOv7Ebt7fvD0gMHXz02j YeSNj3iwLTN8wD33NXS5E073m67P2FQYqGHkjL4MhsXcZ9DYgPXVBW6pFEW9UHdSySKk zgPeJA0UwmTQdipBGsLHg9H8zsLd8MBPvKT6PhzilIz7hlGz+NNWWXGR4/hqRqEopbZH VnGQ==
X-Received by 10.67.13.226 with SMTP id fb2mr16558299pad.146.1392135565555; Tue, 11 Feb 2014 08:19:25 -0800 (PST)
Content-Type text/plain; charset=windows-1252
Mime-Version 1.0 (Mac OS X Mail 7.1 \(1827\))
Subject Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!)
From Travis Griggs <travisgriggs@gmail.com>
In-Reply-To <CAPTjJmq7iqZwC1Vf74imv1ETg651D4xNTyzgB_tToyYqyCd71A@mail.gmail.com>
Date Tue, 11 Feb 2014 08:19:24 -0800
Content-Transfer-Encoding quoted-printable
References <85c2698c-d681-4511-b111-bb1e549ece93@googlegroups.com> <52f9c392$0$11128$c3e8da3@news.astraweb.com> <4E8B29DC-F3A3-44A4-B912-9438CE56B3F2@gmail.com> <CAPTjJmq7iqZwC1Vf74imv1ETg651D4xNTyzgB_tToyYqyCd71A@mail.gmail.com>
To "python-list@python.org" <python-list@python.org>
X-Mailer Apple Mail (2.1827)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6681.1392135575.18130.python-list@python.org> (permalink)
Lines 70
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1392135575 news.xs4all.nl 2923 [2001:888:2000:d::a6]:59311
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:65925

Show key headers only | View raw


On Feb 11, 2014, at 7:52 AM, Chris Angelico <rosuav@gmail.com> wrote:

> On Wed, Feb 12, 2014 at 2:36 AM, Travis Griggs <travisgriggs@gmail.com> wrote:
>> OTOH, I’m not sure I’ve heard the parameters-less functions are a code one? Is it just loose functions that you’re 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 desirable thing. There are code smells that are the opposite in fact, methods with long parameter lists are generally seen as code smell (“passing a paragraph”).
>> 
> 
> '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=some_file) # Print that text
> print(file=some_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.

So at this point, what I’m reading is that actually making a “no arg function” is difficult, if we widen the semantics. The “arguments” of a function may be bound to its implicit self parameter, or tied to module state.

> 
> 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].

Which leaves me wondering, how would I get my code to smell this way then? What IS an example of a no arg function that doesn’t have an implicit object, that smells? It seems I can  escape the smell clause, as long as I find some data that I reason is attached to my function.

This all aside, I don’t think these are what the OP had in mind. A code inspection algorithm is not going to be able to discern when an explicitly parameterless function has implicit parameters. It’s just going to see something like

print vs print()

or 

aPoint.transpose vs aPoint.transpose()

 

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Rick Johnson <rantingrickjohnson@gmail.com> - 2014-02-10 10:45 -0800
  Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-10 19:15 +0000
  Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Ned Batchelder <ned@nedbatchelder.com> - 2014-02-10 14:17 -0500
  Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Rotwang <sg552@hotmail.co.uk> - 2014-02-10 21:12 +0000
    Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Ned Batchelder <ned@nedbatchelder.com> - 2014-02-10 17:00 -0500
    Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Terry Reedy <tjreedy@udel.edu> - 2014-02-10 17:59 -0500
  Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Chris Angelico <rosuav@gmail.com> - 2014-02-11 09:30 +1100
  Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Steven D'Aprano <steve@pearwood.info> - 2014-02-11 06:30 +0000
    Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Tim Chase <python.list@tim.thechases.com> - 2014-02-11 09:26 -0600
    Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Travis Griggs <travisgriggs@gmail.com> - 2014-02-11 07:36 -0800
      Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-02-11 18:07 +0200
        Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Chris Angelico <rosuav@gmail.com> - 2014-02-12 03:14 +1100
      Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Steven D'Aprano <steve@pearwood.info> - 2014-02-13 04:11 +0000
        Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Chris Angelico <rosuav@gmail.com> - 2014-02-13 15:30 +1100
          Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Roy Smith <roy@panix.com> - 2014-02-13 09:58 -0500
            Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Chris Angelico <rosuav@gmail.com> - 2014-02-14 06:17 +1100
        Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Tim Chase <python.list@tim.thechases.com> - 2014-02-13 05:39 -0600
        Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Tim Chase <python.list@tim.thechases.com> - 2014-02-13 05:51 -0600
        Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-13 15:00 -0700
    Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Chris Angelico <rosuav@gmail.com> - 2014-02-12 02:52 +1100
    Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Travis Griggs <travisgriggs@gmail.com> - 2014-02-11 08:19 -0800
    Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Terry Reedy <tjreedy@udel.edu> - 2014-02-11 12:57 -0500

csiph-web