Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Teaching Programming

Reply
Thread Tools

Re: Teaching Programming

 
 
Ed Keith
Guest
Posts: n/a
 
      05-04-2010
--- On Tue, 5/4/10, Stefan Behnel <(E-Mail Removed)> wrote:

> From: Stefan Behnel <(E-Mail Removed)>
> Subject: Re: Teaching Programming
> To: http://www.velocityreviews.com/forums/(E-Mail Removed)
> Date: Tuesday, May 4, 2010, 8:40 AM
> Ed Keith, 04.05.2010 14:15:
> > I wrote AsciiLitProg (http://asciilitprog.berlios.de/) in Python. It is
> > a literate programming tool. It generates code from a

> document. It can
> > generate code in any language the author wants. It

> would have been a LOT
> > easier to write if it did not generate Python code.
> >
> > 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?
>
> Stefan
>
> -- http://mail.python.org/mailman/listinfo/python-list
>


The program is written using itself. If you click on the link above you will see an HTML file that fully describes the program. That HTML is generated from an AcsiiDoc (http://www.methods.co.nz/asciidoc/) document. The same document is used to generate the python code that it describes.
The source document, and the generated HTML and Python code are all avalable at BerliOS (http://developer.berlios.de/projects/asciilitprog/).

For more information on Literate Programming in general see the following links.

http://www.literateprogramming.com/
http://en.wikipedia.org/wiki/Literate_programming
http://en.literateprograms.org/LiteratePrograms:Welcome


-EdK

Ed Keith
(E-Mail Removed)

Blog: edkeith.blogspot.com





 
Reply With Quote
 
 
 
 
alex23
Guest
Posts: n/a
 
      05-04-2010
Ed Keith <(E-Mail Removed)> wrote:
> For more information on Literate Programming in general see the following links.


None of which address the question of what you found problematic about
generating Python code. Was it issues with indentation?


 
Reply With Quote
 
 
 
 
James Mills
Guest
Posts: n/a
 
      05-04-2010
On Wed, May 5, 2010 at 12:21 AM, Ed Keith <(E-Mail Removed)> 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.

--James
 
Reply With Quote
 
Andre Engels
Guest
Posts: n/a
 
      05-04-2010
On Tue, May 4, 2010 at 4:35 PM, James Mills
<(E-Mail Removed)> wrote:
> On Wed, May 5, 2010 at 12:21 AM, Ed Keith <(E-Mail Removed)> 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, (E-Mail Removed)
 
Reply With Quote
 
Ethan Furman
Guest
Posts: n/a
 
      05-04-2010
Andre Engels wrote:
> On Tue, May 4, 2010 at 4:35 PM, James Mills
> <(E-Mail Removed)> wrote:
>> On Wed, May 5, 2010 at 12:21 AM, Ed Keith <(E-Mail Removed)> 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~
 
Reply With Quote
 
D'Arcy J.M. Cain
Guest
Posts: n/a
 
      05-04-2010
On Wed, 5 May 2010 00:35:18 +1000
James Mills <(E-Mail Removed)> 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 <(E-Mail Removed)> | 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.
 
Reply With Quote
 
D'Arcy J.M. Cain
Guest
Posts: n/a
 
      05-04-2010
On Tue, 4 May 2010 17:00:11 +0200
Andre Engels <(E-Mail Removed)> wrote:
> 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.


Well, I'm afraid your lack of experience shows. Experienced C coders
will tell you that one of the most annoying things is counting braces
to make sure that you have the right number in the right places. In
fact, they add indentation so that they can use the visual layout to
check the brace layout. Braces are the added step.

--
D'Arcy J.M. Cain <(E-Mail Removed)> | 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.
 
Reply With Quote
 
Chris Rebert
Guest
Posts: n/a
 
      05-04-2010
On Tue, May 4, 2010 at 8:49 AM, D'Arcy J.M. Cain <(E-Mail Removed)> wrote:
> On Wed, 5 May 2010 00:35:18 +1000
> James Mills <(E-Mail Removed)> 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.


The amount of mental scaring that Fortran has caused regarding
indentation is astounding.
Maybe the PSF should run re-education camps for Fortran programmers...

> 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.


Technically, that pitfall /could/ be eliminated if curly-braces
languages simply always required the curly-braces for bodies and
stopped special-casing the null body case, in which case both your
examples would be syntax errors. Removing the special-casing of
single-line bodies too would remove a further class of errors.
However, I've yet to encounter a language that takes such an approach.
Quite a pity.

Cheers,
Chris
--
I've thought a lot about this.
http://blog.rebertia.com/2010/01/24/...nd-semicolons/
 
Reply With Quote
 
Dave Angel
Guest
Posts: n/a
 
      05-04-2010
Ethan Furman wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">Andre
> Engels wrote:
>> On Tue, May 4, 2010 at 4:35 PM, James Mills
>> <(E-Mail Removed)> wrote:
>>> On Wed, May 5, 2010 at 12:21 AM, Ed Keith <(E-Mail Removed)> 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~
>
>

Much more important to be able to read code reliably than write it quickly.

When I was heavily doing C++ I found myself wishing that incorrect
indentation would be an error or at least a warning. And I hadn't ever
heard of Python. When I did, I said "About time!"

Of course, I was surrounded by many programmers who ignored any warning
that the compiler produced, while I cranked up warnings to max, with
pedantic.

On one project I generated C++ code, about 20k lines. And it was all
indented and commented. Most of that code went through the code
generator twice. The "source" was a header file from outside my
organization. The generator used that to create a new header, more
detailed. Then the generator used that to create source & headers that
were actually used by the project.

DaveA
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Teaching Programming Ed Keith Python 4 05-08-2010 04:21 AM
Re: Teaching Programming Samuel Williams Python 22 05-05-2010 10:01 PM
Re: Teaching Programming Chris Rebert Python 0 05-04-2010 04:13 PM
Announcing Wing IDE 101 for teaching intro programming courses Wingware Python 0 08-03-2007 07:28 PM
teaching programming to children andy@post.tau.ac.il Python 14 12-18-2003 01:13 AM



Advertisments