Newbie : checking semantics

A

Andrew Dalke

Stefan said:
From time to time I teach some programming (in an institution
called "Volkshochschule" here in Germany -- inexpensive courses
for adults). My Python course is for absolute beginners with no
previous programming experience of any kind.

I also taught a beginning programming course. I found that
the hard thing was learning the concept of an algorithm. I
don't recall people getting confused over the indentation part
that much.

Python's block indentation is derived from ABC. ABC did various
human factors studies to test how to make a language easier to
use by beginning programmers. Combining that with my own experience
both using and teaching the language make me distrustful of anyone
else's evidence based only on anecdotal accounts.

Leaving out the easy of learning aspect, there are two other
reasons for the indentation:
http://python.fyxm.net/doc/essays/foreword.html

] Perhaps Python's most controversial feature is its use of indentation
] for statement grouping, which derives directly from ABC. It is one of
] the language's features that is dearest to my heart. It makes Python
] code more readable in two ways. First, the use of indentation reduces
] visual clutter and makes programs shorter, thus reducing the attention
] span needed to take in a basic unit of code. Second, it allows the
] programmer less freedom in formatting, thereby enabling a more uniform
] style, which makes it easier to read someone else's code.

So I would appreciate optional statements to end a block
(indentation rules may be mandatory). This comes also very handy
in something like Python Server Pages of mod_python (where a
comment line to explicitly end a block is sometimes needed).

See the program "pindent.py" in the Python distribution under
Tools/scripts

# This file contains a class and a main program that perform three
# related (though complimentary) formatting operations on Python
# programs. When called as "pindent -c", it takes a valid Python
# program as input and outputs a version augmented with block-closing
# comments. When called as "pindent -d", it assumes its input is a
# Python program with block-closing comments and outputs a commentless
# version. When called as "pindent -r" it assumes its input is a
# Python program with block-closing comments but with its indentation
# messed up, and outputs a properly indented version.

# A "block-closing comment" is a comment of the form '# end <keyword>'
# where <keyword> is the keyword that opened the block. If the
# opening keyword is 'def' or 'class', the function or class name may
# be repeated in the block-closing comment as well. Here is an
# example of a program fully augmented with block-closing comments:

# def foobar(a, b):
# if a == b:
# a = a+1
# elif a < b:
# b = b-1
# if b > a: a = a-1
# # end if
# else:
# print 'oops!'
# # end if
# # end def foobar

Andrew
(e-mail address removed)
 
B

Bengt Richter

That's true. But they also not very used to give nothing (->
whitespace) a meaning. I teached quite some beginners and most of
them had problems to get the indentation right.

At least in the very beginning IMHO it would be useful to
explicitly end a block with some kind of an end statement.

Meaningful whitespache is not a big problem (as many people seems
to think) but it's also not very obvious and sometimes it causes
at least a little bit trouble.
Training wheels do no belong as a permanent part of a bicycle, IMO.

If you want to show newbies Python code with block bracketing, please
program up a suitable code viewer for them ;-)

Regards,
Bengt Richter
 
S

Stefan Nobis

(e-mail address removed) (Bengt Richter) writes:

[block end statements]
Training wheels do no belong as a permanent part of a bicycle,

Yes, but they would be useful for example in web programming
(embedding Python into HTML), too. So they are not only training
wheels.
 
S

Stefan Nobis

(e-mail address removed) (Bengt Richter) writes:

[block end statements]
Training wheels do no belong as a permanent part of a bicycle,

Yes, but they would be useful for example in web programming
(embedding Python into HTML), too. So they are not only training
wheels.

But that's not so important. What Python got really wrong is
mixing binding and assignment (because this way you have little
chance to catch typos in identifiers).
 
A

Antoon Pardon

Op 2005-05-16 said:
Training wheels do no belong as a permanent part of a bicycle, IMO.

But what is a training wheel depends on your point of view.

IMO the required indentation is more like permanent training wheels
than end block-markers would be. A structure in general has a begin
marker and an end marker. Even python has them in some cases like
lists and tuples.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,239
Messages
2,571,200
Members
47,838
Latest member
elibuskamoSeAve

Latest Threads

Top