From: Andre Engels on
On Tue, May 4, 2010 at 4:35 PM, James Mills
<prologic(a)shortcircuit.net.au> wrote:
> On Wed, May 5, 2010 at 12:21 AM, Ed Keith <e_d_k(a)yahoo.com> wrote:
>> To deal with indentation I had to
>>
>>   1) keep track of indentation of all chunks of code embedded in the
>>      document and indent inserted chunks to the sum of all the
>>      indentation of the enclosing chunks.
>
> In my experience of non-indentation sensitive languages
> such as C-class (curly braces) it's just as hard to keep track
> of opening and closing braces.

Although I have little or no experience with this, I still dare to say
that I don't agree. The difference is that in C you do not _need_ to
know where in the braces-defined hierarchy you are. You just embed or
change a piece of code at the right location. In Python however you
_do_ need to know how far your code is to be indented.


--
André Engels, andreengels(a)gmail.com
From: Ethan Furman on
Andre Engels wrote:
> On Tue, May 4, 2010 at 4:35 PM, James Mills
> <prologic(a)shortcircuit.net.au> wrote:
>> On Wed, May 5, 2010 at 12:21 AM, Ed Keith <e_d_k(a)yahoo.com> wrote:
>>> To deal with indentation I had to
>>>
>>> 1) keep track of indentation of all chunks of code embedded in the
>>> document and indent inserted chunks to the sum of all the
>>> indentation of the enclosing chunks.
>> In my experience of non-indentation sensitive languages
>> such as C-class (curly braces) it's just as hard to keep track
>> of opening and closing braces.
>
> Although I have little or no experience with this, I still dare to say
> that I don't agree. The difference is that in C you do not _need_ to
> know where in the braces-defined hierarchy you are. You just embed or
> change a piece of code at the right location. In Python however you
> _do_ need to know how far your code is to be indented.

And how do you know where the right location is? You have to figure it
out from the different (nested) braces at the 'right' location. For me,
at least, it's much easier to get that information from the already
indented Python code, as opposed to indenting (and double-checking the
indents) on the braces language.

~Ethan~
From: Stefan Behnel on
Ed Keith, 04.05.2010 15:19:
> --- On Tue, 5/4/10, Stefan Behnel wrote:
>> Ed Keith, 04.05.2010 14:15:
>>> Python is a great language to write in (although I do
>>> wish it did a better job with closures). But it is a PITA to
>>> generate code for!
>>
>> Interesting. Could you elaborate a bit? Could you give a
>> short example of what kind of document text you translate
>> into what kind of Python code, and what the problems were
>> that you faced in doing so?
>
> The program is written using itself. If you click on the link above you
> will see an HTML file that fully describes the program.

I did. I find it a bit hard to read due to the block splitting (basically
like 'include' based spaghetti programming), but so far, the actual code
that does the code merging looks pretty simple and I can't figure out where
the "PITA" bit is on that page. That's why I asked.

Stefan

From: alex23 on
Ed Keith <e_...(a)yahoo.com> wrote:
> Tabs are always a problem when writing Python. I get
> around this problem by setting my text editor to expand
> all tabs with spaces when editing Python, but I have had
> problems when coworkers have not done this.

It's best not to trust others to do the right thing. I do trust Tools/
scripts/reindent.py more though :)

> Don't get me wrong, I love working in Python. It is one
> of my favorite languages, but it, like all other languages,
> is not perfect.

I was genuinely interested in the problems you hit as I have some hazy
projects in mind that I was planning on trying to handle via code
generation. Context managers seem the best place to first try dealing
with it. If you're interested I can keep you posted when I finally
have some working code.

Cheers for the clarification.
From: D'Arcy J.M. Cain on
On Wed, 5 May 2010 00:35:18 +1000
James Mills <prologic(a)shortcircuit.net.au> wrote:
> In my experience of non-indentation sensitive languages
> such as C-class (curly braces) it's just as hard to keep track
> of opening and closing braces.

Harder. That was the big "Aha!" for me with Python. My first
programming language was Fortran in 1969 so when I saw indentation as
syntax I also recoiled in horror for about 0.5 seconds. However, I
immediately realized that from now on I could be sure that if it looked
right then it was right.

for (x = 0; x++; x < 10);
printf("Current number is %d\n", x);

Or...

for (x = 0; x++; x < 10);
{
printf("Current number is %d\n", x);
}

Oops. Looks right but isn't. Try to make that mistake in Python.

Note untested - I wasn't about to fire up an editor, create a C
program, add the includes, compile and run the a.out just to test
this. Another way that Python excels. However, I am pretty sure that
the above would compile.

--
D'Arcy J.M. Cain <darcy(a)druid.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.