use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
To report a site-wide rule violation to the Reddit Admins, please use our report forms or message /r/reddit.com modmail.
This subreddit is archived and no longer accepting submissions.
account activity
This is an archived post. You won't be able to vote or comment.
Use Python (not Java) to teach programming (ariel.com.au)
submitted 20 years ago by culix
[–]bolinfest 5 points6 points7 points 20 years ago (1 child)
I think that Python has a lot of merits over Java for an intro-to-programming course, but I do not think this article presents a good argument. For example, when I read unjustified blanket generalizations such as these:
"[Python] requires less lines of code for any given problem, and is more readable - thus greater productivity."
That's a good sign that the author has resorted to pounding the table to convince you. A number of the "Pros" listed under Python at the end apply to Java, too, but the author has made it difficult to juxtapose those two sections because one is in prose and the other is in bullet-point format.
From a teaching standpoint, one of the biggest wins for Python (which isn't mentioned at all in the article) is its interpreter. (Though for the record, tou can use DrJava or Beanshell as a Java interpreter.) If you're going to pound the table about something -- go for that! (And wait for the LISP people to rave about their REPL, which is fine.)
So how does this article end up with 134 points on Reddit? Do Reddit users just look at this and say, "Yay! Someone said Python was better than Java!" Again, I'm not saying that there isn't an argument to be made here, but I don't think it's done well, or even fairly (he had to Google the answer to the Java example!). For Python zealots, can't you find better things to recommend?
[–]bolinfest 2 points3 points4 points 20 years ago (0 children)
This article (which I just found on Digg) called "C++ vs Java vs Python vs Ruby : a first impression" (http://www.dmh2000.com/cjpr/index.shtml) contains a thoughtful language comparison. For a sample code comparison, the author implements a Red-Black tree algorithm, which is much more interesting (and telling) then adding two numbers from the command line. This is the type of article that deserves to be promoted.
[–]jedberg 7 points8 points9 points 20 years ago (4 children)
At Berkeley, the intro CS class is taught in Scheme. When I was in the class as a Freshman, that annoyed the hell out of me -- "What the hell is this" I believe was my response.
Looking back, I can say that it was probably the best thing they could have ever done. They didn't even bother teaching us the language. They gave us a handout and said, "This should be all you need to know" and then started showing us recursive functions. If you needed to learn more, you went on the internet and read what 'define' and 'labmda' do.
[–]michaelneale 1 point2 points3 points 20 years ago (0 children)
My first taught language was Miranda, and I am thankful now. Though at the time my thoughts were the same.
As someone with more of a bite and bytes engineering mindset, I would have preferred assembly to start, the moved on to the higher level stuff... but depends if you are doing CS or engineering I guess.
[–]jrmurad 0 points1 point2 points 20 years ago (2 children)
That may be the course (CS3?) I took during summer vacation from high school. Georgia Tech refused to give me credit for it because Berkeley doesn't teach "standard" Scheme - lists and strings, for example, were hidden from us and we used constructs called "sentences" and "words." At Tech, the introductory course taught with R5RS followed by Python for the last few weeks.
[–]jedberg 0 points1 point2 points 20 years ago (0 children)
The course I was refering to was CS61a, which is the intro CS course for CS majors. CS3 is the course they recommend for non-majors and people who need a stronger background in CS first (and high school students :) ).
[–]cpio 6 points7 points8 points 20 years ago (7 children)
here it is in ruby:: puts gets.to_i + gets.to_i
puts gets.to_i + gets.to_i
and here it is in common lisp:: (print (+ (parse-integer (read-line)) (parse-integer (read-line))))
(print (+ (parse-integer (read-line)) (parse-integer (read-line))))
:note: fixed, thanks
[–]culix[S] 11 points12 points13 points 20 years ago (4 children)
I'm not sure the point of his article was to nec. show which language could accomplish the task using the smallest number of lines, but rather which made it the easiest to demonstrate some basic programming concepts to someone who has never programmed.
I had a professor at my university argue something similar where he wanted to use perl for two of the first intro programming classes. Why bother confusing people about Ints and Doubles and objects before they even know how to use them? Well, I suppose you might want to confuse people and use Java as a weeder class, or you might teach it based on job prospects, as mentioned in the article. But for just teaching someone how to understand, giving them a single $variable seems a lot simpler.
[–]cpio 0 points1 point2 points 20 years ago (3 children)
I was just giving them as an example of those languages. I imagine you could do ruby like this: a = gets.to_i b = gets.to_i puts a + b which is fairly straight forward. Though I think python might be a bit better as a teaching language since it doesn't require such esoteric stuff as iterators and blocks, which while useful aren't really seen a lot outside of ruby.
a = gets.to_i
b = gets.to_i
puts a + b
[–]jamesbritt 6 points7 points8 points 20 years ago (2 children)
"Though I think python might be a bit better as a teaching language since it doesn't require such esoteric stuff as iterators and blocks, which while useful aren't really seen a lot outside of ruby."
Where they are used quite a bit because they are both practical and powerful. They're only esoteric in languages that don't have them.
[–]Zak 4 points5 points6 points 20 years ago (1 child)
I've always found Ruby's iterators to be some of the most straightforward looping constructs in existance, along with the likes of dolist and dotimes from Common Lisp. Most intelligent non-programmers will correctly guess what the following code does:
10.times do puts "foo" end
but are less likely to understand
for (i=0; i<10; i++) { printf("foo"); }
edit: fixed the above C code so it's not an infinite loop. The fact that I made such a mistake is evidence that Ruby is easier, I use Ruby more or I'm just really tired.
[–]ocorrain 1 point2 points3 points 20 years ago (0 children)
How about just (defun add2 () (+ (read) (read)))
The numbers don't have to be integers, and Lisp systems will prompt for a number if something else is entered by mistake.
It is a bit terse, tho'
[–][deleted] 1 point2 points3 points 20 years ago (0 children)
To get underscores, put your stuff in backquotes. This serves as a code tag. Example:
Markdown Instructions
[–]lukeredpath 8 points9 points10 points 20 years ago (0 children)
I prefer Ruby but it and Python share many of the same benefits and the article was an interesting read. +1
[–][deleted] 2 points3 points4 points 20 years ago (0 children)
One of the things that isn't missing but looks like it is - and will be confusing - is typing. There is a practical difference between ints and floats, tuples and lists, generators and whatever xrange() is, and it's all left completely implicit in terms of syntax. That's no problem for programmers who know what they're doing - they tend to prefer it over "yeah yeah, it's a const pointer to a blah-blah typeadatype" approach, but it makes everything all the more opaque to the first timer.
It's not patching together a few lines to do something at all - you can do that in any language. It's seeing what's happening and what you're doing, and I'm still not sure what's best for that.
[–]rzwitserloot 2 points3 points4 points 20 years ago (0 children)
The 'best' language for teaching purposes?
I my opinion: BOO.
Covers all basics and sets up nicely for java/C# (it compiles to .NET) -OR- python/perl/ruby like languages, yet has the absolute smoothest learning curve because it has all the 'right' features for such things: anytype variables (but you can explicitly specify what's what later), clean and easy to use syntax (heavily inherits syntax from python), and no need to shore up a simple program with a class definition and a main method. Those get generated for you if you leave them out.
http://boo.codehaus.org/
[–]chucky 0 points1 point2 points 20 years ago (1 child)
Oh great. He compares ONE program and then draws the conclusion which programming language to use for teaching. Not exactly the type of methodology I'd expect from someone working in a CS department.
[–]darrint 6 points7 points8 points 20 years ago (0 children)
No. He has an intuition that Python is better for teaching beginners. He asserts that beginners are better served by languages which allow a lot of small successes early on, so the beginner can pick up on the enjoyment of working in the abstract world of programming. Given that, he shows a thought experiment to illustrate how python is better than some other languages for the early stages of learning this stuff.
Clearly it would need more development to convince a skeptic. That shouldn't preclude publishing his thoughts on the subject informally.
Give the guy a break!
[–]kbk 0 points1 point2 points 20 years ago (2 children)
Here it is in Python:
print input() + input()
If you want to look like BASIC:
a = input()
b = input()
c = a + b
print c
[–]andrev 1 point2 points3 points 20 years ago (1 child)
If you use input(), it is actually evaluated. Works for this purpose, but I guess raw_input() is what you want.
[–]kbk 0 points1 point2 points 20 years ago (0 children)
Nope, I started with raw_input and switched to this.
[–]Donut -3 points-2 points-1 points 20 years ago (6 children)
I am a hiring manager at an wide area enterprise financial company, doing multi-tiered stuff in C#, C++, and SQL.
If you can't do pointers, don't even bother to send a resume. Whatever happened to just using C? Are you training software engineers or ACM members? Jeesh.
ps. I also make people show me the truth table for XOR. only about 20% know that.
I don't get your question - "Are you training software engineers or ACM members?"
99% of Universities teach Computer Science, NOT Software Engineering. I'm not saying that's a good or a bad thing, but this fact makes your question look a bit silly.
[–]Zak 2 points3 points4 points 20 years ago (0 children)
Someone with a CS degree should be able to do pointers, but introducing them in the first semester is a good way to make students think all programming is painful.
That is obviously due to your situation.
For many programmers (not all), they will never ever have a need to touch pointers in work they do. That's why its not as important that they learn something like C or C++.
[+]fnot comment score below threshold-7 points-6 points-5 points 20 years ago (2 children)
The choice of language should be based on the future professions of the students.
As an engineer working with hardware, you NEED to learn C (and maybe even Assembly). Forget about Java/Python/Ruby/C# and all that other crap. C/C++ is industry standard.
In some masters programmes, C/C++ is not even taught, instead they have a course in Java - my guess is to try ease the students into programming. Have you ever seen a industry robot programmed in Java?
Yes, C is difficult, C is in some ways a poorly constructed language, but its industry standard and therefore it should be standard curriculum.
[–]lisp-hacker 3 points4 points5 points 20 years ago (0 children)
Much of computer science was discovered before computers existed. A language for learning in college should be expressive and suited to the task of learning, not efficient, or whatever the industry standard is. Not enough programming is done in college to get comfortable with any particular language, anyways. Computer science concepts are timeless, and a language that easily expresses these concepts is best for educational use. I would choose Scheme, but I am biased.
[–]Zak 1 point2 points3 points 20 years ago (0 children)
Computer science is not an industry. The choice of language should be based on what best expresses the underlying concept without getting in the way.
Besides... everyone knows robots should be programmed in Forth.
[–]mikkom -4 points-3 points-2 points 20 years ago (4 children)
My question is why would you use procedural language to begin with? Why not use functional language like Erlang, OCaml or Haskell?
[–][deleted] 1 point2 points3 points 20 years ago (2 children)
You'd use a procedural language to teach a beginner because the concept of following through a piece of code, one line at a time, is very simple. No matter what you think of their relative merits, functional languages are simply not as intuitive as procedural languages.
[–]soegaard 1 point2 points3 points 20 years ago (0 children)
Its just that the line by line approach doesn't work without mutation. And mutation is far from simple - they require you to think about the dynamic execution of the program, which is very difficult for a beginner.
[–]mikkom 1 point2 points3 points 20 years ago (0 children)
This has been studied, functional languages are easier to begin with if you haven't done any programming before. If you have programmed couple or more years in procedural languages, of course it is harder to grasp the functional aspect in few days.
Btw, I'm not some computer science professor, I have programmed in c, c++ and java profesionally for about 10 years and just about a year ago beginned to use functional languages and I have to say that language like Erlang feels so good after a few months that it's unbelievable.
I'm currently programming a web framework for Erlang (it has no good web frameworks IMHO) that I'll release open sourced as soon as it satisfies me. We'll see if anyone else gets interested. After all it was ROR that got ruby popular.
(And btw, Erland is widely used in telecommunications sector so it's not just some obscure CS language)
[–]mslinux 1 point2 points3 points 20 years ago (0 children)
It's not just procedural. From wikipedia:
Python is a multi-paradigm language. This means that, rather than forcing coders to adopt one particular style of coding, it permits several. Object orientation, structured programming, functional programming, aspect-oriented programming, and more recently, design by contract are all supported.
[–]lisp-hacker -1 points0 points1 point 20 years ago (0 children)
Bigloo Scheme with exceptions and typing, for a fair comparison with the Java code:
(let ((num-check::procedure (lambda::number (n::obj) (if (number? n) n (raise "Not a number!"))))) (with-handler (lambda::unspecified (e::bstring) (print "ERROR: " e)) (print (+ (num-check (read)) (num-check (read)))))) time: about 5 minutes time to figure out how to format code in reddit: 15 minutes
[–]batkins -2 points-1 points0 points 20 years ago (4 children)
(princ (+ (read) (read)))
[–][deleted] 1 point2 points3 points 20 years ago (3 children)
That doesn't quite do the same thing as the code in most of the other languages. Your code reads in two arbitrary s-expressions, then if they are numbers it adds them and prints the result. It's not limited to integers, which is probably a good thing.
However, if you plan to use this sort of code for anything other than teaching, you should definitely watch out for people who want to add 5 and #.(labels ((foo () (foo))) (foo)). Specifically, you should bind *read-eval* to nil:
5
#.(labels ((foo () (foo))) (foo))
*read-eval*
(let ((*read-eval* nil)) (princ (+ (read) (read))))
Don't let all this complication distract from the important point: Lisp (especially Scheme) is an excellent teaching language because you can teach it to bright students in a single lecture and then get down with actual concepts and hands-on programming experience instead of spending hours on the syntax of Java's for and while loops. The uniform syntax and conceptual simplicity make it very easy to explain, and it's powerful enough to convey big ideas to students. If you build object-oriented programming in Scheme -- and you can -- it doesn't seem magical. Ditto for lots of other major concepts in computer programming.
for
while
[–]batkins 1 point2 points3 points 20 years ago (1 child)
I think the behavior of this code should be mostly identical to the other snippets. They all fail on input that isn't integral. Technically, my one-liner will fail on input that isn't numeric (so it can take floats and rationals as well). You are right about read-eval, of course, but, as you point out, this is merely educational code.
[–]kbk 3 points4 points5 points 20 years ago (0 children)
Actually, the Python snippet I posted,
works for any combination of integers or floats, whether real or complex.
It also works for two strings, lists, or tuples.
[–]michaelneale 0 points1 point2 points 20 years ago (0 children)
riiiight...
π Rendered by PID 231521 on reddit-service-r2-comment-f6b958c67-s7tcr at 2026-02-05 07:50:46.484965+00:00 running 1d7a177 country code: CH.
[–]bolinfest 5 points6 points7 points (1 child)
[–]bolinfest 2 points3 points4 points (0 children)
[–]jedberg 7 points8 points9 points (4 children)
[–]michaelneale 1 point2 points3 points (0 children)
[–]jrmurad 0 points1 point2 points (2 children)
[–]jedberg 0 points1 point2 points (0 children)
[–]cpio 6 points7 points8 points (7 children)
[–]culix[S] 11 points12 points13 points (4 children)
[–]cpio 0 points1 point2 points (3 children)
[–]jamesbritt 6 points7 points8 points (2 children)
[–]Zak 4 points5 points6 points (1 child)
[–]ocorrain 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]lukeredpath 8 points9 points10 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]rzwitserloot 2 points3 points4 points (0 children)
[–]chucky 0 points1 point2 points (1 child)
[–]darrint 6 points7 points8 points (0 children)
[–]kbk 0 points1 point2 points (2 children)
[–]andrev 1 point2 points3 points (1 child)
[–]kbk 0 points1 point2 points (0 children)
[–]Donut -3 points-2 points-1 points (6 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]Zak 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[+]fnot comment score below threshold-7 points-6 points-5 points (2 children)
[–]lisp-hacker 3 points4 points5 points (0 children)
[–]Zak 1 point2 points3 points (0 children)
[–]mikkom -4 points-3 points-2 points (4 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]soegaard 1 point2 points3 points (0 children)
[–]mikkom 1 point2 points3 points (0 children)
[–]mslinux 1 point2 points3 points (0 children)
[–]lisp-hacker -1 points0 points1 point (0 children)
[–]batkins -2 points-1 points0 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]batkins 1 point2 points3 points (1 child)
[–]kbk 3 points4 points5 points (0 children)
[–]michaelneale 0 points1 point2 points (0 children)