[Edu-sig] Python as a first language for computer sciencist

Radenski, Atanas radenski at chapman.edu
Wed Oct 19 23:11:27 CEST 2005


> -----Original Message-----
> From: edu-sig-bounces at python.org [mailto:edu-sig-bounces at python.org]
On
> Behalf Of Mark Engelberg
> Subject: Re: [Edu-sig] Python as a first language for computer
sciencist
 
> In my mind, one important feature of a first programming language is
> that it must provide meaningful error messages for every common error
> a student might make.

Unfortunately, there is no language that can provide meaningful error
messages for every common error a student might make, except in one's
dreams. 

Consider this program that is intended to calculate the area of a
triangle, given its sides, s1, s2, s3. It is written in a statically
typed language. It gives you a good headache with a simple typo (s2
accidentally typed instead of s3).

float triangleArea(float s1, float s2, float s3) {
  float p = (s1 + s2 + s3) / 2; // triangle perimeter
  return Math.sqrt (p*(p-s1)*(p-s2)*(p-s2)); // s2 typed instead of s3
}

Or consider this (3.1514 typed instead of 3.1415): 

float circleArea(float r) {
  float pi = 3.1514; // pi value mistyped
  return pi*r*r;
}

> It is very bad that a minor typo can really mess with the semantics of
your code.  

Certainly, I agree. But this cannot be avoided.

> Typed languages, of course, don't have this problem, because you have
> to declare the types of everything you use, before you use them.

Python is a typed language, too. Do you mean 'statically typed
languages'? 

Atanas

Atanas Radenski      
mailto:radenski at chapman.edu      http://www.chapman.edu/~radenski/
 



More information about the Edu-sig mailing list