Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2a.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.048 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; '22,': 0.09; 'python': 0.11; 'times,': 0.14; 'interest,': 0.16; 'unlikely': 0.16; 'wrote:': 0.18; 'user.': 0.19; 'appears': 0.22; 'input': 0.22; 'print': 0.22; 'why.': 0.24; '(or': 0.24; 'sort': 0.25; '>': 0.26; 'first,': 0.26; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; "doesn't": 0.30; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; 'usually': 0.31; 'end,': 0.31; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'done,': 0.36; "i'll": 0.36; 'wrong': 0.37; 'skip:& 10': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'explain': 0.39; 'bad': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'matter': 0.61; 'pick': 0.64; 'limit': 0.70; 'recursion,': 0.84; 'tricky': 0.84 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 :content-type; bh=iPTUMsnshFilTlFPEywmH7uLV23L+jhTvw+zrN07yjE=; b=BVz8GWj9kzhRFn7BsS2XHzaTo/gwY3bIM52y5pA78RUCti2ypqknoypcYc9HjT/MWS nK9bVXMIqqNuqpDqdL8yHYLOnncwbjD182v+PaEhRtyJxuas1c1qngSis2iAFfWO6gVA /czFP93yMEYUdvUs2IYOePnmYaG4QvP2MavLbimmo9+TgA73kfM8KSg9UHQ7xrq6ede8 UVw/ob4UdlfoUwGqfw7CXGcBPt3IE2LnYqj85UTjOGcy6jR8b6hDieGU/EFwnBgKb2lB HRkkpxm3sWiuDksz96Alo37Ve58xisncahlal+gkqSvravkmkoknIqJ5scxdgzWNYwaY kmDw== MIME-Version: 1.0 X-Received: by 10.68.131.39 with SMTP id oj7mr39053432pbb.145.1419292124668; Mon, 22 Dec 2014 15:48:44 -0800 (PST) In-Reply-To: <5498808D.60305@davea.name> References: <5498808D.60305@davea.name> Date: Mon, 22 Dec 2014 16:48:44 -0700 Subject: Re: Program calling unwanted functions From: Ian Kelly To: Python Content-Type: multipart/alternative; boundary=047d7b15ab13ec6c26050ad6b26c 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1419292133 news.xs4all.nl 2944 [2001:888:2000:d::a6]:36121 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82817 --047d7b15ab13ec6c26050ad6b26c Content-Type: text/plain; charset=UTF-8 On Dec 22, 2014 2:37 PM, "Dave Angel" wrote: > > I'll pick on one function first, called instructions(). If the user types something invalid, you print "Invalid input." and call the function again. In this case, because the call is at the end, no harm is usually done, but it would be tricky to explain why. If the user happened to type the wrong input 1000 times, you'd hit a recursion limit and crash, but that's unlikely unless you have a very stubborn user. Point of interest, Python (or at least CPython) doesn't optimize tail-call recursion, so in fact this sort of unbounded recursion (a "stack leak", if you will) is equally bad no matter where it appears in the function. --047d7b15ab13ec6c26050ad6b26c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Dec 22, 2014 2:37 PM, "Dave Angel" <davea@davea.name> wrote:
>
> I'll pick on one function first, called instructions().=C2=A0 If t= he user types something invalid, you print "Invalid input." and c= all the function again.=C2=A0 In this case, because the call is at the end,= no harm is usually done, but it would be tricky to explain why.=C2=A0 If t= he user happened to type the wrong input 1000 times, you'd hit a recurs= ion limit and crash, but that's unlikely unless you have a very stubbor= n user.

Point of interest, Python (or at least CPython) doesn't = optimize tail-call recursion, so in fact this sort of unbounded recursion (= a "stack leak", if you will) is equally bad no matter where it ap= pears in the function.

--047d7b15ab13ec6c26050ad6b26c--