how to avoid leading white spaces

rusi rustompmody at gmail.com
Wed Jun 8 04:27:54 EDT 2011


On Jun 7, 11:37 pm, "ru... at yahoo.com" <ru... at yahoo.com> wrote:
> On 06/06/2011 08:33 AM, rusi wrote:
>
> > For any significant language feature (take recursion for example)
> > there are these issues:
>
> > 1. Ease of reading/skimming (other's) code
> > 2. Ease of writing/designing one's own
> > 3. Learning curve
> > 4. Costs/payoffs (eg efficiency, succinctness) of use
> > 5. Debug-ability
>
> > I'll start with 3.
> > When someone of Kernighan's calibre (thanks for the link BTW) says
> > that he found recursion difficult it could mean either that Kernighan
> > is a stupid guy -- unlikely considering his other achievements. Or
> > that C is not optimal (as compared to lisp say) for learning
> > recursion.
>
> Just as a side comment, I didn't see anything in the link
> Chris Torek posted (repeated here since it got snipped:http://www.princeton.edu/~hos/frs122/precis/kernighan.htm)
> that said Kernighan found recursion difficult, just that it
> was perceived as expensive.  Nor that the expense had anything
> to do with programming language but rather was due to hardware
> constraints of the time.
> But maybe you are referring to some other source?

No the same source, see:

> In his work Kernighan also experimented with writing structured and unstructured programs.
> He found writing structured programs (programs that did not use goto's) difficult at first,
> but now he cannot imagine writing programs in any other manner.  The idea of recursion
> in programs also seemed to develop slowly; the advantage to the programmer was clear,
> but recursion statements were generally perceived as expensive, and thus were discouraged.

Note the also -- it suggests that recursion and structured programming
went together for Kernighan.

>
> > Evidently for syntactic, implementation and cultural reasons, Perl
> > programmers are likely to get (and then overuse) regexes faster than
> > python programmers.
>
> If by "get", you mean "understand", then I'm not sure why
> the reasons you give should make a big difference.  Regex
> syntax is pretty similar in both Python and Perl, and
> virtually identical in terms of learning their basics.

Having it part of the language (rather than an import-ed module makes
for a certain 'smoothness' (I imagine)

> There are some differences in the how regexes are used
> between Perl and Python that I mentioned in http://groups.google.com/group/comp.lang.python/msg/39fca0d4589f4720?,
> but as I said there, that wouldn't, particularly in light
> of Python culture where one-liners and terseness are not
> highly valued, seem very important.  And I don't see how
> the different Perl and Python cultures themselves would
> make learning regexes harder for Python programmers.  At
> most I can see the Perl culture encouraging their use and
> the Python culture discouraging it, but that doesn't change
> the ease or difficulty of learning.

See Roy's answer.


> What if a Perl programmer says that Python programmers under-use regexes?

That's what I gather they would say (and I guess you and I agree its
true?)

>
> And why do you say "overuse" regexs?  Why isn't it the case
> that Perl programmers use regexes appropriately in Perl?  Are
> you not arbitrarily applying a Python-centric standard to a
> different culture?  


>
> > 1 is related but not the same as 3.  Someone with courses in automata,
> > compilers etc -- standard CS stuff -- is unlikely to find regexes a
> > problem.  Conversely an intelligent programmer without a CS background
> > may find them more forbidding.
>
> I'm not sure of that.  (Not sure it should be that way,
> perhaps it may be that way in practice.)  I suspect that
> a good theoretical understanding of automata theory would
> be essential in writing a regex compiler but I'm not sure
> it is necessary to use regexes.
>
> It does I'm sure give one a solid understanding of the
> limitations of regexes but a practical understanding of
> those can be achieved without the full course I think.

How do you answer when a regex-happy but CS-illiterate programmer asks
for a regex to match parenthesis?

Anyway you may be right and this is quite far from my main points --
which I would like to iterate:

1. regexes were invented by automata-theorists and used mostly-
unchanged by early unix hackers.
   This works upto a point and fails badly when they get too large.
2. Larry Walls suggestions are on the whole good and python can
leapfrog over Perl by implementing them, especially given that it is
much easier for python to add a newRe module than for perl5 to become
perl6.
3. A big problem with regexes is not having re-debuggers. Things like
emacs' re-builder, regex-tool and python's native kodos need more
visibility



More information about the Python-list mailing list