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

Re: Tabs v.s. spaces



>>>>> "Tom" == Tom  <tb.31112.nospam@comcast.net> writes:

    Tom> Do whitespace mistakes cause compile time errors?  The frustrating
    Tom> thing about fortran was variable names that started with C could be
    Tom> interpreted as comments not indented correctly, which would just
    Tom> cause that line to be skipped.

Normally Python has no distinction between compile time and run time: it is
interpreted (there is a project called Psyco to compile Python code,
though).  But yes, wrong whitespace stops you from running your code.
Unlike Fortran, when this happen you happily accept that it is your error.
E.g., you will not be able to run your code if you write

  def fibo(n):
      curr = 1
        next = 1  # wrong indentation -> can't run
      i = 0
      while i < n:
      curr, next = next, next+curr  # no indent after while, fail
      i = i + 1
      return curr

instead of

def fibo(n):
      curr = 1
      next = 1
      i = 0
      while i < n:
          curr, next = next, next+curr
          i = i + 1
      return curr

because the interpretor won't understand what you mean.  I bet that if you
try to write the first version you'll happily say "okay, my fault".

    Tom> Integer literals not indented correctly could be interpreted as
    Tom> line numbers and would really cause havoc with computed gotos.

That's fixed-width nonsense does not appear in Python at all.

    Tom> I.e., they were as super-frustrating to debug as misspelled
    Tom> variable names in a declaration-less language, or the types of
    Tom> bizarre situtations you get into in C when you start overwriting
    Tom> memory.

Python is declaration-less, to let you down.  But then, unit testing is
easier in Python than in C.

    Tom> If whitespace mistakes are always caught at compile-time, then I
    Tom> probably wouldn't care about them either.  So I'm not bashing
    Tom> python; having never used it: I'm bashing languages where syntatic
    Tom> mistakes are not caught at compile-time.  I have no idea if Python
    Tom> is in that category or not.

There are whitespace errors that are not caught on compile time.  In the
code above, if you write

def fibo(n):
      curr = 1
      next = 1
      i = 0
      while i < n:
          curr, next = next, next+curr
      i = i + 1
      return curr

Python will happily run i = i+1 outside the while loop.  But then, that's
the natural thing to expect when any sane person read the code.

Regards,
Isaac.



Reply to: