Is anybody coming from Pascal?

Paul Sidorsky paulsid at home.com
Sat Jul 21 18:47:53 EDT 2001


Edmund Strangely wrote:

> I've been lurking here for a while while working my way through 'Learning
> Python'. So far only a few things have pissed me off with it. I was just
> wondering, is anybody else coming from Pascal? 

I'm not coming from Pascal but I'm quite familiar with it, so maybe I
can offer a different perspective.  (I used to be vehemently anti-Pascal
until I actually started to work with it; now I don't mind it so much.)

> and as I understand it
> Python is written in C which is why it shares some of the same
> conventions. 

I suspect the actual reason for this is that C (and C++) are just so
popular so language designers often borrow features from them.  

> Python is my first object orientated language. Pascal was my
> second programming language (after BASIC on a spectrum) and although I
> sort of learned C later, I still prefer Pascal. 

There are probably a bunch of people who would say that if you've only
programmed in BASIC and Pascal, you haven't programmed yet.  :-)  

> (And I like BASIC
> even better in this respect, in that integers and fp numbers are
> automatically converted, and strings will grow and shrink as required (as
> in Python seemingly)). 

Technically Python strings never change size, they get replaced with a
new object.  Try playing around with the built-in id() function to see
this.

> >>>a=5
> >>>b=2
> >>>#and then
> >>>c=a/b
> >>>#then
> >>>c
> 2
> 
> in Pascal if you *want* modulo arithmetic (which is not normally the case
> ) then you have DIV and MOD. 

There was a long discussion about this recently.  Search the archives
for more.  

(I like it the way it is.  I think keeping the integers closed under the
division operator when programming avoids many nasty surprises, even
though real-life integer division doesn't work this way.)

> I like having a distinction between functions
> and procedures, for purely aesthetic reasons (I think having loads of
> function names followed by () just looks ugly, procedures don't give
> return values). 

Personally I think () provides for more followable code, because it is a
distinctive tag to indicate the program will "branch" there. 
Admittedly, though, I never had a problem with the distinction in
Pascal, or even BASIC.  (I've been doing some VBScript lately and I
barely notice it.)

> But
> the one thing above all that I think Pascal has over C (and which Python
> shares) is that you can nest your procedures/functions! Most of my Pascal
> programs had a mere few lines in the 'main' body of the program and the
> rest would be large functions and procedures each with their own
> sub-procedures and sub-functions with their own sub-sub units etc.  When I
> first started on C I just couldn't *believe* that you couldn't nest
> functions, and just had to put them one after the other! You call that
> structured programming?

I've been doing C/C++ for 10 years and have never once needed to nest
functions.  In fact I never even heard of the concept until I met
Python.  I've used them in Python on occasion, but don't see them as
much more than a small time-saver.  

I'm not an expert in object-oriented design, but nested functions seem
kind of anti-OO too me.  Can behaviours (methods) really have their own
behaviours (nested functions), or does the behaviour (nested function)
actually belong to the object (class)?  And for non-OO use they seem
completely unnecessary to me.  About all they seem to do is keep the
global namespace a bit less polluted, but that's going to happen in
non-OO anyhow.  But maybe I'm missing something...

> I conclusion, and in reviewing this post, I seem to have been rambling a
> bit (it's a bit late/early in the day) but I'd be interested to get a
> response from anybody else who rates Mr Wirth, and in how any such people
> finding the transition. I'd also be curious to hear from anybody who has
> tried object Pascal.

Object Pascal is okay.  I don't have much experience with it, but
personally I'd hate to have to learn object-oriented concepts on it.  It
shares the same problem with C++ as being an extension to an existing
language, so the implementation of OO features is kind of glued on.  I
think it's better to pick up OO concepts on Python (or even Java) before
trying Object Pascal.

Anyhow, I hope you stick with Python.  You'll get a lot of the
convenience of Pascal merged with a cleaner and much more well-designed
language!

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid at home.com                      http://members.home.net/paulsid/




More information about the Python-list mailing list