Regular expressions

rurpy at yahoo.com rurpy at yahoo.com
Wed Nov 4 09:38:19 EST 2015


On 11/03/2015 08:48 PM, Steven D'Aprano wrote:
> On Wednesday 04 November 2015 11:33, rurpy wrote:
>
>>> Not quite.  Core language concepts like ifs, loops, functions,
>>> variables, slicing, etc are the socket wrenches of the programmer's
>>> toolbox.  Regexs are like an electric impact socket wrench.  You can do
>>> the same work without it, but in many cases it's slower. But you have to
>>> learn the other hand tools first in order to really use the electric
>>> driver properly (understanding torques, direction of threads, etc), lest
>>> you wonder why you're breaking off so many bolts with the torque of the
>>> impact drive.
>>
>> I consider regexs more fundemental
>
> I'm sure that there are people who consider the International Space Station 
> more fundamental than the lever, the wedge and the hammer, but they would be 
> wrong too.
>
> Given primitives for branching, loops and variables, you can build support 
> for regexes. Given regexes, how would you build support for variables?
>
> Of course, you could easily prove me wrong. All you would need to do to 
> demonstrate that regexes are more fundamental than branching, loops and 
> variables would be to demonstrate that the primitive operations available in 
> commonly used CPUs are regular expressions, and that (for example) C's for 
> loop and if...else are implemented in machine code as regular expressions, 
> rather than the other way around.

I'm afraid you are making a category error but perhaps that's in 
part because I wasn't clear.  I was not talking about computer 
science.  I was talking about human beings learning about computers.  
Most people I know consider programming to be a higher level activity 
than "using" a computer: editing, sending email etc.  Many computer
users (not programmers) learn to use regular expressions as part
of using a computer without knowing anything about programming.
It was on that basis I called them more fundamental -- something
learned earlier which is expanded on and added to later.  But you
have a bit of a point, perhaps "fundamental" was not the best choice
of word to communicate that.

Here is what I wrote:

> I consider regexs more fundemental.  One need not even be a programmer
> to use them: consider grep, sed, a zillion editors, database query 
> languages, etc.

I thought the context, which you removed even to the point cutting 
text from the very same line you quoted, made that clear but perhaps
not.

Indeed it is quite eye-opening when one does learn a little CS and 
discovers these things that were just a useful "feature" actually have 
a deep and profound theoretical basis.



More information about the Python-list mailing list