[NTLUG:Discuss] Python Article by Eric S Raymond
Carl Haddick
sysmail at glade.net
Fri May 8 08:52:48 CDT 2009
On Thu, May 07, 2009 at 01:52:12PM -0500, Val Harris wrote:
> On this list, we occasionally see requests for programming language
> recommendations. Here is an interesting article about Python, written
> by one who has wrestled more than a few project past the faults of its
> chosen language:
>
> http://www.linuxjournal.com/article/3882
First, disclaimers - I've long been a Python patriot, and I'm just a
lurker here so feel free to take me with a grain of salt. For some
reason, this just seemed like a good thing to rattle on about.
I, too, seek no flame war. Perl is a proven tool with awesome
potential.
>From the perspective of already being appreciative of Python there is
nothing in that article that I disagree with much, and some powerful
Python features that were overlooked, such as ease of debugging.
The whitespace indentation seems horrific as syntax, but only until you
use it and start forgetting the original disgust. Vim and emacs will
both handle the indentation for you, anyway.
If that's still not enough, consider how Perl hackers don't mind
shift-and-flicker variables like $_.
Better yet, consider any program in Python can be typed in interactively
and tested in pieces. Any program. Defining objects, importing obects,
those metaclasses in the article, file manipulation, _any_ Python
program. For yet fancier support and built-in help text use Idle, the
Python debugger. Or don't, command line debugging is pretty cool and
there is nothing to learn. Just type Python code in and mess with it
from the Python prompt. Come to think of it, the help function works on
the command line, too, and adding your own documentation is just a
matter of putting your docs in a string before anything else in a
function or class.
Python's idea of objects is like object code without all the
bureaucracy. Forget friends, public, and private elements - I use
Python classes all the time to build testable units of code. That's the
power of Python objects, to me. Once a class does what I want it to I
can romp on it and it won't break.
My first Python project was a web site for news, before the contraction
'blog' ever joined the popular vernacular. I spent three days and had a
web-based gizmo that published pages, accepted drafts, let me upload and
embed pictures, resized and rotated pictures, all kinds of bells and
whistles.
After three days of work it was put into production on a site getting
about 60,000 hits per month and ran without modification for the next
five years or so. No bugs.
In earlier versions of Python I thought Perl had a little performance
edge over Python, but I don't think that's a wide gap these days. Even
if it is, the possibility of writing without error wins the day as I
balance the equation.
As far as learning the language, I know I was able to write my first
project faster in Python, including the time it took to learn the
language, than I could have in Perl. By multiples, maybe even an order
of magnitude.
The article commented on regular expressions being easier in Perl, and
that may be true. However, Python's support isn't so bad:
====================
import re # get the regular expression stuff
targetregex=re.compile(r'linux\s+user')
def showregex(filename):
"""
Here's what the 'help' function will show (this string).
Showregex is a quick demonstration of compiled regexes. To my eye,
this is easier to follow that Perl. More typing, by a little, but
also more self-documenting.
And now, back to regularly expressive programming...
"""
for l in file(filename): # spin through the file, line by line
if targetregex.search(l): # check for a hit
print 'bingo: %s'%l.strip() # print, trimming white space
====================
But why am I posting all this? It's really quite an ingenious plot.
You see, nobody ever listens to me, ergo, if I thump my chest about
Python everybody else will use Perl, looking down at me for my
kindergarten ways.
Which leaves me with my secret weapon, Python, ALL TO MYSELF!!!
:-)
Seriously, there are many good tools out there. Python gets overlooked
too much, and is worth a glance if you're curious.
Now, for a real 'scripting' language, I remember back in the days when I
ran an MP/M 86 box for a desktop system, I had a project to control
stepper motors (in complex ways) with an eight bit processor. It was
thought to be at least several months of coding.
First, I implemented a version of Forth from scratch with a cross
assembler, then I wrote some assembler primitives, then I put a high
level wrapper around those in Forth, and was finished with my part of
the project in about three weeks.
Python is like that. You can start with zero knowlege in Python and get
running quick. Later, when you come back to a cold project, you can
start from the position of having forgotten everything about the project
and get back up to speed, quick.
And Perl is obviously very effective, too.
Meanwhile, back at the ranch,
Carl
More information about the Discuss
mailing list