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


Groups > comp.lang.python > #38043

Re: Best approach to OO Style (only slightly off topic)?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'classes.': 0.07; 'layers': 0.07; 'main()': 0.07; 'think,': 0.07; 'used.': 0.07; 'welcome.': 0.07; 'python': 0.09; '"my': 0.09; 'code"': 0.09; 'curve': 0.09; 'logic': 0.09; 'mvc': 0.09; 'separating': 0.09; 'worse': 0.09; 'looked': 0.10; 'gui': 0.11; 'itself.': 0.11; 'ignore': 0.13; 'steve': 0.13; 'sat,': 0.15; '"business': 0.16; '"user': 0.16; 'design:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'interface"': 0.16; 'prefer.': 0.16; 'simplest': 0.16; 'subject:)?': 0.16; 'with?': 0.16; 'wrote:': 0.17; "shouldn't": 0.17; 'code,': 0.18; 'feb': 0.19; 'code.': 0.20; 'changes': 0.20; 'all,': 0.21; 'orientation': 0.22; 'programming': 0.23; 'flexibility': 0.23; 'seems': 0.23; 'idea': 0.24; 'header :In-Reply-To:1': 0.25; 'am,': 0.27; 'separate': 0.27; 'wonder': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'there.': 0.28; 'class': 0.29; "i'm": 0.29; 'ease': 0.30; 'code': 0.31; 'point': 0.31; 'generally': 0.32; 'could': 0.32; 'point,': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'done': 0.34; 'massive': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'add': 0.36; 'really': 0.36; 'but': 0.36; 'smaller': 0.36; "didn't": 0.36; 'anything': 0.36; 'should': 0.36; 'too': 0.36; 'subject: (': 0.36; 'level': 0.37; 'two': 0.37; 'why': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; 'sure': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'application': 0.40; 'end': 0.40; 'think': 0.40; 'your': 0.60; 'most': 0.61; 'high': 0.61; 'face': 0.61; 'kind': 0.61; "you'll": 0.62; 'truly': 0.62; 'more': 0.63; 'bothered': 0.65; 'harder': 0.65; 'plan,': 0.65; 'subject:off': 0.65; 'want,': 0.65; 'fact,': 0.69; 'grow': 0.74; '2013': 0.84; 'challenge.': 0.84; "else's": 0.84; 'simmons': 0.84; 'subject:Best': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=4NqNuELD1TfjvaDnPpTaZjPHD/d+LQUsCGpnE8vtlTE=; b=XK1MTQLCcUJKd8Di72vj6hPLvIQtFjPYghzEi22UdkSlSPcZFTBn6H8QWwhN+GfVKE mXtlsM5+SBFLDVyyQcXwk2OUAbFHBes52eiYkEH5bJJuEZvW2Lh1FIut7C0+ZWKPVO5d RP/Edg+C1fqWhxN++Vy0Vz/h6CXCAr0W/qLCLiNswRFApNTlVH8CQqDUcv91UKV/0BJi R3H+SLKZHw1xp7tRAHIAa27nSzNi3cU95yhOo8E3BlwJQEtbDd6NzEhoDiXR+/6HVZWN FYZcdo4diHGkmMUTG6R0no9GTkZm3wX4uraQaX4qFdcHTOgUWDbCgWXQjPIveYIp5Ka3 7npQ==
MIME-Version 1.0
X-Received by 10.220.149.200 with SMTP id u8mr10361225vcv.7.1359731863701; Fri, 01 Feb 2013 07:17:43 -0800 (PST)
In-Reply-To <510BD022.5070402@gmail.com>
References <510BD022.5070402@gmail.com>
Date Sat, 2 Feb 2013 02:17:43 +1100
Subject Re: Best approach to OO Style (only slightly off topic)?
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.1280.1359731866.2939.python-list@python.org> (permalink)
Lines 48
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1359731867 news.xs4all.nl 6916 [2001:888:2000:d::a6]:48908
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38043

Show key headers only | View raw


On Sat, Feb 2, 2013 at 1:24 AM, Steve Simmons <square.steve@gmail.com> wrote:
> At this point, I began to wonder what a 'correctly structured' OO program
> should look like. Should I separate GUI logic from 'business' logic?  Should
> everything be in one class?  Should my main() be carrying the high level
> logic?  Anyinput most welcome.
>
> I looked briefly at the MVC model which answers my question at a high level
> but itrepresents another learning curve that I'm reluctant to add to my
> current challenge.

Rule #0 of design: There's always a worse pattern you could have used.

Python gives you all the flexibility you could want. And with that
flexibility comes ease of complication. The key is to find the
simplest design that will accomplish what you want, and go from there.

The idea of separating out "business logic" from "user interface"
seems all very well on the face of it, but it's often harder than you
might think, and when you force an application into that kind of
segregation, you'll often end up with thin layers around one or the
other so there's really UI code interspersed with "guts" code despite
your best efforts. Drastically changing your UI will generally involve
lots of code changes anyway, so don't be too bothered if you find you
need to change something that didn't feel like "user interface" code.

Model/View/Controller systems tend, imho, to be massive overkill for
anything smaller than Huge. In fact, I can't point to any MVC system
that fitted onto a single computer that couldn't have been done better
with something rather simpler.

Above all, don't have one class for "someone else's code" and one for
"my code" unless there's some really REALLY good reason for it. A
better model in Python would be to have two *modules*, not two
classes.

But there are myriad ways you could lay out your code, and few of them
are truly *wrong*. The most important thing to do is to think about
what you do; plan, don't just let it grow by itself. The plan
shouldn't be chiseled into basalt, but any time you change it, be sure
you know why you're changing it.

You say you're new to OO; what programming model(s) are you more
familiar with? Python doesn't force you into object orientation - you
can ignore it and just work with imperative code, if you prefer.

All the best!

ChrisA

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


Thread

Re: Best approach to OO Style (only slightly off topic)? Chris Angelico <rosuav@gmail.com> - 2013-02-02 02:17 +1100

csiph-web