Java: A language to teach novice programmers?

I just got asked by a colleague on AIM:

Gilles: Question for you. What language would you suggest for somebody who wants to “learn to program”… something easy, yet with good concepts…

…and the attached is my response and justification. I’d be interested in what other people have used to teach modern newbies the essentials of coding; we’ve come a long way from the BASIC, Fortran77 and M68K assy with which I started.

Alec: Java

Gilles: Nah. Way too complex… objects… methods… classes… not for a 15 year old non-geek.

Alec: noooooooooooooooo, i disagree

Alec: they should avoid applet programming for the first couple of months
Alec: avoid the GUI and do commandline java
Alec: Java is reasonably clear

Gilles: Well… that’s an idea…

Alec: and if you are teaching the ideas of subroutines and objects, you can ignore foundation classes

Gilles: True.

Alec: get them thinking in an OOPS manner early, just doing basic maths

Gilles: How about an interpreted language?
Gilles: Python?

Alec: I feel the only other contender is Lisp
Alec: BASIC is evil and too diverse
Alec: Perl is complex and depends on a body of Unix knowledge
Alec: Python – another VHLL – is not far from that, and has weird ideas about records and formatting
Alec: Ruby gets rave reviews, but is similarly a VHLL
Alec: Lisp is simple, very simple, and has good constructs, but can be daunting
Alec: Fortran is dead
Alec: C would be good, but crashes too easily
Alec: C++ is evil
Alec: Forth good is think you backwards can if
Alec: Java is good, so long as you avoid the bullshit
Alec: need i go on?

Comments

