rongenre•

At one job we'd replace particularly awful hairball perl scripts with OCaml equivalents. It'd let us [well, me] know what the code was supposed to do a month after the code was working and forgotten.

That it ran significantly faster was just a bonus.

14
rwmjones•

libguestfs is composed of a number of OCaml and Perl scripts, so I guess I'm in a position to comment on this.

OCaml is definitely the preferred language overall, but lack of easy to use first class regexps makes some things more difficult. (Yes, I could use mikmatch, but that would mean requiring an extra library and the numpties don't like adding dependencies).

You'd think that since many of the virt tools are written in Perl, whereas the generator code is written in OCaml, that outside contributors would rush to send patches to the Perl tools only. In fact the reverse is true. Although people say that OCaml scares them, we've had far more outside contributions to the OCaml scripts, and virtually none at all to the Perl code. (This is of course not a very scientific measure, because the scripts are used for different things.)

Some of the scripts like virt-resize that do data structure manipulation I really wish I'd written in OCaml and not in Perl. Wherever I need to use some sort of complex structure in a sane way, Perl fails.

The main complaint about the choice of Perl for virt-v2v was that it's not Python. However choosing Python would have solved none of the problems that we've had with Perl.

Edit: I don't know why people complain that Perl is unreadable. Sure if it's written by morons. But our Perl is clean and 'strict'.

Edit #2: I think also using OCaml is a nice bar to contributions. If someone sends a patch to some OCaml code it's easy to check that it's correct (ie. does it compile?). For Perl we have to check line by line because every dynamic use of something is a potential unchecked bug. (Of course we check all patches line by line anyway, but using OCaml is a lower cognitive burden for the reviewer).

Edit #3: Example Perl script: http://git.annexia.org/?p=libguestfs.git;a=blob;f=tools/virt-resize;hb=HEAD Example OCaml script: http://git.annexia.org/?p=libguestfs.git;a=blob;f=src/generator.ml;hb=HEAD

Edit #4: The ability to combine Perl code with man pages, command line processing and usage, all in one file, is awesome. I really wish OCaml had something like that (if it did I'd probably not use Perl or POD ever again).

8
yogthos•

Perl scripts are cthulhian horrors meant to drive all would be investigatators mad :P

4
sigzero•

That would be because sucky programmers are doing the scripting. It isn't the language's fault.

-4
yogthos•

I think the language certainly plays a role, it's pretty obvious if we apply your argument to brainfuck.

11
ayrnieu•

rongenre isn't replacing a bunch of brainfuck programs with OCaml equivalents. That he is not should give you the final clue.

0
sigzero•

That language is designed to be crazy in the first place. You can program very nice ( nice = readable and maintainable) code in Perl. There is no reason to write "line noise" with it. That is the choice of the programmer.

0
erikd•

Erik Naggum (RIP) hit the nail on the head when he said:

It's not that perl programmers are idiots, it's that the language rewards idiotic behavior in a way that no other language or tool has ever done.

8
reddit_clone•

Don't use a scalpel when a butter knife will do.

Perl does some things better than anything else out there. Had been doing it for years.

1
[deleted]•

I was expecting some replies about Ocaml here, but it's all about Perl, how weird ...

4
[deleted]•

[deleted]

3
LordoftheLemmings•

I'm a smalltalk programmer (self taught), what features does OCaml have that would make someone want to use it over say smalltalk?

1
rwmjones•

Strong typing, checked at compile time, generally short programs / lack of verbosity, and a development environment which is more similar to traditional Unix C compilers. (You may regard the latter as a bad thing, but honestly I've never understood why integrated environments are popular, and I found the one I used in Smalltalk to be extremely annoying).

4
bonzinip•

honestly I've never understood why integrated environments are popular, and I found the one I used in Smalltalk to be extremely annoying

GNU Smalltalk also has a traditional development environment.

2
blondin•

an interesting library on that page: Sexplib

-3
Tommah•

That's for S-expressions, not the more interesting thing :)

4
mhd•

I still dream of a girl with whom I could use sexp as a predicate…

3
Paczesiowa•

scripts often have to print things. ocaml (with all its parametric polymorphism, object system, modules and functors) is not the language to print things.

-5
rwmjones•

I don't know where people get these strange ideas from. We wrote a huge generator script in OCaml. It's sole purpose in life is to print stuff. The majority of the code in that script is concerned with writing to stdout or files. Printing things is not an issue at all.

9
sigzero•

I am curious and I don't know much about ocaml. I have heard that a weakness of ocaml is its libraries or lack there of. Why not use Haskell (which has a very large library to work from) in place of ocaml?

Also is there a good ocaml tutorial out there?

1
rwmjones•

What you're probably hearing is the standard library is spartan. Of course there are hundreds of external libraries which do everything you could possibly want.

The problem here is that people on packaging-challenged platforms (ie. Windows) find that every external library they have to download and install is a huge burden for them, so they'd prefer to have a single installer. Whereas the OCaml developers are all using Debian/Fedora where you just apt-get/yum install the libraries you need instantly. GODI solves this for Windows / Mac users, but since it is a packaging system those users probably don't understand what it does. There's also a "Batteries Included" distribution which attempts to bundle lots of external libraries into a single download.

http://www.ocaml-tutorial.org/ (that's a site I started, so I declare a conflict of interest)

3
notfancy•

GODI broke under one of the latest cygwin releases, so right now Windows is not very viable as a platform for OCaml.

Edit: and things are so complicated outside GNU/Linux precisely because of people like you :-) Thank you so much for your effort!

1
[deleted]•

[deleted]

1
[deleted]•

Here's OCaml Batteries Included for the curious. It's also available as part of the aforementioned GODI.

1
reddit_clone•

I am curious and I don't know much about ocaml.

Because they didn't have their own "Dons" perhaps? :-/

Its lack of popularity surprises me as well. Ocaml is a nice pragmatic multi-paradigm language. Just bad marketing I suppose. Annoying twits like Jon Harrop didn't help much.

Windows was always a second class citizen. I haven't looked at it in years. So I don't know if it has changed.

Also they refused to embrace the multi-threaded model. Ocaml run time ran on a single OS thread and Ocaml itself used green threads. Leroy actually thought OS multi-threading was a passing fad. I don't know if he has changed his mind since.

No overwhelmingly nice IDE.

3
rwmjones•

The multithreaded model (ie. oc4mc) was discussed at the OCaml Users Conference back in April.

The results are not that appealing: in a few cases there is super-linear speed up, in many cases there is poor performance, even worse performance than using a single thread. The cost is (a) a big penalty for single-threaded code, and (b) a great complexity in the implementation.

People already write parallel OCaml code successfully using fork + things like OCaml Ancient. OCaml is notably used where performance matters, such as Lexifi and Jane St (the website of the parent article). With coming 32+ core processors which will be highly NUMA, it's not clear that investing all this effort in SMP (horrible to program as well as not being a clear win) is a good idea at all.

Edit: OCaml doesn't use "green threads" to my knowledge. It has always used ordinary POSIX threads.

3
Paczesiowa•

maybe it's ok for "huge generators" but all those "functions from modules to modules" don't help you with writing function named print. even java has lightweight System.out.println()... and there's something really wrong when adding so many advanced features to the language, and still can't print things comfortably.

-5
yminskyOP•

In ocaml, it's as easy as:

printf "%d + %d = %d\n" 1 1 2;;
7
Paczesiowa•

how about:

printf "%? and %?\n" (Some 1) [1.0] 
1
[deleted]•

This would be a lot more interesting if you had a single iota of a clue as to what you're talking about.

6
rwmjones•

Did you actually bother to look at the link I posted before you wrote that?

2
notfancy•

ocaml (...) is not the language to print things

Eh? I've found OCaml perfect for generating Postscript, for instance, much more sane than tracking arguments on the stack.

1