python vs awk for simple sysamin tasks

Steve Lamb grey at despair.dmiyu.org
Fri Jun 4 16:41:59 EDT 2004


On 2004-06-04, William Park <opengeometry at yahoo.ca> wrote:
> I realize that this is Python list, but a dose of reality is needed
> here.  This is typical view of salary/wage recipient who would do
> anything to waste time and money.  How long does it take to type out
> simple 2 line shell/awk script?  And, how long to do it in Python?

    No, that is the view of someone who wants to get the job done and save
time/money.

    How long does it take to write out a simple 2 line shell/awk script?  Not
that long.  How long does it take to do it in Python?  Maybe a dozen or so
minutes longer.  Yay, I save a few minutes!

    How long does it take me to modify that script a few weeks later when my
boss asks me, "Y'know, I could really use this and this."  In shell, quite a
few minutes, maybe a half hour.  Python?  Maybe 10 minutes tops.

    How long does it take me to modify it a month or two after that when my
boss tells me, "We need to add in this feature, exclusions are nice, and what
about this?"  Shell, now pushing a good 30-40m.  Python, maybe 15m.

    How long does it take me to rewrite it into a decent language when my boss
wonders why it is taking so long and the SAs are bitching at me because of the
runtimes of my shell script?  In shell, an hour or two.  In Python, oh, wait,
I don't have to.

    Not gonna happen, ya say?  Piffle.  The only difference in the above
example was that I wasn't the one who made the choice to write the tool in
shell in the first place and the language I rewrote it in (to include the
exclusions they wanted which shell seemed incalable of doing) was Perl instead
of Python.  I had the RCS revisions all the way back to the time when it was a
wee little shell script barely 3-4 lines long.  

    Now, if you like flexing your SA muscle and showing off how cool you are
by being able to whip out small shell scripts to do basic things, that's cool.
Go for it.  But the reality check is that more time is saved in the long run
by spending the few extra minutes to do it *properly* instead of doing it
*quickly* because in the long run maintenance is easier and speed is
increased.  It is amazing how much shell bogs down when you're running it over
several hundred thousand directories.  :P

> "Right tool for right job" is the key insight here.  Just as Python
> evolves, other software evolves as well.

    What you're missing is that the job often evolves as well so it is better
to use a tool which has a broader scope and can evolve with the job more so
than the quick 'n dirty, get-it-done-now-and-to-hell-with-maintainability,
ultra-specialized, right-tool-for-the-job tool.

    Do I use one-liners?  All the time.  When I need to delete a subset of
files or need to parse a particular string out of a log-file in a one-off
manner.  I can chain the tools just as effectively as the next guy.  But
anything more than that and out comes Python (previously Perl) because I
*knew* as soon as I needed a tool more than once I would also find more uses
for it, would have more uses of it requested of me and I'd have to maintain it
for months, sometimes years to come.  

-- 
         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
       PGP Key: 8B6E99C5       | main connection to the switchboard of souls.
-------------------------------+---------------------------------------------



More information about the Python-list mailing list