26 responses to “Java: A language to teach novice programmers?”

  1. acb
    re: Java: A language to teach novice programmers?

    When I was a CS academic, Java had become the de facto teaching language of choice. And it was taught without the vast class libraries, the GUI stuff and such, as a sort of C++-with-training-wheels. In more academic institutions, they also taught a functional language (not Lisp/Scheme, but a more modern one, like Haskell, Miranda or ML).

    In the late 1990s, C++ seemed to have that role; they taught it on PCs (Turbo C++), and just taught a subset of it.

    When I was a student, in the early 1990s, we used specialised teaching languages. The first-year language we got thrown at us was named Turing, which was a sort of Pascal-lite running on Macintosh Pluses.

    I think that Python would be a good choice for a basic teaching language; its syntax is sparse (few rules to learn) and it supports the imperative, functional and OO paradigms. The thing about it being a VHLL is, IMHO, a good thing if you adopt the top-down paradigm of teaching (first teach them about algorithms and such, and then let them get into the details of implementing data structures and such). Oh, and it also aggressively encourages good indentation practices too. 🙂

  2. J
    re: Java: A language to teach novice programmers?

    Python is the first language now taught on the Comp Sci undergrad modules at Leeds University and it seems extremely effective. There’s a good explanation about the use of Python in the book “Learning to think like a Computer Scientist”.

  3. Katz
    The world of CS…

    When I was cutting my teeth on code in the early/mid 90s the educators language of choice was Pascal (Turbo Pascal on PCs.) I was dinking around with C at home on Linux/FreeBSD because I was a geek.

    The thing with Pascal and C++ in schools and CS programs is that there are a variety of texts designed specifically to educate on the use of those language and explaining CS concepts in the syntax of those languages. Oh Pascal! comes to mind.

    What I’m curious about is what kind of texts exist today that could do the CLI teaching and very basic programming concepts in Java that you’re recommending for Giles’ subject…. maybe just saying “try this stuff out” and handing them a reference book?

  4. Marc Hamilton
    re: Java: A language to teach novice programmers?

    If your not a computer scientist, it is probably easy to confuse teaching a programming language with teaching programming. I’m a big believer in the concept of teaching Objects first. The longer you wait to introduce Objects, the harder it becomes. It is hard to break the bad habits of an old C programmer (speaking from personal experience). If you want to learn about Objects first, and the Java language along the way, you definitely should check out the book “Objects First With Java” and the BlueJ interactive Java environment. My ten year old picked up the book this summer and had his first Java object oriented program working in less than an hour!

  5. alecm
    Python

    >and it also aggressively encourages good indentation practices too

    Mmmmm… so that’s how they justify it, huh? 😎

  6. alecm
    OOPS

    Interesting.

    I’m probably atypical – hell, I’m certainly atypical – but as a dyed-in-the-wool procedural-programmer (BASIC, Fortran, Forth, C, Perl4, Lisp, various homebrew mini-languages) sometime around 1997 I managed to pick-up Java in about 2 weeks, chiefly by mainlining example code snippets.

    The OOPSy-ness of it all just seemed logical, except for some baggage that I found ugly and awkward, notably overloading of “+” for string handling, religious fervour that there was to be no varargs/printf mechanism, and that for a language that was supposedly unlimited, why were you not allowed to serialize a String that was >64kb ?

    ObQuery: What idiot imposed *that* 16-bit limit?

    That I took so well and so immediately to OOPS surprised me; that said, I avoid other people’s OOPS programming because most of it seems so *awful*, especially in the Perl world.

    People just sometimes sometimes seem to create classes just because they feel they should, rather than its making any sense to do so; if you have to create objects to perform a single action, and then destroy them, you’re doing something wrong

    ObJavaBitch: “foo”+42+”bar”+i should only create 1 StringBuffer, not three nested ones… It’s an evil waste of memory and CPU time, both in operation and GC. Has that been fixed yet?

    I do sometimes wonder whether prior exposure to AmigaOS – where procedural C was the order of the day, and where everything was a OOPSalike shared library, with IPC done by shared-memory message-passing – might have been the key to my “getting it”.

  7. Chris Samuel
    Python considered psychologically damaging

    I *strongly* dislike bondage and discipline languages, so Python is right out for me. I also had the nasty experience of being given some Python code to work with back in the UK when I’d had no experience of it, and it took me about a week to work out that the only reason my code wouldn’t work was because it had some dumb idea that my formatting wasn’t what it wanted. Of course it wasn’t what it wanted, it was what *I* wanted.

    If I wanted to be told how to write my program I’d be a Microsoft weenie.. grrrr…

    Chris

  8. Stephen Usher
    re: OOPS

    Your comment “People just sometimes sometimes seem to create classes just because they feel they should, rather than its making any sense to do so; if you have to create objects to perform a single action, and then destroy them, you’re doing something wrong” would put the heckles up for the pure OOP evangelists.

    For them, every data type must be an object. The only way to modify an object should be by using one of the object’s methods. So, instead of using the “i = j + k” you should have a method for the type i is which adds the values and set the value of the type.. and of course you’d need to use a method to extract value as well.

    Yes, I agree that’s stupidly cumbersome but idealists like the cumbersome as it make it seem like a black art.

  9. Chris Samuel
    Fortran

    Before I got into this whole HPC world I’d have laughed at folks who said that Fortran was useful, but now I’m amazed at how much it is still in use, and how far some folks go with their C code to avoid constructs that will avoid a few extra clock cycles, some of which is apparently unnecessary in Fortran.

    When you’ve got codes that run for weeks or months (or even “for ever”, with checkpointing so that when we need to do a shutdown the can restart from where they left off) that makes a lot of a difference.

    GCC has finally got a Fortran 95 compiler in GCC 4.0 too!

  10. alecm
    re: OOPS

    >instead of using the “i = j + k” you should have a method for the type i is which adds the values and set the value of the type…

    I do. They’re called “opcodes” for “store” and “increment”…

    >and of course you’d need to use a method to extract value

    …and “fetch”. 😎

  11. alecm
    re: Fortran

    Fortran 95? Pah! That’s for N00bZ!

    You’ve never had to work around a one-trip do-loop, I can tell! 8->

  12. acb
    Bondage and discipline languages?

    Come now, Python isn’t that draconian.

    Firstly, is requiring strict indentation any more of an imposition than requiring strict bracketing (as C/C++/java/Perl and that family do)? And secondly, shouldn’t any competent programmer who cares about their code being maintainable be indenting things consistently in the first place?

    Also, talking about teaching languages, and forming programming habits, there is such a rule as being too laissez-faire. Were students dropped straight into, say, Perl, without the experience to have formed good programming habits, they could end up habitually writing horrible spaghetti code.

  13. alecm
    re: Fortran

    Incidentally, as cited elsewhere I *was* the first person in the Physics department at UCL to submit a final-year thesis in C rather than Fortran; if I knew then what I know now, I would have done it in Fortran because double-to-single-and-back type casting was a total PITA.

    I just haven’t seen any real Fortran code since, oh, debugging Horst Holstein’s geophys package back in 1989, and getting bunged 200 quid for spending 2 hours working out that he’d missed a large-memory compiler switch.

  14. alecm
    /* strict bracketing? */

    main() { {

    int i; { {}{}{}{}{}

    {}{}{}{}{} for (i = 0; i<16; i++)

    printf((((“surely\n”)))); {{printf(“you jest?\n”);}}}}}

  15. alecm
    perl

    incidentally, i agree that Perl is a horrible teaching language; the point of perl is that is utterly breaks the Unix toolkit rule by being every unix tool all in one, and even tries to look the same:

    perl -e vs: sed -e

    tr/abc/123/cd vs: tr -cd abc 123

    grep(/foo/, @list) vs: grep, and awk ‘/foo/{}’

    cat <<!EOT vs: $var =<< “EOT”;

    …all of Unix is there, under one roof, and this is what makes it useful – BUT if you dont know Unix lore, it is a pig to understand why the syntax is that way

  16. alecm
    re: /* strict bracketing? */

    …the irony being, in case anyone misses it, that the one construct in that program which typically takes {braces} – the for loop – is actually missing them, whereas braces and parenthesis are liberally spattered in the code, in spurious places.

    …and if you’re complaining about the need ot have them balanced in pairs, check out “superbrackets” in Lisp, which close all extant open parenthesis:

    http://www.dreamsongs.com/NewFiles/HOPL2-Uncut.pdf

    <<<One of the minor, but interesting, syntactic extensions that Interlisp made was the introduction of the superparenthesis, or superbracket. If a right squarebracket ] is encountered during a read operation, it balances all outstanding open left parentheses, or back to the last outstanding left square bracket [. >>>

  17. Serge Burlyga
    re: Java: A language to teach novice programmers?

    IMHO, I’ll use the foollowing list of choices:

    1. Any from specialised teaching languages;

    2. UML;

    3. Java;

    My 2 cents.

  18. Chris Samuel
    re: Bondage and discipline languages?

    > Come now, Python isn’t that draconian.

    There was some implied humour in the original title of “Python considered psychologically damaging”.

    In fact it’s become a bit of an in joke around here along the lines of the Babylon 5 Drazzi “green” “purple” conflict. “Perl!” “Python!” “Perl!” “Python!”

    I guess they’re lucky I’ve not introduced anyone to Intercal yet, then they’d know what real line noise programming is. 🙂

    > Firstly, is requiring strict indentation any more of an > imposition than requiring strict bracketing […] ?

    I’m happy to use strict indentation as long as I have the freedom to use the *style* of strict indentation, not have it imposed on me by the language.

    I guess I have a rebellious streak that dislikes being told what to do in these sorts of things. 🙂

    DISCLAIMER: I am a sysadmin, not a programmer. The first real programming (as opposed to taught programming) I did was in B for HoneyBoard and AberMUD. This probably explains a lot, when you consider that B had precisely three variable types, auto, extern and internal (if you forgot to define it as one of the other two). 🙂

    Chris

  19. Christopher Davis
    re: OOPS

    I’ve never been too impressed with Perl’s OO features; they always seemed kind of duct-taped on.

    I’ve come to really like Python; I thought the indentation thing would be an issue, but since I generally spent a lot of time re-indenting C or Perl code so that I could tell what Emacs thought the parsing would look like, it actually was easier to work with Python than the other languages I’d been using.

    M68K assembly? Hah, n00b. Try 6502 sometime.

  20. Stephen Usher
    re: Fortran

    Ah, but the only standard FORTRAN is ISO FORTRAN (now at FORTRAN 99 I think) and the old FORTRAN 77 is a distant memory.. well, that’s what the standards committee are saying. 🙂

    FORTRAN has a few very big wins in scientific computing. Firstly, it’s far more predictable at the compilation stage which allows the compiler to optimise far more agressively. Secondly, the formatted text I/O side for reading and writing data files is far better than the native C ones. And having a native imaginary number system helps a great deal as well.

    As for one trip do loops, they’re a thing of the past as well. It’s usually a compiler switch option. If you’re worried, use while/end while or do/while.

    Modern FORTRAN also has structures and dynamic memory management (about time) and I think F99 has started adding OOP stuff.

    OK, so most code is still written with F77+extensions but that’s ‘cos it’s quick and easy to do so.

    Oh, and of course you don’t need to stick to one language in your programs. There are many applications built with FORTRAN for the bits which FORTRAN does best and C for the other bits.

    If you want the job done there’s no point in being a programming language snob.

  21. Stephen Usher
    First language: why one?

    Well, surely, the first language taught should be one which introduces the basic aspects of programming in a simple, clean and unconfusing manner. It shouldn’t necessarily be a language which is useful for all things, however.

    The problem is that if the person is taught a language which confuses them and makes them feel as if they’re never going to grasp it then they will soon give up on programming altogether and think that they can’t do it. This is why I think that C, Pascal, C++, Java, Perl, Python, etc. etc. are ALL the wrong beginner’s languages. The reason? The syntax is too convoluted and confusing. It obscures the most important features, the program design and structure.

    I’m not sure that there *IS* a good learning language out there for OOP. For structured programming, a structured BASIC would be pretty good if there were any standard, free and properly thought out versions out there now.

    The closest I’ve seen so far for a beginner’s language is the Matlab script. There is at least a free version of this, Octave, though it only implements Matlab 4 language elements so it’s a bit primitive and doesn’t have some of the more useful constructs which would help a first time programmer.

  22. Tess
    re: OOPS

    You mean Z80A, surely. 6502 was far too verbose.

  23. Tess
    re: OOPS

    I am likewise lumbered with a longstanding procedural mindset, much to the consternation of the younger developers who fell under my supervision. As far as I’m concerned, objectivification is far too often done just for the sake of it by people who can write OO but have absolutely no ability to debug it. Little is more frustrating when debugging than having to skip around between 20 or 30 classes or sourcefiles to do something that could be as easily and plainly done in a twenty line for-loop.

  24. acb
    re: Bondage and discipline languages?

    What do you mean by the style of the indentation? If you mean deciding how many spaces to indent each block relative to its parent, Python has no problems with that as long as you’re consistent.

    The only other meaning I can think of is whether to break lines before/after opening brackets, which obviously is a non-issue in Python.

  25. Chris Samuel
    re: OOPS

    I like Ted Ts’o’s quote on the dangers of overloading in C++ from the LKML quoted on LWN at:

    http lwn.net/Articles/114782/

    “That’s the problem with C++; it is far too easy to misuse. And with a project as big as the Linux Kernel, and with as many contributors as the Linux Kernel, at the end of the day, it’s all about damage control. If we depend on peer review to understand whether or not a patch is busted, it is rather important that something as simple as

    a = b + c;

    does what we think it does, and not something else because someone has overloaded the ‘+’ operator. Or God help us, as I have mentioned earlier, the comma operator.”

  26. Chris Samuel
    re: Bondage and discipline languages?

    It was so long ago now that, to be honest, all I can remember was that I was indenting my code, and Python wouldn’t work with it until I reformatted it to its liking. I was hacking on urllib to add some basic “If-Modified-Since:” functionality to GET requests.

    This was, erm, 2000/2001, so things may have changed since.. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *