Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Bernardo Sulzbach Newsgroups: comp.lang.python Subject: Re: When I need classes? Date: Mon, 11 Jan 2016 22:53:44 -0200 Lines: 28 Message-ID: References: <56927b37$0$1586$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de vVKITV4iBEWp563kBU8IFAVkgbuZbUt5OxRfOTGEaeKA== Return-Path: 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; 'classes,': 0.05; 'think,': 0.05; 'classes.': 0.07; 'function),': 0.09; 'script,': 0.09; 'python': 0.10; 'jan': 0.11; 'interpreter': 0.15; '(when': 0.16; '2016': 0.16; 'feasible': 0.16; 'instantiate': 0.16; 'readability.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'scratch': 0.16; 'simplifies': 0.16; 'travis': 0.16; 'user- defined': 0.16; 'why,': 0.16; 'wrote:': 0.16; 'subject:need': 0.18; 'math': 0.20; 'do.': 0.22; 'java': 0.22; 'c++,': 0.22; 'suppose': 0.22; 'tuples': 0.22; 'pass': 0.22; 'am,': 0.23; 'wrote': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'script': 0.25; 'message-id:@mail.gmail.com': 0.27; 'purposes.': 0.29; 'classes': 0.30; 'good.': 0.32; 'point': 0.33; 'class': 0.33; 'problem': 0.33; 'though.': 0.33; 'handle': 0.34; 'add': 0.34; 'gets': 0.35; 'received:google.com': 0.35; 'quite': 0.35; 'but': 0.36; 'project': 0.36; 'received:209.85': 0.36; 'to:addr :python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:209': 0.38; 'data': 0.39; 'application': 0.39; 'enough': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'organization': 0.60; 'your': 0.60; 'making': 0.62; 'more': 0.63; 'different': 0.63; 'experience.': 0.66; '9:45': 0.84; 'around,': 0.84; 'bernardo': 0.84; 'enhances': 0.84; 'oo"': 0.84; 'subject:When': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=XSt6T8tR110Lk+RBFT6OauaDKbGgYBOp/Pv0JMOkw+0=; b=sdCKlkzFU+ZH3Q0GePM/Uz0Wm89cAO7InmOUGM4vueNWf63ARTWulB5SFHBMjxvJOw 14VBLhOMJw5+Tzt++NIc3mvfOYk0U3KbQfy8DdKVE1uQGl9YmX90KER2KA+itQTndL/q Q9JkhUmfJK32Spn8swDZfmkEgpys4jYOBgZSAfVNq8L6ZWA2tz/vqM4SH4yJQUcK6Lic PrFXRmPdafH+YznhXVhxKR/W3BjnLFL/k43k81FQNFkFJO/4/G9pP+ofhaFSzaRukIsn JDL2hcFRVnx9o0l9Hy2cJ87t9oJI8R879BNGG97wM1lnnSaagYB+8kbsd4B4JjuAvTvi 1P+A== X-Received: by 10.112.147.4 with SMTP id tg4mr19762lbb.125.1452560063956; Mon, 11 Jan 2016 16:54:23 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101505 On Mon, Jan 11, 2016 at 9:45 PM, Travis Griggs wrote: > >> On Jan 10, 2016, at 9:48 AM, Bernardo Sulzbach wrote: >> >> Essentially, classes (as modules) are used mainly for organizational purposes. >> >> Although you can solve any problem you would solve using classes >> without classes, solutions to some big problems may be cheaper and >> more feasible using classes. > > I think, this is often why, for a simple script, OO just kind of gets in the way. You have a straightforward procedure that you just want to do. The state (data) is not rich enough to make making it the focal point of your program. Your answer is quite good. I am not a purist myself (when it comes to Java and C++, I am never going to instantiate a Math class to get a logarithm function), but I understand the value of OO from experience. As I mentioned those "tuples and dictionaries" to pass data around, I would like to add that when a single script has two kinds of tuples or dictionaries, you may be better of using two different classes, as having "dedicated" types simplifies project organization and enhances readability. I have never gone "seriously OO" with Python though. I never wrote from scratch an application with more than 10 classes as far as I can remember. However, I would suppose that the interpreter can handle thousands of user-defined classes simultaneously. -- Bernardo Sulzbach