[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash vs. python scripts - which one is better?

Vincent Lefevre wrote:
> Braces are not a problem: they are kept in a copy-paste, and if for
> some reason a brace is missing (because you did a mistake), then you'll
> get a syntax error 

    Unless, of course, you are programming in C with that pesky...


> In Python, you may need to re-indent (correctly!) all what you've
> copy-pasted, and if you forget an indentation, the syntax will still
> be valid.

    Which is not that hard.  Have you done it?  Doubt it.  I have, many times.
   Say I'm 3 levels deep and paste something 2 levels deep.  Like this:

            for foo in bar:
        if foo > 200:
            print baz
            print spam

    First off, that's an error in Python.  Don't believe me?

>>> if '1':
...     if '2':
...             for foo in bar:
...         if foo > 200:
  File "<stdin>", line 4
    if foo > 200:
IndentationError: unindent does not match any outer indentation level

    Secondly, as I stated earlier, any programmer's editor will be able to
indent by blocks.  I know vim and idle can, pretty sure emacs can as well for
those of that sect.  So you mark the four lines and indent twice.  Viola, you
have a working script!  The secret is that while the block may not match the
indentation of your code it pretty much will be consistent to itself.  If it
isn't you have far more problems than a simple block alignment.

    Also, as I said, would you really trust someone who doesn't reindent their
code so they can read it even if they are cut and pasting code with braces?

> In languages like Perl, the indentation can automatically be done by
> the editor (and checked by the developer in real time), and after a
> copy-paste, the indentation can be fixed automatically, without any
> ambiguity.

    Presumed ambiguity.  There is no ambiguity here.  The code runs as it is
indented, not how the computer sees it vs. how the human reads it.

> If you need to paste code from web pages (that could be mailing-list
> archives, for instance), whitespace can have already changed by
> generic tools.

    Still not a problem.  Like I said, I've been doing this for years and so
far the gains from significant whitespace have far outstripped the exceedingly
rare times it ever was a problem for me.  I chose that phrasing because I feel
like it must have been a problem at least once but can't recall a single time.
 It is that insignificant.

Reply to: