flowcharting is automatic for Python via preprocessor
Larry Bates
lbates at swamisoft.com
Mon Aug 2 19:20:50 EDT 2004
Small changes eliminate the need for flow
diagram (IMHO).
def f():
"""Demonstration of flow diagrams."""
for i in range(100):
r=i % 3
if r == 2:
print 'Remainder two, stopping loop'
break
if r == 1:
if i < 10: print 'Less than ten'
else: print 'Greater than ten'
continue
print 'Multiple of three'
While I realize your example function was just that
and example (because you could never even get to some
of the branches because it exits when i=5). I see a
lot of code with nested if/elif constructs that are
unnecessary which add to the difficulty of
"deciphering" what is going on.
Larry Bates
Syscon, Inc.
<barnesc at onid.orst.edu> wrote in message
news:mailman.1069.1091487166.5135.python-list at python.org...
>
> I like your idea.
>
> It is easy to get lost inside in eg a multiply nested if statement in a
couple
> multiply nested for loops, inside a try block.
>
> Sometimes one can split such code into separate functions, and this makes
the
> code cleaner. Sometimes not.
>
> However, the real issue is how the eye parses code.
>
> It's really inefficient to scan a whole page of code line by line to
understand
> where loops, branches, continues, and breaks occur.
>
> I think your visual diagrams could help, if they are:
>
> 1. Semantically cleaner.
> IMO, there is too much detail in the flow diagrams.
> (See http://www.getcet.org/images/ex3.png).
>
> A minimal amount of detail is easier to parse with the eye.
>
> See http://oregonstate.edu/~barnesc/temp/flow.pdf for a cleaner
> example I came up with. This doesn't have arrows all over the
> place (and hence may not be a flow diagram), but it does help
> point out the relevant control structures.
>
> 2. Integrated into a code editor.
>
> I could see this being a new code editor fad, like collapsable
> functions and classes.
>
> It could be quite useful, if the amount of visual information
> is kept minimal, so that the coder is not distracted during
> coding.
>
> If the flow diagrams are not integrated into an editor, I don't
> think many coders will use them.
>
> Perhaps editors already do this.
>
> - Connelly
More information about the Python-list
mailing list