Computer Science Canada

Making the case for O'Caml as an introductory language

Author:  wtd [ Wed Dec 22, 2010 3:33 pm ]
Post subject:  Making the case for O'Caml as an introductory language

Making the case for O'Caml as an introductory language.

Let's compare it to some other popular choices and see how it compares. Let's call those choices Java, C++, Python and Scheme.

Tools

One of the critical aspects of instruction is that a good selection of tools exist to aid in teaching. I will disregard texts here as this is mostly about software tools, except to say that the language I'm trying to make a case for is at a disadvantage.

I think one of the most important tools a programming language can provide is some form of interactive environment: a quick and easy prompt to enter expressions or statements into and see a result, without having to write an entire program, save to a file and compile and/or run it.

Both Python and Scheme rank pretty highly here, and O'Caml is right up there with them. Java and C++ have no such polished environments. Java does have BeanShell, but the verbosity of the Java language does not work well with such an environment.

O'Caml's interactive environment earns special points for clarifying type information in its output and very clearly highlighting the source of any syntax errors.

Win: O'Caml

Java and C++ provide compilers, while Python and Scheme (as it is commonly taught) provide interpreters. Interpreters are often nice as they avoid separate compile and run steps. However, a compilation step does frequently catch problems with type incompatibilities that an interpreter leaves until run-time.

O'Caml provides both tools, offering greater flexibility, and remains statically-typed in its interpreted form, catching mistakes sooner rather than later.

Win: O'Caml

All of the languages mentioned have solid and open developer support, which is critical to their use in an educational environment.

Ambiguity

One of the biggest stumbling blocks I've noticed for students new to programming is ambiguity in the programming language they're using. A language which allows operator overloading, and in particular in Java's case overloads them only sometimes only serves to confuse students.

C++ is particularly notorious for this. Java is mildly better, but some might argue worse, as it allows for special cases, while C++ has codified its ambiguity, albeit with byzantine rules.

Python is much better, especially wit its indentation-based blocks and relatively simple syntax. New students may find list comprehensions and literals a bit confusing, and operator overloading can make things a bit odd. There's a fair amount of magic going on.

Scheme is very unambiguous thanks to s-expressions and essentially the lack of syntax.

O'Caml goes down a different road, with a lot of syntax, but ends up at a similar place since operators are almost never overloaded for different types, and keywords are rarely reused for different purposes (C++ I'm looking at you).

Win: O'Caml's static typing and strict enforcement of that allow it to slightly edge out Scheme for me in this area. It also gains special points for not allowing an "if" without an "else" or unmatched patterns.

Learning Curve

It has been my observation that students new to programming benefit from a gentle learning curve. To ask them to go from no knowledge to understanding high-level concepts in order to get started is asking too much.

Let's look at Java. To construct a basic first program, we have a class and a method with keywords like "public" and "static". We have objects like "System.out". This is a lot to throw at a new student who doesn't have the vaguest idea what it means.

The same thing in C++ demands a knowledge of namespaces and functions and operator overloading.

Scheme, Python and O'Caml win here, adding depth as students go, rather than dumping it all on them at the start and then explaining it over the duration of the course, but Python takes half a step back as soon as we start to delve into "everything is a object".

Win: O'Caml and Scheme tie

Breadth

A gentle learning curve is great, but we also want to be able to cover a lot of concepts with an introductry language. If not in one course, then in a couple of them.

C++ is a very versatile language, with support for a wide variety of programming styles. Unfortunately the support for many of these relies heavily on things like templates, which current tools do not support overly well with clear error messages. Debugging a template error is not something that should be forced upon students in an introductory class.

Java is very narrow. The only interest Java has is object-oriented programming. While one may argue this is good from a commercial standpoint, it limits its usefulness in education tremendously.

Python is much more broad than Java, and makes its breadth of concepts more easily accessible than C++. Unfortunately there is a certain callousness among the powers that be in the Python community toward functional programming which keeps it from earning top marks here.

Scheme does a very nice job with both imperative and functional programming, but object-oriented programming is a bit of an afterthought, and it shows, and while may might prefer it that way, I think not preparing students for this style of programming would be inadvisable.

Win: O'Caml supports imperative, functional and object-oriented programming well. It is the clear winner here.

Conclusion

Exploring four major areas of concern in an introductory programming course: tools, ambiguity, learning curve and breadth, we are left with a clear winner, and a strong case for taking a serious look at O'Caml as a language to use in such a course.

