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


Groups > comp.lang.python > #50526

Re: Understanding other people's code

References <66c25416-eaa5-4ac1-a71d-2b2948dec2fb@googlegroups.com>
Date 2013-07-13 00:46 +1000
Subject Re: Understanding other people's code
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.4633.1373640379.3114.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, Jul 13, 2013 at 12:22 AM, L O'Shea <lo0446@my.bristol.ac.uk> 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 understanding other peoples code. There has to be 10/15 different scripts with at least 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

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


Thread

Understanding other people's code "L O'Shea" <lo0446@my.bristol.ac.uk> - 2013-07-12 07:22 -0700
  Re: Understanding other people's code Chris Angelico <rosuav@gmail.com> - 2013-07-13 00:46 +1000
  Re: Understanding other people's code Peter Otten <__peter__@web.de> - 2013-07-12 17:21 +0200
  Re: Understanding other people's code "Eric S. Johansson" <esj@harvee.org> - 2013-07-12 12:04 -0400
  Re: Understanding other people's code Terry Reedy <tjreedy@udel.edu> - 2013-07-12 18:11 -0400
  Re: Understanding other people's code Joel Goldstick <joel.goldstick@gmail.com> - 2013-07-12 19:49 -0400
  Re: Understanding other people's code CM <cmpython@gmail.com> - 2013-07-13 23:58 -0700
  Re: Understanding other people's code Azureaus <lo0446@my.bristol.ac.uk> - 2013-07-15 03:02 -0700
    Re: Understanding other people's code CM <cmpython@gmail.com> - 2013-07-15 12:13 -0700
    Re: Understanding other people's code albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-27 13:13 +0000
      Re: Understanding other people's code Chris Angelico <rosuav@gmail.com> - 2013-07-27 14:41 +0100
  Re: Understanding other people's code asimjalis@gmail.com - 2013-07-15 19:10 -0700
  Re: Understanding other people's code David M Chess <chess@us.ibm.com> - 2013-07-16 14:38 -0400
  Re: Understanding other people's code David Hutto <dwightdhutto@gmail.com> - 2013-07-16 20:05 -0400
  Re: Understanding other people's code David Hutto <dwightdhutto@gmail.com> - 2013-07-19 22:57 -0400
  Re: Understanding other people's code Azureaus <lo0446@my.bristol.ac.uk> - 2013-07-25 09:26 -0700

csiph-web