Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'something,': 0.07; 'suggesting': 0.07; 'python': 0.08; 'arguments,': 0.09; 'mapped': 0.09; "object's": 0.09; 'object?': 0.09; 'tuple': 0.09; 'am,': 0.12; 'argument': 0.15; '"programming': 0.16; 'constructor,': 0.16; 'constructor.': 0.16; 'did,': 0.16; 'lisp': 0.16; 'subject:OOP': 0.16; 'wrote:': 0.16; 'cheers,': 0.18; 'functions,': 0.18; 'programming': 0.20; 'seems': 0.20; 'compatible': 0.21; 'header:In-Reply-To:1': 0.22; '(or': 0.23; 'objects,': 0.23; 'sep': 0.23; 'somehow': 0.23; 'suggests': 0.23; 'input': 0.24; 'variable': 0.24; 'creating': 0.25; 'string': 0.26; 'function': 0.27; 'beyond': 0.28; 'sat,': 0.28; 'message- id:@mail.gmail.com': 0.29; 'arguments.': 0.30; 'oop': 0.30; '(e.g.': 0.31; 'functional': 0.31; 'received:209.85.161.46': 0.31; 'received:mail-fx0-f46.google.com': 0.31; 'values': 0.32; 'value.': 0.32; 'generally': 0.32; 'objects': 0.32; 'does': 0.32; 'too': 0.33; 'to:addr:python-list': 0.33; 'things': 0.34; 'function.': 0.34; 'implies': 0.34; 'rather': 0.35; 'external': 0.35; 'object': 0.35; 'received:209.85.161': 0.35; 'another': 0.37; 'example,': 0.37; 'depend': 0.37; 'opposed': 0.37; 'languages': 0.37; 'model': 0.37; 'using': 0.37; 'think': 0.38; 'maps': 0.38; 'some': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'missing': 0.39; 'to:addr:python.org': 0.39; 'sense': 0.39; 'called': 0.40; 'raw': 0.40; 'where': 0.40; 'results': 0.61; 'traditional': 0.64; 'taking': 0.66; 'william': 0.68; 'research,': 0.82; 'strings)': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=pki+xBGAoopt9fPz/fTD390YZkXVbwv0yavTaFh7Zbw=; b=H5tZ/BKOmrTfRChfFSbneCKt59o5sAzYab0efuZhkVhZCBPwKWmVcfY4CUulFFDKRT Sk5xuHsBh+2PEpCj4r/y1Px2NcEwTu8mBF/rWmzVg03FOT/8Ulxkb++1CXkvaPjpnqpS qYwONBnoDWcuNgGKw5NEPxaO8PMy+ChR+tM2k= MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Sat, 3 Sep 2011 12:50:14 -0600 Subject: Re: Functions vs OOP To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1315075846 news.xs4all.nl 2420 [2001:888:2000:d::a6]:39138 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12714 On Sat, Sep 3, 2011 at 10:15 AM, William Gill wrot= e: > During some recent research, and re-familiarization with Python, I came > across documentation that suggests that programming using functions, and > programming using objects were somehow opposing techniques. > > It seems to me that they are complimentary. =A0It makes sense to create > objects and have some functions that take those objects as arguments. Are > they suggesting that any function that takes an object as an argument sho= uld > always be a method of that object? =A0Conversely I can see creating funct= ions > that take raw input (e.g. strings) and return it in a format compatible w= ith > an object's constructor, rather than have objects accept any conceivable > format for its constructor. > > Am I missing something, or am I taking things too literally? I think you may be confusing "functional programming" and "programming using functions". These are not the same thing. Functional programming is about using functions in the *mathematical* sense. A mathematical function maps one value (or tuple of values) to another value. The mapped value never varies; if it did, it would be a different function. So functional programming eschews the use of functions where the results depend on any internal or external state beyond the values of the passed-in arguments, such as the variable state of the object the method is being called on. Functional programming and OOP are not entirely opposed -- for example, string methods in Python such as str.upper are perfectly functional, since strings are immutable. Many functional languages such as Common LISP also have powerful OOP facilities. Still, functional programming does not fit well with the traditional OOP model of objects passing messages to other objects, which generally implies statefulness. Cheers, Ian