Lyndon,
I have been saving this recent article on
A Very Quick Comparison of Popular Langauges for
Teaching Computer Programming that you might find
interesting as compared to your posting;
Joe Cervenka
[EMAIL PROTECTED]
In the CS department where I currently teach I
recently got involved in a debate on which
programming language should be used to teach
beginners. Java and C are the most commonly used
languages in the department, and for many subjects
this is appropriate, but not (I believe) for absolute
beginners. I believe Python is a much better choice
for beginners, and to firm up my own position I
performed the very brief, very unscientific test
described below.
The Test
I wanted to look at what was involved in writing very
simple programs in a (small) variety of languages. The
languages I chose were BASIC, C, Java and Python. I
used C and Java because these are in common use in the
department (and in other teaching institutions. I ch-
ose Python because I love it, and think it an
excellent choice for teaching, and I chose BASIC
because, well, it was just too easy.....
"Hello World" seemed a bit too trivial, so I decided
on the relatively simple task of reading two numbers
from the user, adding them together and printing out
the result. My interest was
How long did it take to write and debug the code
How many things does a student need to understand in
order to write this code
The times given to write the code are obviously not
meant to be representative of the time required by a
student, but I believe that they give a roughly
accurate measure of comparison. I am reasonably
skilled (1-5 years professional experience) in each
language, so I don't think I was unreasonably biased.
BASIC
I learned to program, back in the late 70s, on a Level
I TRS-80, and on a time sharing system that my high
school had occasional access to. The program is
trivial in good 'ol BASIC:
10 INPUT A
20 INPUT B
30 C=A+B
40 PRINT C
RUN
Time to write:
15 seconds. I admit I don't have a BASIC interpreter
handy and did not test this, but I just know it works.
(OK, I fired up the TRS-80 emulator and actually ran
it - it works...)
Things to explain:
Line numbers
Variables
INPUT
PRINT
RUN
Pros and Cons
BASIC is very easy for beginners to get started with,
but it is an old, poorly designed language, lacking in
almost every modern feature. Visual BASIC adds a lot
to "good 'ol BASIC", but it is not appropriate (I
believe) to teach a single-platform proprietary
language. And it's still not really a good
language....
C
#include <stdio.h>
int main(int argc, char*argv[])
{
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
c = a+b;
printf("%d\n",c);
}
%> gcc -o add add.c
%> ./add
Time to write:
about three minutes, including debugging.
Things to explain:
#include, functions (main), return types, argc, argv
variables, types (int)
scanf (and pretty soon it's limitations and how to
work around them)
printf, format strings
pointers (already!!)
compiling, braces and semicolons
Pros and Cons
C was designed by top hackers for their own use. It
was designed for writing operating systems, compilers
and other system tools, and in this role it has become
almost totally dominant.
It can provide excellent performance (assuming good
choice of algorithm and good C skills) and allows low
level hardware access, but these are not normally
things required by the beginner. C's use of pointers
are a source of frustration and confusion for
beginners, but they are essential in even fairly
trivial programs (like the one above, albeit in a
trivial way).
Further, C's string handling is weak compared to many
other modern languages (the scanf function used above
is notoriously problematic).
C is a major and very important language, and all
programmers should have significant exposure to it.
It is however a terrible language to teach beginners.
There is too much C that has to be explained, leaving
less time for explaining programming.
Java
import java.io.*;
public class Addup
{
static public void main(String args[]) {
InputStreamReader stdin = new
InputStreamReader(System.in);
BufferedReader console = new
BufferedReader(stdin);
int i1 = 0,i2 = 0;
String s1,s2;
try {
s1 = console.readLine();
i1 = Integer.parseInt(s1);
s2 = console.readLine();
i2 = Integer.parseInt(s2);
}
catch(IOException ioex) {
System.out.println("Input error");
System.exit(1);
}
catch(NumberFormatException nfex) {
System.out.println("\"" +
nfex.getMessage() + "\" is not numeric");
System.exit(1);
}
System.out.println(i1 + " + " + i2 + " = "
+ (i1+i2));
System.exit(0);
}
}
%> javac Addup.java
%> java Addup
Time to write:
19 minutes! Actually, I spent about 15 minutes,
failed, then searched Google for an example. The code
above is copied from a web page, which, tellingly I
thought, starts with the words "It might be thought
that a programme that reads in two user entered
integers and prints out their sum would be a simple
piece of code".
Obviously, this code is not perfectly equivalent to
the other programs presented here since it does proper
error checking, however Java makes it difficult not to
do error checking. You must catch the exceptions, and
having caught them you might as well do something with
them.
I'm actually kind of embarassed I had so much trouble
with this - I've been working on a commercial Java
package for two years, but because it's GUI based I
rarely have to deal with reading from the console.
Real Java programmers will probably look down on me
with a mixture of pity and disgust. Such is life.
Things to explain
import, classes, semicolons braces
public, static, void, String, main args[]
InputStreamReader, BufferedReader, System.in
variables, types
try, catch, exceptions, readLine, parseInt
System.out.println, compiling, running
Pros and Cons
Java is a useful language for cross-platform GUI
development, is a robust platform for OO development,
and has an extensive and highly evolved set of class
libraries. Perhaps most importantly, it's the most
popular language around and there's lots of jobs for
Java programmers.
The extensive class library is however quite daunting.
It appears there's a class for almost everything, and
much of "programming in Java" seems to consist of
"searching for the right class". Even after two years
I find I cannot do much in Java without constant
reference to the documentation.
Java enforces Object Orientation, exception checking
and strict typing - these are all (arguably) good
things - they make it easier for a group of
programmers to robustly create large systems. But for
small problems (such as those faced in introductory
programming classes) these things become nothing more
than a complicated, time-sucking burden.
The employment reason alone is sufficient to make Java
a "must teach" lanaguage, but I believe we do our
students a disservice if this is the best language we
show them.
Python
import sys
a = sys.stdin.readline()
b = sys.stdin.readline()
c = int(a) + int(b)
print c
%> python add.py
Time to write:
about one minute, including testing and debugging.
Things to explain
import
variables
sys.stdin
readline (reads a string)
int (converts a string to an integer)
print
Pros and Cons
Python has an awful lot of good points:
enforces good programming style (indentation is
meaningful)
OO available but not enforced
Exceptions used but not enforced
is not a toy or academic language - much real world
work is done in Python
allows concentration on algorithms and problem, not on
langauge features and shortcoming.
is cross platform and has a powerful set of libraries
is safe - it has dynamic run time type checking and
bounds checking on arrays
has powerful built-in data types - dictionaries,
lists, sequences, functions, sets (in 2.4)
has powerful built-in control structures - simple
looping over sequences, map, generators, list
comprehensions, regular expressions...
requires less lines of code for any given problem, and
is more readable - thus greater productivity.
For teaching as a first language however it has some
specific advantages. As can be seen from the examples
above (ignoring BASIC), Python requires less time,
less lines of code, and less concepts to be taught to
reach a given goal. This allows more time to be spent
on the important things. Further, some common student
errors are completely byassed in Python:
end of line is end of line (no forgotten semicolons)
no type declarations
true block structure always obvious (no missing braces
error)
dynamic memory allocation and garbage collection
Finally programming in Python is fun! Fun and frequent
success breed confidence and interest in the student,
who is then better placed to continue learning to
program.
But Python is Just a Scripting Language
Python is often dismissed as "just a scripting
language" (Perl and Ruby also suffer from this silly
bigo-try). This is simply incorrect. It is not "just a
scripting language" - it is a full featured very high
level language that is ideal for many applications,
including simple scripting duties.
The fact that you can write "quick and dirty" scripts
in Python is an advantage, not a disadvantage, since
scripting is actually an essential part of
professional programming. If students don't know
Python (or Perl, or Ruby, or....), they will waste a
lot of time trying to solve script-like problems in
Java.
But Python is Slooooooow
Python is an interpreted language, and this does add
some overhead. Dynamic bounds checking, dynamic typing
and other clever Python things slow it down even
further. Python can be orders of magnitude slower
than equivalent C code. However
Many, many applications are not compute bound. To use
a high performance language for them exemplifies the
sin of early optimisation.
Python interfaces well to C - enormous gains can be
made by coding critical sections in C
Time saved coding in Python, and the much greater
simplicity of the code written, allows much more time
for experimentation in more efficient algorithms -
often much more fruitful than simply running a bad
algorithm very quickly.
Conclusion
C and Java are important languages - for the concepts
they embody, for the employment prospects, and for the
classes of problems they solve. Students must be given
a thorough grounding in these languages. They do not
however form a sufficient arsenal for the professional
programmer - a good "scripting language" is a must -
nor are they good languages to teach students new to
programming. They have a lot of overhead and other
impediments that take a lot of the pleasure out, and
make both the student's and the teacher's jobs more
difficult than they ought to be.
There are people who would argue that the impediments
are part of the discipline of programming - students
must learn to catch their exceptions, use pointers,
declare all their types and so forth. Maybe, maybe not
- but there's time for that later. Let's let st-udents
have the simple joy of small successes that we (well,
"I" anyway) had when we were starting.
--- lyndon hughey <[EMAIL PROTECTED]> wrote:
> I've done CF for about 5 years (1year of MX) and C#
> and
> Asp.net<http://Asp.net>for 2years. I've compiled a
> quick list of pros
> and cons for CF and .NET
>
> CF.
> -pluses
> ----------------
> Dev time (smaller projects)
> Ease of writing queries (form and capture
> applications were very quick to
> write)
> CFDUMP (saved my sanity. .NET does not natively have
> hierachial debugging
> without VS.net <http://VS.net>)
> Less platform dependent (eventhough I never deployed
> an app to a non windows
> system)
> Often times less expensive to hire CF developer
> (good for employer)
> Reporting and graphing (said in earlier post)
> Verity (one of my favorites)
> Flex (but it is expensive)
> Flash remoting (alternatives like OpenLaslo (free)
> are clumsy)
>
> -minuses
> Often times less expensive to hire CF developer (Bad
> for developer)
> CF's association with Dreamweaver gives the public
> perception that it is "a
> language for web designers, not programmers")
> .NET
> -pluses
> ---------------
> Dev sanity (larger projects)
> Most larger companies are either doing .NET or J2EE
> (CF is often not
> considered real J2EE by the Java community,
> eventhough it is)
> The code I write for web apps can often be taken out
> and put into a windows
> form
> Encourages you to learn windows development. THIS IS
> HUGE (the transition
> from Asp.net <http://Asp.net> to windows dev is very
> simple. I'm now able to
> develop many more solutions and consider myself as a
> Asp.net/Windows<http://Asp.net/Windows>developoer I
> could easily get a
> job doing
> asp.net <http://asp.net> or traditional windows dev)
> Power of ADO.net <http://ADO.net> (eventhough I
> don't interact with DB using
> LLBLGen (object persistance framework))
> Perception that it is more difficult (it is at
> first)
> Documentation (MSDN docs and the thousands of sites
> devoted to .net dev)
> Developer community
> Framework is "free" (if you buy windows) :)
> .NET v2.0 (is awesome!!!)
> 3rd party products (there are thousands)
> Large framework (over 35000 objects. Very robust.
> Gives you the ability to
> do awesome things)
> Tricky code like complex algorithms are easier to
> write
> -minuses
> price of VS.net <http://VS.net> if you don't have a
> MSDN
> Platform dependent (yeah, yeah MONO)
> I'm working with devil
> Lyndon
>
> On 6/9/05, Jacob Cameron
> <[EMAIL PROTECTED]> wrote:
> >
> > Have you priced RedHat Enterprise edition lately?
> Last time I compared
> > Microsoft, RedHat and Suse, they were all around
> the same price!!!
> > Jacob
> > ------------------------------
> > *From:* [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] *On
> > Behalf Of *Kent Irvin
> > *Sent:* Thursday, June 09, 2005 9:59 AM
> > *To:* [email protected]
> > *Subject:* Re: CF VS .Net?
> >
> > ASP is not free, in runs on a proprietary web
> server which requires
> > Windows Y2K or higher. That is not a free
> sceneario in my mind.
> >
> > Kent
> >
> > Knipp, Eric wrote:
> >
> > Tom,
> >
> > Did you go back to Thomson?
> >
> > Eric
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> <[EMAIL PROTECTED]>]
> > Sent: Thursday, June 09, 2005 9:33 AM
> > To: [email protected]
> > Subject: RE: CF VS .Net?
> >
> >
> > I've started doing some C# programming and agree
> that it's a waste of
> > time to do C# without visual studio. The good
> thing that I've seen
> > about C# and .net is that everything is an object.
> The intelli-sense in
> > Visual Studio is awesome. I would love to see
> Macromedia/Adobe add that
> > functionality to DreamWeaver. It would be cool as
> you code to know what
> > methods and properties are available from your
> CFC.
> >
> > ColdFusion is hands down easier to develop with
> IMO. But that could be
> > a factor of what you are used to. 8 or 9 years of
> CF development versus
> > 2 weeks of C#. Hmmmmm.
> >
> > The knock on CF is that it's not free like ASP or
> PHP. Not sure of what
> > VisualStudio costs, but that has to be included in
> the comparison.
> >
> > Tom
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> <[EMAIL PROTECTED]>] On
> > Behalf Of Matthew Woodward
> > Sent: Thursday, June 09, 2005 8:59 AM
> > To: [email protected]
> > Subject: Re: CF VS .Net?
> >
> > I've done two smallish projects in C#, and if you
> don't use Visual
> > Studio the amount of code you have to write is
> HEINOUS. If you plan
> > to do any amount of .NET development whatsoever,
> add Visual Studio
> > licenses to the total cost because writing all
> that code by hand is a
> > nightmare. To me that's not a strength of the
> Visual Studio tool,
> > it's a weakness of the language. ;-) I just don't
> understand why
> > everything other than CF (and some J2EE servers of
> course) doesn't
> > manage your datasources so you can have simple
> query statements like
> > we have in CF, and that's just one example. All
> that extra code adds
> > up quickly.
> >
> > Matt
> >
> > On Jun 9, 2005, at 8:49 AM, John Ivanoff wrote:
> >
> >
> >
> > A while back ben forta blogged on this "Defending
> ColdFusion
> > Against ASP.NET <http://asp.net/>*MailScanner has
> detected a possible fraud attempt from
> "www.forta.com" claiming to be* *MailScanner has
> detected a possible fraud attempt from
> "www.forta.com" claiming to be "
> >
>
http://www.forta.com/blog/index.cfm?mode=e&entry=1264
> >
> > he said it should be more J2EE vs .NET
> > "*
>
<http://www.forta.com/blog/index.cfm?mode=e&entry=1264hesaiditshouldbemoreJ2EEvs.NET>ASP.NET
> <http://asp.net/> apps take advantage of the .NET
> framework and infrastructure,
> > just like ColdFusion apps take advantage of J2EE"
> >
> > I've looked into .NET and to me it's like
> programming cobol. 30* lines
> > of code to do a "HELLO WORLD" But I'm sure you can
> do some really cool
> > stuff with it.
> >
> > * not really but sure seems like 30.
>
=== message truncated ===
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
----------------------------------------------------------
To post, send email to [email protected]
To unsubscribe:
http://www.dfwcfug.org/form_MemberUnsubscribe.cfm
To subscribe:
http://www.dfwcfug.org/form_MemberRegistration.cfm