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

Re: OT - trivial programming language

On Sat, 29 May 2004 15:54:48 +0200, Kai Grossjohann <kai@emptydomain.de> wrote:
> Steve Lamb <grey@dmiyu.org> writes:
>> Faheem Mitha wrote:
>>> Bob Proulx makes good points elsewhere in this thread. Whether you
>>> like the indentation as syntax feature is really a matter of
>>> taste. Personally, I am ambivalent about it. On the one hand it makes
>>> code more compact. On the other hand, indentation is easily lost
>>> information, for example when cutting and pasting. Also, I have the
>>> habit in emacs of hitting tab to get code to line up. I've done this
>>> for years, and it is a hard habit to break. Unfortunately it has
>>> disastrous consequences in python code.
>>     So have EMACS treat the tab key as the equivolent number of spaces and
>> write the file out using spaces instead of tabs.
> This won't help: in Emacs, TAB computes the right indentation from
> the buffer contents.  In C-like languages, this is fairly easy: after
> a "{", indent more, after a "}", indent less.  There are a lot of
> other rules, but that's the basic.
> But in Python, it is not possible to compute the indentation from the
> buffer contents.  This means that just hitting TAB on each line is
> either a no-op (then why are we doing this), or it would get the end
> of a loop wrong and suchlike.
Yes. There have been a lot of people in this thread you have
misunderstood what I was saying. I think Kai summarised it pretty
well. The bottom line is that in Python whitespace is syntatically
meaningful, in C etc. it is not.

This has the consequence that in C, emacs is able to correctly indent
the code, using the built-in syntax rules it knows about. This is very
useful since it shows up trivial syntax bugs right away.

On the other hand, much of the time emacs does not know what to do
with Python code (when in python mode, that is), since part of the
synax info is encoded in the whitespace. Blindly hitting tab, which
works fine with C/C++ and probably most of the other languages out
there, can really mess up Python code. It does know enough to avoid
indenting if you forget the colon at the end of if statement, for
example, so it *is* of some use.

Hope this clarifies things.

Reply to: