[Edu-sig] java

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Oct 15 14:12:18 EDT 2003



> Static languages require declaring variable types before use and are
> generally a lot stricter, and therefore take somewhat longer to learn.

[some text cut]

> Static languages include:  Java, C, C++, C#, Pascal, ocaml


Hi Kirby,


I do have to disagree about clumping OCaml in with those other languages.
OCaml (and the ML languages) are strictly typed, but their type systems
are much more intelligent than traditional "typed" languages.  Unlike
Java, C, C++, C#, and Pascal, OCaml will perform proper type inference; in
almost all cases, types won't have to be explicitely written out.  For
example:

(******)
# let rec length list =
      if list = [] then 0
      else 1 + length (List.tl list);;
val length : 'a list -> int = <fun>
(******)


This length() function takes a list of any type, and knows that it'll
return an integer.  Nothing here requires the programmer to explicitly
declare variable types -- it'll work on lists of strings just as well as
on lists of integers.

(******)
# length ["hello"; "world"];;
- : int = 2
# length [1;2;3;4;5];;
- : int = 5
(******)


And, like Python, OCaml's types will follow values, not names:

(******)
# let age = "forty-two";;
val age : string = "forty-two"
# let age = 42;;
val age : int = 42
(******)

OCaml has a lot of the good features of a "dynamic" language, including a
interactive interpreter.  And although its syntax is a little wacky, that
shouldn't be an excuse to aggregate it with the likes of Java.  *grin*


> If I had to choose one over the other, I'd take Python over Java.
> Students would be more productive more quickly and it's easier to teach.

Yes, Python and OCaml are excellent alternatives to Java.  Both present an
environment where the cost of playing around with the language is very low
--- their interactive interpreters allow for casual experimentation. Java,
on the other hand, requires explicit compilation, so it's just not much
fun to play with.


My apologies for focusing on OCaml so much on this post; I'm still a bit
brainwashed after reading Mark Jason Dominus's page on:

    http://perl.plover.com/yak/typing/typing.html

*grin*


Good luck to you!




More information about the Edu-sig mailing list