Re: Teaching Programming

Discussion in 'Python' started by Ed Keith, May 4, 2010.

  1. Ed Keith

    Ed Keith Guest

    --- On Tue, 5/4/10, Stefan Behnel <> wrote:

    > From: Stefan Behnel <>
    > Subject: Re: Teaching Programming
    > To:
    > 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


    Blog: edkeith.blogspot.com
     
    Ed Keith, May 4, 2010
    #1
    1. Advertising

  2. Ed Keith

    alex23 Guest

    Ed Keith <> 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?
     
    alex23, May 4, 2010
    #2
    1. Advertising

  3. Ed Keith

    James Mills Guest

    On Wed, May 5, 2010 at 12:21 AM, Ed Keith <> 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
     
    James Mills, May 4, 2010
    #3
  4. Ed Keith

    Andre Engels Guest

    On Tue, May 4, 2010 at 4:35 PM, James Mills
    <> wrote:
    > On Wed, May 5, 2010 at 12:21 AM, Ed Keith <> 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,
     
    Andre Engels, May 4, 2010
    #4
  5. Ed Keith

    Ethan Furman Guest

    Andre Engels wrote:
    > On Tue, May 4, 2010 at 4:35 PM, James Mills
    > <> wrote:
    >> On Wed, May 5, 2010 at 12:21 AM, Ed Keith <> 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~
     
    Ethan Furman, May 4, 2010
    #5
  6. On Wed, 5 May 2010 00:35:18 +1000
    James Mills <> 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 <> | 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.
     
    D'Arcy J.M. Cain, May 4, 2010
    #6
  7. On Tue, 4 May 2010 17:00:11 +0200
    Andre Engels <> 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 <> | 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.
     
    D'Arcy J.M. Cain, May 4, 2010
    #7
  8. Ed Keith

    Chris Rebert Guest

    On Tue, May 4, 2010 at 8:49 AM, D'Arcy J.M. Cain <> wrote:
    > On Wed, 5 May 2010 00:35:18 +1000
    > James Mills <> 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... :p

    > 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/of-braces-and-semicolons/
     
    Chris Rebert, May 4, 2010
    #8
  9. Ed Keith

    Dave Angel Guest

    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
    >> <> wrote:
    >>> On Wed, May 5, 2010 at 12:21 AM, Ed Keith <> 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
     
    Dave Angel, May 4, 2010
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    14
    Views:
    562
    Sean Ross
    Dec 18, 2003
  2. Wingware
    Replies:
    0
    Views:
    409
    Wingware
    Aug 3, 2007
  3. Samuel Williams

    Re: Teaching Programming

    Samuel Williams, May 3, 2010, in forum: Python
    Replies:
    22
    Views:
    624
    Martin P. Hellwig
    May 5, 2010
  4. Chris Rebert

    Re: Teaching Programming

    Chris Rebert, May 4, 2010, in forum: Python
    Replies:
    0
    Views:
    390
    Chris Rebert
    May 4, 2010
  5. Stefan Ram

    Teaching Java, teaching what?

    Stefan Ram, Dec 8, 2013, in forum: Java
    Replies:
    57
    Views:
    664
    Ali Sh
    Dec 18, 2013
Loading...

Share This Page