char** to {'':('',)}

Grant Griffin not.this at seebelow.org
Fri Aug 31 18:01:07 CEST 2001


In article <mailman.999116565.21504.python-list at python.org>, "Tim says...
>
>[Ignacio Vazquez-Abrams]
>> I am using the following blecherous code to do a conversion from
>> char*s in the form "<a>=<b>" to the form {'<a>':(tuple of '<b>'s), ...}.
>> I'm sure that there's probably a more straightforward way out there.
>> Does anyone have any ideas as to how I can simplifiy this?
>
>Ya, write it in Python -- coding in C is a PITA.  If you need to do it in C
>for speed (whatever), don't be afraid of gotos!

I've been developing a theory that people who use 8 spaces per indent (via hard
tabs) become less afraid of gotos than the rest of us <wink>.

>The Python implementation
>has many examples of this, jumping to an error label at the end when things
>go wrong "in the middle".

That's a good reason.  (I've also found gotos quite helpful in converting
Fortran to C <wink>.)

I can't say I use them much, but I _am_ a big fan of the "almost-goto"
constructs like return, break, and continue.  In particular, I like to do early
returns to avoid needless nesting.

Coincidentally, I thought I'd seen everything there was to see about gotos until
just yesterday, when I saw a new form that I had never ever seen (or even
thought of) before.  It goes to this:

   bool foo()
   {
       bool flag = false;
       for (;;)
       {
           if (x)
           {
              flag = true; 
              break;
           }

           do_stuff;

           if (y)
           {
               flag = true;
               break;
           }

           do_more_stuff;

           break;
       }

       return flag;
   }

whereas any sensible person would have done:

   bool foo()
   {
       if (x)
          return true;

       do_stuff;

       if (y)
          return true;

       do_more_stuff;

       return false;
   }

or maybe even used gotos <wink>.  This construct occurred repeatedly throughout
the code.  The author considered it to be a "feature".

a-drawing-should-have-no-unnecessary-lines-and
   -a-machine-should-have-no-unnecessary-parts-ly y'rs,

=g2

_____________________________________________________________________

Grant R. Griffin                                       g2 at dspguru.com
Publisher of dspGuru                           http://www.dspguru.com
Iowegian International Corporation            http://www.iowegian.com




More information about the Python-list mailing list