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


Groups > comp.lang.python > #50725

Re: Ideal way to separate GUI and logic?

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 <rosuav@gmail.com>
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 <b8d83518-77f9-4b09-8b6b-f8e6c84efa50@googlegroups.com> <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 <rosuav@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4754.1373944739.3114.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Tue, Jul 16, 2013 at 10:25 AM,  <fronagzen@gmail.com> 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

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


Thread

Ideal way to separate GUI and logic? fronagzen@gmail.com - 2013-07-13 04:07 -0700
  Re: Ideal way to separate GUI and logic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-13 11:43 +0000
  Re: Ideal way to separate GUI and logic? Roland Koebler <r.koebler@yahoo.de> - 2013-07-13 15:56 +0200
  Re: Ideal way to separate GUI and logic? Dave Cook <davecook@nowhere.net> - 2013-07-13 17:40 +0000
  Re: Ideal way to separate GUI and logic? Wayne Werner <wayne@waynewerner.com> - 2013-07-13 14:03 -0500
    Re: Ideal way to separate GUI and logic? fronagzen@gmail.com - 2013-07-14 17:24 -0700
    Re: Ideal way to separate GUI and logic? fronagzen@gmail.com - 2013-07-14 17:25 -0700
      Re: Ideal way to separate GUI and logic? Joel Goldstick <joel.goldstick@gmail.com> - 2013-07-14 21:02 -0400
        Re: Ideal way to separate GUI and logic? Roy Smith <roy@panix.com> - 2013-07-14 21:30 -0400
      Re: Ideal way to separate GUI and logic? Steven D'Aprano <steve@pearwood.info> - 2013-07-15 01:44 +0000
  Re: Ideal way to separate GUI and logic? asimjalis@gmail.com - 2013-07-15 10:06 -0700
    Re: Ideal way to separate GUI and logic? fronagzen@gmail.com - 2013-07-15 17:25 -0700
      Re: Ideal way to separate GUI and logic? Owen Marshall <o@owenmarshall.invalid> - 2013-07-16 00:42 +0000
      Re: Ideal way to separate GUI and logic? Asim Jalis <asimjalis@gmail.com> - 2013-07-15 18:02 -0700
      Re: Ideal way to separate GUI and logic? Chris Angelico <rosuav@gmail.com> - 2013-07-16 13:18 +1000

csiph-web