Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; '16,': 0.03; 'odd': 0.07; 'plenty': 0.07; 'think,': 0.07; 'exceeds': 0.09; 'function,': 0.09; 'python': 0.11; 'language,': 0.12; 'suggest': 0.14; 'directive': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hits': 0.16; 'length,': 0.16; 'length.': 0.16; 'limit,': 0.16; 'nesting': 0.16; 'rationale': 0.16; 'responses.': 0.16; 'subject:GUI': 0.16; 'wrote:': 0.18; '(not': 0.18; 'bit': 0.19; 'restrictions': 0.19; 'split': 0.19; 'code,': 0.22; 'putting': 0.22; 'separate': 0.22; 'certainly': 0.24; 'instance,': 0.24; 'fairly': 0.24; "i've": 0.25; 'switch': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; '(this': 0.29; '[1]': 0.29; 'am,': 0.29; 'generally': 0.29; 'message- id:@mail.gmail.com': 0.30; 'largest': 0.30; "i'm": 0.30; 'code': 0.31; 'produces': 0.31; 'cases': 0.33; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'c++': 0.36; 'ones,': 0.36; 'doing': 0.36; 'next': 0.36; 'thanks': 0.36; 'subject:?': 0.36; 'should': 0.36; 'wrong': 0.37; 'level': 0.37; 'massive': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'short': 0.38; 'heard': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'even': 0.60; 'length': 0.61; 'making': 0.63; 'name': 0.63; 'high': 0.63; 'relatively': 0.65; 'here': 0.66; 'between': 0.67; 'eight': 0.74; 'felt': 0.74; 'jul': 0.74; '.in': 0.84; 'laid': 0.84; 'divided': 0.91; '2013': 0.98 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=ylyaZ3HeeIbEshyAPuuzAe2D07ztyY8MZo7+GaGH+TY=; b=muVCNwPi3/sPfL3MFyCJvwXW8aT40VHZFd1x0wdJEr4EUjtZNXVH9C1xjSVF7Cvia9 5ks/FCFRXrlenQoH9pWQXZTNGonLz8EkryWXsSkPIUblgUPu65dae1M4VQGMhnn3vM83 /Ej50+prpMNP8Rnm308eIWqJJm2m4rmOsJyO3Bi/Ze/2Vb7r06ZDEHADYD0akfYXmzdy 50fWI2Gyj/HNjIjfhiOOkxi56n1oySWExZxoYySGEeDcW+MDn5Wn89OLaujn++yu5Yrr dIubHVGZ/OfbbZEv1kmVhX8H1Sx5FAxvn3xhWuRcokbbPI6Gwxi9ZXj+iorSnM57nNYT hOHQ== MIME-Version: 1.0 X-Received: by 10.220.128.72 with SMTP id j8mr29363927vcs.3.1373944736461; Mon, 15 Jul 2013 20:18:56 -0700 (PDT) In-Reply-To: <8152b57e-5ff3-4024-9de1-d0a20b5c14b6@googlegroups.com> References: <22e50125-633a-4bae-a317-a83a748be225@googlegroups.com> <8152b57e-5ff3-4024-9de1-d0a20b5c14b6@googlegroups.com> Date: Tue, 16 Jul 2013 13:18:56 +1000 Subject: Re: Ideal way to separate GUI and logic? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373944739 news.xs4all.nl 15936 [2001:888:2000:d::a6]:37496 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50725 On Tue, Jul 16, 2013 at 10:25 AM, wrote: > Again, thanks for all the responses. I'm curious, though, what exactly is the rationale for making functions so small? (I've heard that the function calling of Python has relatively high overhead?) A function should be as long as it needs to be - neither longer nor shorter. If you can name a function appropriately, and it's doing exactly what its name suggests, it's the right length. This generally produces short functions rather than long ones, but if the right length for a function exceeds some arbitrary limit, let the function be longer. For instance, I have a single function that's a bit over a page in length, because it's one big switch block (this isn't in Python, obviously), doing one thing fairly cleanly. Larger than that would have to be called code smell, but there's certainly nothing wrong with having the odd function here or there that's over Steven's dozen-line estimate. There'll also be plenty of really short functions - even one-liners. The largest single function in any of my code, I think, is a gigantic double-nested switch block in PHP .In any decent language, that would be divided up not just into functions but into files, but PHP has some stupid restrictions on its include directive that make that impractical. So syntactically it's one massive function, but logically it's about seven or eight separate sub-blocks, and the code is laid out in those blocks. It's just that the technical nesting level never actually hits zero in between them :) Have to confess, though, I've had some fairly large functions in C++ (not as big as the aforementioned, but still fairly large - what's the next one down from gigantic, megantic? [1] would suggest so), which in some cases could be split if I felt like putting in the time to do it. ChrisA [1] http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=370794