Author:  jcollins1991 [ Wed Dec 22, 2010 4:58 pm ]
Post subject:  Re: Making the case for O'Caml as an introductory language

Interesting arguments for O'Caml, but seems a bit one sided... In what ways might O'Caml lose to other languages? / Is there anything about it that might deter users of other languages from switching?

Author:  wtd [ Wed Dec 22, 2010 9:10 pm ]
Post subject:  RE:Making the case for O\'Caml as an introductory language

A lack of widespread industry adoption could be a ding against it compared to Java or C++ and to a lesser extent Python. Scheme is equally academia-bound.

However, I consider this to be something of a moot point, as an introductory language is fairly far removed from a programmer being ready for the workplace. There is time to learn Java or C++ or something else.

Author:  TerranceN [ Wed Dec 22, 2010 10:16 pm ]
Post subject:  RE:Making the case for O\'Caml as an introductory language

This may just be my inexperience with the language talking, but I find it very hard to read. Looking at some code samples on Wikipedia, I had trouble understanding what was going on, while similar examples in python and Turing, are far easier to read as an outsider to the language.

Author:  wtd [ Wed Dec 22, 2010 10:37 pm ]
Post subject:  RE:Making the case for O\'Caml as an introductory language

Mind elaborating and providing some samples?

Keep in mind I'm making a case for this as an introductory language. Lack of syntactic bias would lead to fewer such incidents.

How do you find O'Caml code for readability compared to the other languages I listed?

Author:  jcollins1991 [ Wed Dec 22, 2010 10:55 pm ]
Post subject:  Re: Making the case for O'Caml as an introductory language

If one were to look at any of the languages (with no prior knowledge of them) I think Java or C++ would be easiest to understand just because of indentation and how stuff is written.

code:

#let rec map f l =
   match l with
     [] -> []
   | hd :: tl -> f hd :: map f tl;;


I think the short forms of a bunch of this stuff may be more confusing to people, which is why I like Scheme as a learning language because the syntax is faster to learn, once you know it it's easier to understand sample programs.

code:

let fib n =
  let rec fib_aux n a b =
    match n with
    | 0 -> a
    | _ -> fib_aux (n - 1) (a + b) a
  in
  fib_aux n 0 1;;


