Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'scripts': 0.03; 'interpreter': 0.05; '(so': 0.07; 'interpreter.': 0.07; 'subject:code': 0.07; 'tkinter': 0.07; 'tackle': 0.09; 'unrecognized': 0.09; 'project,': 0.12; 'up-to-date': 0.14; 'code),': 0.16; 'command-line': 0.16; 'definition.': 0.16; 'docstring': 0.16; 'dumps': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'guessing': 0.16; 'itertools': 0.16; 'itself,': 0.16; 'namespace.': 0.16; 'say.': 0.16; 'statements,': 0.16; 'sat,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'file,': 0.19; 'import': 0.22; 'source': 0.25; 'possibly': 0.26; 'references': 0.26; 'this:': 0.26; 'second': 0.26; 'least': 0.26; 'skip:" 20': 0.27; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'strongly': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; 'that.': 0.31; '13,': 0.31; 'subject:other': 0.31; 'anyone': 0.31; 'file': 0.32; 'stuff': 0.32; 'third': 0.33; 'comment': 0.34; "i'd": 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'idle': 0.36; 'library.': 0.36; 'starting': 0.37; 'to:addr:python- list': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'even': 0.60; 'skip:u 10': 0.60; 'tips': 0.61; 'entire': 0.61; "you're": 0.61; 'first': 0.61; "you'll": 0.62; 'different': 0.65; 'techniques': 0.66; 'lose': 0.68; 'overall': 0.69; 'jul': 0.74; 'lack': 0.78; 'yourself': 0.78; 'gain': 0.79; 'actually,': 0.84; 'grabbing': 0.84; 'nice,': 0.84; 'seriously,': 0.84; 'subject:people': 0.84; 'understand,': 0.84; 'wipe': 0.84; '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:content-transfer-encoding; bh=n4ADwX/jBJOg3y+myGfIFA2ux5Yc44/gFvWkXvo6hvs=; b=vjeH4KxdseDfYMEAmb3JdcBJMxomEpNAbHAxPeNxvoprzXHY4rA+dBzr3YiB/68gVi rG0GQ4ccL9Vgamd80s0BfYYKDYUAb683Z2YGf5FpG/9OQOv7Y7sHXlDQEXLboETIu6wg apQDOnW4m431wfUVFl3yN/+mMmBAqXDYyn4DWKhx8GoQbrmeKlU8++9gSLq3cU4FHFG8 n8ndQntO+QrGn9U9lXF09F8opBuZFH0Hg5hK7OjO7BEDGdS997Ofmp6AQ87JZkc3cdVP WMuzQhEOU09shG9DCK2c0o1W5p2Oib9N4DNLNgIdnrdiEn2uCgLnAMfmmhBUDDC55k/F D+KA== MIME-Version: 1.0 X-Received: by 10.58.187.4 with SMTP id fo4mr24657459vec.55.1373640375853; Fri, 12 Jul 2013 07:46:15 -0700 (PDT) In-Reply-To: <66c25416-eaa5-4ac1-a71d-2b2948dec2fb@googlegroups.com> References: <66c25416-eaa5-4ac1-a71d-2b2948dec2fb@googlegroups.com> Date: Sat, 13 Jul 2013 00:46:15 +1000 Subject: Re: Understanding other people's code From: Chris Angelico 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.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: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373640379 news.xs4all.nl 15966 [2001:888:2000:d::a6]:37459 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50526 On Sat, Jul 13, 2013 at 12:22 AM, L O'Shea wrote: > I'm starting to get pretty worried about my lack of overall progress and = so I wondered if anyone out there had some tips and techniques for understa= nding other peoples code. There has to be 10/15 different scripts with at l= east 10 functions in each file I would say. The first thing I'd recommend is getting yourself familiar with the language itself, and (to some extent) the standard library. Then you'll know that any unrecognized wotzit must have come from your own project, so you'll be able to search up its definition. Then I'd tackle source files one at a time, and look at the very beginning. If the original coder was at all courteous, each file will start off with a block of 'import' statements, looking something like this: import re import itertools Or possibly like this: from itertools import cycle, islice Or, if you're unlucky, like this: from tkinter import * The first form is easy. You'll find references to "re.sub" or "itertools.takewhile"; the second form at least names what it's grabbing (so you'll find "cycle" or "islice" in the code), and the third just dumps a whole lot of stuff into your namespace. Actually, if the programmer's been really nice, there'll be a block comment or a docstring at the top of the file, which might even be up-to-date and accurate. But I'm guessing you already know to look for that. :) The other thing I would STRONGLY recommend: Keep the interactive interpreter handy. Any line of code you don't understand, paste it into the interpreter. Chances are it won't wipe out your entire hard drive :) But seriously, there is much to gain and nothing to lose by keeping IDLE or the command-line interpreter handy. ChrisA