Comments on "A Very Quick Comparison of Popular Languages for Teaching Computer Programming"
C++
On 25th Feb 2005, Terje Slettebo wrote:
You might also want to consider C++ as a language for teaching programming
(and I think it's a plausible alternative, enabling both high-level and
low-level programming). Here's the corresponding program in C++:
#include <iostream>
int main()
{
int a,b;
std::cin >> a >> b;
int c=a+b;
std::cout << c;
}
%> gcc add.cpp -lstdc++ -o add
%> ./add
It's rather interesting that Java - a language that purports to be _simpler_ than C++, actually makes it harder to write such a simple program as this (and other ones, as well). Just one nit from your Python list, though: "requires less lines of code for any given problem, and is more readable - thus greater productivity." For "any given problem"? And less than what? Surely, you can't mean that Python programs will always be shorter for any problem, than the corresponding program in any other languages, even DSLs?
|
It's a fair point about my overly broad statement though - perhaps I should have said "requires less lines of code (and is more readable) than any more popular general purpose language, for almost any problem."
Smalltalk
On 8th April, 2005, Doug Clapp wrote:|
Well, there's smalltalk, where you would have something like:
x := FillInTheBlank request: 'Enter a number for X'. y := FillInTheBlank request: 'Enter a number for Y'. Transcript show : x + y. |
Lisp
On 20th April 2005, Erling Ellison suggested the following Lisp:(print (+ (read) (read)))
Nevertheless, I can't help thinking, if Eric Raymond and Richard Stallman think Lisp is an important language to learn, that it possibly is...
Ruby
On 7th April 2005, Mark Hubbart wrote recommending Ruby, and shortly after David Morton wrote an almost identical email. Their arguments, jumbled together:
The first program looks like this:
a = gets.to_i b = gets.to_i c = a + b puts c
Concepts needed to learn:
pros and cons:
|
Perl
On 28th April 2005, Steven Cayford wrote:|
I liked your article and the comments. I thought I would throw perl in
as well. First concept, took about a minute mainly since I forgot the operator precedence between string concatenation "." and addition "+" while pushing them both into the print function.
#!/usr/bin/perl print "enter a: "; $a = <STDIN>; print "enter b: "; $b = <STDIN>; print $a + $b . "\n";
#!/usr/bin/perl print <STDIN> + <STDIN>;
Otherwise, probably similar pros and cons as python and ruby.
|
Shell
On 31st May 2005, Nathan Laredo wrote:|
I think it's also important to teach good shell programming -- your
python example opens the door to all these (examples assume they were
typed at a shell prompt): here's the whole thing for bash/sh/ksh/zsh:
read a; read b; echo $[a + b] here's the whole thing for awk:
awk 'BEGIN { getline a; getline b; print a + b; exit; }'
or alternatively:
awk '{ a = $0; getline b; print a + b; exit; }'
and here's the whole thing in perl (though I dislike perl more than C++):
perl -e 'print <> + <> . "\n"' Of course all of the above can be formatted as needed when in a script file rather than entered at the shell prompt. Some people write simple programs in languages like java and C++ when a trivial shell script would have gotten the job done in less time. The right tool for the job is an important lesson to learn, and competent shell scripting is a lost art. If you're wasting time at work coming up with java code to read and then add two numbers, your employer might not be so happy, but of course shell scripting is clearly the wrong way to do visualizations of satellite orbits. Then again, I may be the last person in the world who looks for excuses to use awk...
|
Serious working Unix programmers would probably be well served by really understanding shell and awk, but I think, although they solve the above problem easier than Java, they are generally so baroque as to be a very poor choice for beginners.
I agree though that it's very important to impress upon students the idea that "if all you have is a hammer, every problem looks like a nail" - and that they should aim to constantly broaden their repertoire of tools. I also think a class devoted to writing one-liners mightn't be a bad idea - it requires more mental discipline than simply churning out the first bloated solution that comes to your head. But again - these are not issues beginners should be grappling with.
Patrick Jordan - patrick@ariel.com.au - 2005-05-31
...original article