Overall the syntax of O'Caml looks interesting, but in larger programs it seems like if someone isn't very experienced they could end up writing extremely confusing code (though that's always a risk).

wtd: From the second code sample, is the _ basically the else of the language or something else? Also, what type of support does it have for recursion? IIRC Scheme is designed to be allowed unlimited tail recursive calls, does O'Caml have something similar?

Author:  wtd [ Wed Dec 22, 2010 10:59 pm ]
Post subject:  RE:Making the case for O\'Caml as an introductory language

To convert one sample:

code:
let rec sum xs =
  match xs with
    | [] -> 0
    | x :: xs' -> x + sum xs'


In Python:

code:
def sum(xs):
    if xs == []:
        return 0
    else:
        x = xs[0]
        xs_prime = xs[1:-1]
        return x + sum(xs_prime)


That much clearer in Python?

Author:  wtd [ Wed Dec 22, 2010 11:08 pm ]
Post subject:  RE:Making the case for O\'Caml as an introductory language

The _ in this case is anything so yes it acts as a default case, and it also says to the compiler/interpreter: "I don't care about the value of this, so don't give it a name."

And yes, O'Caml's tools implement tail call elimination.

Author:  wtd [ Wed Dec 22, 2010 11:55 pm ]
Post subject:  RE:Making the case for O\'Caml as an introductory language

Another example:

code:
let stringify x =
   match x with
        1 -> "one"
      | 2 -> "two"
      | 3 -> "three"
      | _ -> "some number"


Alternately, if we actually want that value:

code:
let stringify x =
   match x with
        1 -> "one"
      | 2 -> "two"
      | 3 -> "three"
      | n -> "some number " ^ (string_of_int n)

Author:  wtd [ Thu Dec 23, 2010 3:02 am ]
Post subject:  RE:Making the case for O\'Caml as an introductory language

Of course, we could always just use "if".

code:
let stringify x =
   if x = 1 then "one"
   else if x = 2 then "two"
   else if x = 3 then "three"
   else "some number"


But why bother with that mess when we can use pattern matching?

Author:  wtd [ Thu Dec 23, 2010 4:13 am ]
Post subject:  RE:Making the case for O\'Caml as an introductory language

On the fibonacci example:

code:
let fib n =
    let rec fib_aux n a b =
        match n with
              0 -> a
            | _ -> fib_aux (n - 1) (a + b) a
    in
        fib_aux n 0 1;;
 
def fib(n):
    def fib_aux(n, a, b):
        if n == 0:
                    return a
        else:
                    return fib_aux(n - 1, a + b, a)
    return fib_aux(n, 0, 1)


The two are really not too different in terms of comprehension, once similar indentation style is applied. Of course, the Python example is contrived, as Python does not (and by its BDFL's wishes never will) support tail call elimination.

Author:  bbi5291 [ Thu Dec 23, 2010 4:14 am ]
Post subject:  Re: Making the case for O'Caml as an introductory language

I think Haskell has nicer syntax for this sort of thing:

O'Caml:
code:
#let rec map f l =
   match l with
     [] -> []
   | hd :: tl -> f hd :: map f tl;;


Haskell:
code:
map f [] = []
map f (hd:tl) = f hd : map f tl


O'Caml:
code:
let rec sum xs =
  match xs with
    | [] -> 0
    | x :: xs' -> x + sum xs'


Haskell:
code:
sum [] = 0
sum (x:xs) = x + sum xs


I guess the purely functional paradigm of Haskell does hit students a bit hard though (with no direct support for imperative and object-oriented programming, only emulation with monads and whatnot).

Author:  wtd [ Thu Dec 23, 2010 4:38 am ]
Post subject:  RE:Making the case for O\'Caml as an introductory language

Yeah. Haskell is a fantastic thing for students to challenge themselves with... but later on. It's a great language, but really high in magic content. Smile

Author:  wtd [ Thu Dec 23, 2010 3:19 pm ]
Post subject:  Re: Making the case for O'Caml as an introductory language

Versions of a very simple program written by just about every student early on. All done fairly naively. I haven't had time this morning to dealve back into Scheme, so whoever wants to fill that in, please do so.

code:
#include <iostream>

using namespace std;

float farenheit_to_celsius(float farenheit_temp)
{
    return (farenheit_temp - 32) / 1.8;
}

int main()
{
    float input_temp;

    cout << "Input temperature: ";
    cin >> input_temp;

    cout << "In Celsius: " <<  farenheit_to_celsius(input_temp)" << endl;

    return 0;
}


code:
public class TemperatureConverter {
    public static float farenheitToCelsius(float farenheitTemp) {
        return (farenheitTemp - 32) / 1.8;
    }

    public static void main(String[] args) {
        BufferedReader input = new BufferedReader(newInputStreamReader(System.in));

        System.out.print("Input temperature: ");

        float inputTemp = Float.ParseFloat(input.readLine());

        System.out.println("Celsius temperature: " + inputTemp);
    }
}


code:
def farenheit_to_celsius(farenheit_temp):
    return (farenheit_temp - 32) / 1.8

print "Input temperature: ",

input_temp = float(raw_input())

print "Celsius temperature: ", farenheit_to_celsius(input_temp)


code:
let farenheit_to_celsius farenheit_temp =
    (farenheit_temp -. 32.) /. 1.8;;

print_string "Input temperature: ";;

let input_temp = read_float ();;

print_endline ("Celsius temperature: " ^ (farenheit_to_celsius input_temp));;

Author:  bbi5291 [ Thu Dec 23, 2010 11:39 pm ]
Post subject:  Re: Making the case for O'Caml as an introductory language

Scheme:
code:

(display "Input temperature: ")
(display (format "Celsius temperature: ~a\n" (/ (- (read) 32) 1.8)))

(Scheme might have a printf function, essentially the composition of display and format. I'm too lazy to check the standard.)

Author:  wtd [ Fri Dec 24, 2010 12:11 am ]
Post subject:  Re: Making the case for O'Caml as an introductory language

bbi5291 @ Fri Dec 24, 2010 12:39 pm wrote:
Scheme:
code:

(display "Input temperature: ")
(display (format "Celsius temperature: ~a\n" (/ (- (read) 32) 1.8)))

(Scheme might have a printf function, essentially the composition of display and format. I'm too lazy to check the standard.)


code:
(define (farenheit-to-celsius farenheit-temp)
    (/ (- farenheit-temp 32) 1.8))

(display "Input temperature: ")

(let ((input-temp (read)))
    (display (format "Celsius temperature: ~a\n"
                     (farenheit-to-celsius input-temp))))

Author:  wtd [ Sun Dec 26, 2010 11:37 pm ]
Post subject:  Re: Making the case for O'Caml as an introductory language

jcollins1991 @ Thu Dec 23, 2010 5:58 am wrote:
Interesting arguments for O'Caml, but seems a bit one sided.


To directly address this...

I have considered this issue for a long time, and have experience with numerous programming languages, as well as educating several compsci.ca members on various programming concepts. And of course, I'm self-taught. I have become quite convinced of O'Caml's merits over the years for this purpose.

It is one-sided, but largely because I think this language really is that good.

Author:  SmokeMonster [ Sat Jan 01, 2011 6:17 am ]
Post subject:  Re: Making the case for O'Caml as an introductory language

I see absolutely nothing wrong with teaching Java/C++ as an introductory language. So what if the students have to see more than they need to when start with the language? Java and C++ are fine languages and have a bonus of being widely accepted in the industry. I know tons of people who started off with Java as their first language and turned out to be just fine as programmers. Why not kill two birds with one stone? Teach the students basics of programming and also teach them something that is widely used. An additional advantage of knowing Java or C++ is that it makes transition to C a language that is used in most upper year courses a lot easier. I looker at the sample code for OCaml and the syntax seems cryptic, I don't know how that's easier than the equivalent Java, C++ or Python code. If one insists on teaching an alternative language Ruby might be a better choice, although it might be too easy a language and cause frustration to students learning Java or C++ after programming in Ruby.

Author:  wtd [ Sat Jan 01, 2011 9:03 am ]
Post subject:  RE:Making the case for O\'Caml as an introductory language

SmokeMonster: which programming languages do you know?

I ask because what we already know biases us, but I am proposing an introductory language and not an only language.

Author:  jcollins1991 [ Sat Jan 01, 2011 10:37 am ]
Post subject:  Re: Making the case for O'Caml as an introductory language

@wtd:

A few more questions...

In Racket (PLT Scheme) there are different learning levels you can choose (subsets of scheme), and each has different error messages appropriate to someone who knows just that subset of the language, and they're all very clear on where the error occurred. Are there any versions of O'Caml that have something similar?

Does the breadth of the language really matter that much? I think it'd be useful in that students have another really useful language to work with later, but for an introductory language couldn't this then re-introduce the problem in Java and C++ where students see too much too soon? I go to UW and they eventually teach the concepts not covered in the first course (done solely with Scheme) using C and C++, which I think is useful as you get exposure to more languages. Personally, learning only a single language to get all the concepts would feel more like a college (in the Canadian sense) where you're being taught a single tool to solve problems with. O'Caml seems to have great versatility, but I'm not sure this should really be a deciding factor in the choice of an introductory language.

Last thing about O'Caml is that while it may be good, what about it is so much better than any other introductory language that anyone should SWITCH to it. New courses might be willing to adopt it, but what do you think could convince a university or highschool that already teaches Python or Scheme to switch their resources to O'Caml?

@SmokeMonster:

I can see absolutely everything wrong with trying to teach people with Java or C++. They might be appropriate when you're teaching students in highschool to make eye candy, and possibly for implementing programming concepts, but definitely not for just teaching the programming concepts. And like wtd asked, what programming languages do you know? / what ones were you taught with?

Author:  wtd [ Sat Jan 01, 2011 2:11 pm ]
Post subject:  Re: Making the case for O'Caml as an introductory language

jcollins1991 @ Sat Jan 01, 2011 11:37 pm wrote:
@wtd:

A few more questions...

In Racket (PLT Scheme) there are different learning levels you can choose (subsets of scheme), and each has different error messages appropriate to someone who knows just that subset of the language, and they're all very clear on where the error occurred. Are there any versions of O'Caml that have something similar?


No, and this is a nice feature. Not nice enough to win the game, in my opinion, but nice.

jcollins1991 @ Sat Jan 01, 2011 11:37 pm wrote:
Does the breadth of the language really matter that much?


If we're learning at a C++/Java speed, hindered by all of that baggage: no.

If we're learning at a "holy crap Scheme is easy!" pace, then yes, it would be nice to have a language where you can learn about things like OOP as well.

jcollins1991 @ Sat Jan 01, 2011 11:37 pm wrote:
I think it'd be useful in that students have another really useful language to work with later, but for an introductory language couldn't this then re-introduce the problem in Java and C++ where students see too much too soon?


This is one of the reasons I like O'Caml. You don't need to use namespaces or modules or header files or the like to print "Hello, world!" nor do you need to understand objects. As you wish to learn new things, they're added on.

jcollins1991 @ Sat Jan 01, 2011 11:37 pm wrote:
I go to UW and they eventually teach the concepts not covered in the first course (done solely with Scheme) using C and C++, which I think is useful as you get exposure to more languages. Personally, learning only a single language to get all the concepts would feel more like a college (in the Canadian sense) where you're being taught a single tool to solve problems with. O'Caml seems to have great versatility, but I'm not sure this should really be a deciding factor in the choice of an introductory language.


I've learned many programming languages and it's that experience that lets me pitch O'Caml with authority, so I'd be the last person to tell you not to learn other programming languages. The more the better! (Just this one first)

jcollins1991 @ Sat Jan 01, 2011 11:37 pm wrote:
Last thing about O'Caml is that while it may be good, what about it is so much better than any other introductory language that anyone should SWITCH to it. New courses might be willing to adopt it, but what do you think could convince a university or highschool that already teaches Python or Scheme to switch their resources to O'Caml?


Indeed.

I'm not asking anyone to switch at this point. I'm just making a "grass roots" appeal for it to be seriously considered.

Thanks for your continued interest in the debate!

Author:  bbi5291 [ Sat Jan 01, 2011 2:48 pm ]
Post subject:  Re: Making the case for O'Caml as an introductory language

SmokeMonster @ Sat Jan 01, 2011 6:17 am wrote:
I know tons of people who started off with Java as their first language and turned out to be just fine as programmers.
I'm convinced that there are a lot more people who start off with Java and then don't turn out to be "just fine" as programmers. I'm not really sure why this is. It could be because Java is such a bad language to use to teach programming, or it could be because Java is really easy for people who are n00bs in the first place to understand. Functional languages do seem to do a good job of weeding out students whose motives for studying CS aren't "pure", so to speak.

Author:  wtd [ Sat Jan 01, 2011 3:04 pm ]
Post subject:  RE:Making the case for O\'Caml as an introductory language

Java is a great language to teach first if you want to produce Java programmers.

Author:  jcollins1991 [ Sat Jan 01, 2011 7:02 pm ]
Post subject:  Re: Making the case for O'Caml as an introductory language

Finally, are there any textbooks aimed at teaching introductory CS with examples in O'Caml? It'd be interesting to see how someone would teach programming in O'Caml but most of the intro programming stuff I've found in Google are more about coding than the concepts Sad

Author:  wtd [ Sat Jan 01, 2011 7:37 pm ]
Post subject:  RE:Making the case for O\'Caml as an introductory language

Give me time to write it. Smile

Or, talk to me online and I'll show you some things that'll mess up your mind if you haven't done functional programming before. I'm on Google Talk. My e-mail address is cdutton at gmail dot com.

Author:  wtd [ Mon Jan 03, 2011 2:35 am ]
Post subject:  Re: Making the case for O'Caml as an introductory language

The attached is a very quick draft.

Edit (1/3/2011 @ 9:34PM PST): updated file uploaded.

Author:  SmokeMonster [ Tue Jan 04, 2011 5:32 am ]
Post subject:  Re: RE:Making the case for O\'Caml as an introductory language

wtd @ Sat Jan 01, 2011 9:03 am wrote:
SmokeMonster: which programming languages do you know?

I ask because what we already know biases us, but I am proposing an introductory language and not an only language.


I know VB, Java, C and Ruby (learned in that order). I've done most of my programming recently in C.

bbi5291 @ Sat Jan 01, 2011 2:48 pm wrote:
SmokeMonster @ Sat Jan 01, 2011 6:17 am wrote:
I know tons of people who started off with Java as their first language and turned out to be just fine as programmers.
I'm convinced that there are a lot more people who start off with Java and then don't turn out to be "just fine" as programmers. I'm not really sure why this is. It could be because Java is such a bad language to use to teach programming, or it could be because Java is really easy for people who are n00bs in the first place to understand. Functional languages do seem to do a good job of weeding out students whose motives for studying CS aren't "pure", so to speak.


What is the basis of that remark other than what seems to be a personal hatred and distaste for Java. Do you have any statistics to back that claim up? Java is hardly a noob language, as it has been mentioned in this very thread it has a steeper learning curve due the the fact how engrained OOP is in the design of the language. Sure it's not as hard on you as something like C is but in no way is it a noob language like VB. Also, the second part of your argument does not make a lot of sense, someone doesn't become a programmer by taking that first year course in introductory java, one has to go through exponentially harder stuff like Algorithm Analysis, Compilers, Formal Languages, Operating Systems etc before they graduate and surely those classes would do a better job of weeding out students or toughning them up then any basic first year introductory course using a functional language (or any language for that matter would) ever could.

Author:  wtd [ Tue Jan 04, 2011 12:12 pm ]
Post subject:  RE:Making the case for O\'Caml as an introductory language

Java, VB, C and Ruby means that you've likely done all of your programming in mostly the same imperative way. I do not mean to discount your opinion, but you need to broaden your perspective before you can comment as authoritatively as you are.

I've been in your position. I benefited from diversifying.

Author:  wtd [ Tue Jan 04, 2011 12:57 pm ]
Post subject:  Re: Making the case for O'Caml as an introductory language

Another update. More significant this time.

Hopefully at this point, if nothing else, those with concerns about syntax feel a bit more comfortable with it.

Author:  jcollins1991 [ Tue Jan 04, 2011 3:34 pm ]
Post subject:  Re: Making the case for O'Caml as an introductory language

With the explanation the syntax of O'Caml actually seems pretty nice.

code:

# let baz =
     (let foo = 42
      and bar = 2
      in
         (foo / bar - 5 * 2 + 1))
  and wooble = 4
  in
     (baz - wooble) ;;
- : int = 8


Being able to define local variables within function definitions is extremely nice and could add quite a bit of readability to programs, and feels a lot more intuitive than the equivalents in the Racket teaching languages.

I guess the only problem left would be indentation preference, is there any type of standard for indentation (like with Python)? (In Racket it seemed some profs liked certain indentation while others had really ugly indentation, and I ended up having to completely reformat a lot of code examples to something that my eyes could easily scan through)

Author:  bbi5291 [ Tue Jan 04, 2011 3:54 pm ]
Post subject:  Re: RE:Making the case for O\'Caml as an introductory language

SmokeMonster @ Tue Jan 04, 2011 5:32 am wrote:
wtd @ Sat Jan 01, 2011 9:03 am wrote:
SmokeMonster: which programming languages do you know?

I ask because what we already know biases us, but I am proposing an introductory language and not an only language.


I know VB, Java, C and Ruby (learned in that order). I've done most of my programming recently in C.

bbi5291 @ Sat Jan 01, 2011 2:48 pm wrote:
SmokeMonster @ Sat Jan 01, 2011 6:17 am wrote:
I know tons of people who started off with Java as their first language and turned out to be just fine as programmers.
I'm convinced that there are a lot more people who start off with Java and then don't turn out to be "just fine" as programmers. I'm not really sure why this is. It could be because Java is such a bad language to use to teach programming, or it could be because Java is really easy for people who are n00bs in the first place to understand. Functional languages do seem to do a good job of weeding out students whose motives for studying CS aren't "pure", so to speak.


What is the basis of that remark other than what seems to be a personal hatred and distaste for Java. Do you have any statistics to back that claim up? Java is hardly a noob language, as it has been mentioned in this very thread it has a steeper learning curve due the the fact how engrained OOP is in the design of the language. Sure it's not as hard on you as something like C is but in no way is it a noob language like VB. Also, the second part of your argument does not make a lot of sense, someone doesn't become a programmer by taking that first year course in introductory java, one has to go through exponentially harder stuff like Algorithm Analysis, Compilers, Formal Languages, Operating Systems etc before they graduate and surely those classes would do a better job of weeding out students or toughning them up then any basic first year introductory course using a functional language (or any language for that matter would) ever could.

To address the question of fact: Regardless of whether you start in Java, or C++, or Python, whatever, you're more likely not to be a successful programmer than to be a successful programmer. So in that sense my statement is true at face value. But yes, you're right, I don't have the statistics to back up my real claim, which is that there is a correlation between starting in Java and poor future performance in programming. It's actually based on personal experience. Almost all of the best programmers I know knew how to program before taking high school CS classes, and they rarely choose to learn Java first.

Correlation does not imply causation, which is why I said "I'm not really sure" --- I don't insist that learning Java first tends to make one a bad programmer; rather, I simply consider it likely.
Quote:
JavaSchools also fail to train the brains of kids to be adept, agile, and flexible enough to do good software design (and I don't mean OO "design", where you spend countless hours rewriting your code to rejiggle your object hierarchy, or you fret about faux "problems" like has-a vs. is-a). You need training to think of things at multiple levels of abstraction simultaneously, and that kind of thinking is exactly what you need to design great software architecture.

(This is from http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html )
What can we take away from this? If you really know in advance what skills you're supposed to be developing, and you work on developing them, then it doesn't matter whether you start in Java or any other language. If you don't, which is generally what happens when people learn to program for the first time, then, in Java, you're more likely to be bogged down by the details of OOP when you should be thinking about abstraction, whereas in a functional language, you're forced to think in abstraction from the beginning.

My second comment is only tangentially related to the first one. Some people want to become great software engineers. Others begin with the aspiration of creating amazing games without the willingness to learn good design technique and difficult math and algorithms. The sooner the latter group figures out that CS/SE is really not for them, the better. I'm not saying this out of contempt, but matter-of-factly; I feel sorry for people who, upon reaching Waterloo CS, realize that CS isn't what they thought it would be. If you start by learning a functional language, you'll figure it out pretty quickly, whereas this isn't true of Java, in which you can start writing crappy games pretty quickly.

Author:  wtd [ Tue Jan 04, 2011 10:23 pm ]
Post subject:  Re: Making the case for O'Caml as an introductory language

jcollins1991 @ Wed Jan 05, 2011 4:34 am wrote:
With the explanation the syntax of O'Caml actually seems pretty nice.

code:

# let baz =
     (let foo = 42
      and bar = 2
      in
         (foo / bar - 5 * 2 + 1))
  and wooble = 4
  in
     (baz - wooble) ;;
- : int = 8


Being able to define local variables within function definitions is extremely nice and could add quite a bit of readability to programs, and feels a lot more intuitive than the equivalents in the Racket teaching languages.


For those wondering, the above would look like the following in Scheme.

code:
(let ((baz (let ((foo 42)
                 (baz  2))
               (+ (- (/ foo bar) (* 5 2)) 1)))
      (wooble 4))
    (- baz wooble))


[quote="jcollins1991 @ Wed Jan 05, 2011 4:34 am"I guess the only problem left would be indentation preference, is there any type of standard for indentation (like with Python)? (In Racket it seemed some profs liked certain indentation while others had really ugly indentation, and I ended up having to completely reformat a lot of code examples to something that my eyes could easily scan through)[/quote]

There are no mandated rules about whitespace. I could write my example as follows and it'd be perfectly valid.

code:
# let baz = let foo = 42 and bar = 2 in foo / bar - 5 * 2 + 1 and wooble = 4 in baz - wooble;;
- : int = 8


That said, I either indent 3-4 spaces (consistently) or if I'm putting arguments to a function on their own lines I use:

code:
foo bar
    baz
    (wooble a)
    b;;

Author:  wtd [ Thu Jan 06, 2011 2:19 pm ]
Post subject:  Re: Making the case for O'Caml as an introductory language

Another update.

Author:  Shanethe13 [ Wed Mar 09, 2011 10:00 pm ]
Post subject:  RE:Making the case for O\'Caml as an introductory language

As someone taking computer science at Waterloo next year, I would love it for the courses to be taught in O'Caml. I've never used the language myself, but from what I've seen, it looks like it would make a great stepping stone onto "weirder" languages like Haskell.

Regardless of whether or not you'll ever use it outside of academia, just learning a functional language is a great exercise which all programmers should at the very least attempt. I play around with Haskell on occasion, and despite never having used it in a major project, just the process of learning the language has completely changed how I look at certain problems: it requires a completely different mindset which lends itself extremely well to problem solving.

Scheme is also a great introductory language though, and so long as something like Java or C++ isn't taught, I'm happy.

Edit: Just for clarification, I am not advocating Haskell as an introductory language. I love it myself, but it is just way too mystical to teach as an introductory course: by the time the professor got through all of its nuances (monads, the type system, etc), there wouldn't be enough time to actually teach any computer science. Heck, I've been slowly teaching myself for over a year and I feel like I've barely scratched the surface.

Author:  wtd [ Sun Mar 13, 2011 10:47 pm ]
Post subject:  RE:Making the case for O\'Caml as an introductory language

Thanks for the bump, Shanethe13.


: