
My Company Is Using OCaml for web development. Why?  - gtani
http://www.nicollet.net/2011/02/objective-caml-web-programming/
======
deno
It seems to me that strongly-typed languages—functional or not—are going to
make a strong comeback to web development. The current trend is to narrow down
your webapp to a REST[ful] API. Any HTML you generate is only to bootstrap
your client-side application (and load initial state) and to accommodate non-
JS-enabled clients, which in this date and age should only mean search engine
spiders.

The advantage is a uniform interface, like a file-descriptor in Plan-9 (an
analogy used in latest InfoQ interview with GO/Newsqueak creator), the HTTP
protocol.

And for that, languages like OCaml or Haskell should flourish. Especially
functional languages, since typical REST API request should be nothing but
data+auth token (whether that's cookie or oauth token).

Applications developed in that model—besides being much simpler to write and
test—are easily cacheable and more secure by default. The added bonus is that
object oriented languages, that have been most successful in GUI programming,
can be once again utilized purely for that.

If not embracing this model one is left with little appealing options: 1)
continue to process text in perl-like manner with RoR/Django/etc., coping with
nondeterministic behavior and security 2) to invest in frameworks that hide
HTTP at all, coding to widgets instead of pages, and to let framework decide
how to push that over the wire, which usually means that some sort of
continuations are employed, which are inherently HTTP-unfriendly and
uncacheable outside of the app's context 3) to replace HTTP with something
else, probably some sort of RPC

~~~
spitfire
Welcome back to client server computing!

~~~
deno
Ah, yes. We made it, indeed, a full circle.

Quite sad, if you think about it…

~~~
spitfire
I love it. We're done with the "ZOMG WEB!" thing. You don't have to lay out
your GUI's with a markup language designed for typography - The modern VT100.
You don't have to keep state with a stateless protocol. Now you get a nice
(mostly) standardized interface and you get to build a lighting fast native
GUI for your app.

I can't wait to see what people cook up over the next five years. Particularly
with the trend towards tablet computers.

~~~
deno
It's good online programming becomes sane again.

I see you're actually eager to make a full leap from 'WEB' to native apps. I
don't disagree, but I think REST+DOM/JS will still have its place there. A
lightweight alternative to full-blown applications, interactive documents that
load in the blink of an eye and transparently integrate with your ecosystem. I
guess it's what web was supposed to be in the first place, but with some added
_zing_.

~~~
johnzabroski
If by 'REST+DOM/JS' you mean "Random Bad, Hodge-Podge Code Filled with
Callbacks and pervasive use of global variables", then yes, bad programming
will always have a place - for PHP programmers.

Most really awesome apps being written these days, that use HTML, are using
the CANVAS tag and doing stuff like building terrain maps of buildings and
showing people holding 4.5" smart phones where in the building druglords are.
Crazy stuff like that.

------
MichaelGG
I'm curious as to the hiring implications. Certainly the harder part is
finding programmers capable of dealing with functional programming, not the
specific language?

And wouldn't advertising OCaml (or Haskell) be a way to get talented folks
quickly? It seems a lot of such programmers wish they could have a job where
they get to use a decent language.

~~~
primodemus
According to Yaron Minsky (Jane Street Capital), yes: "One of the things we
noticed very quickly when we started hiring people to program in OCaml was
that the average quality of applicants we saw was much higher than what we saw
when trying to hire, say, Java programmers. It’s not that there are not really
talented Java programmers out there, there are. It is just that for us, ﬁnding
them was much harder. The density of bright people in the OCaml community is
impressive and it shows up in hiring, when reading the OCaml mailing list, and
when reading the software written by people in the community. That pool of
talent is probably the single best thing about OCaml from our point of view".

More: <http://www.janestreetcapital.com/minsky_weeks-jfp_18.pdf>

~~~
rgoddard
Seems like the same phenomenon described in the python paradox essay:
<http://www.paulgraham.com/pypar.html>

------
pnathan
There are two basic reasons I would select an 'advanced' language for
development.

1 - can express 'weird' things that other languages would not be able
necessarily express without strange gyrations.

2 - if you can develop in it, you're probably on the upper half of the
developer bell curve. That brings systemic improvements in general.

~~~
kenjackson
_if you can develop in it, you're probably on the upper half of the developer
bell curve. That brings systemic improvements in general._

Why hasn't this happened? Preumably if you use an _advanced_ language you'll
be a lot more productive because of the language and because you have the best
developers.

Why haven't we seen shops that use _advanced_ languages just utterly clean up?
"Oh, you're doing 30fps with 1m vertices -- we just did 90fps with 50m
vertices -- and btw, we did this w/o using the GPU". Or "Chrome? We built a
new web browser that supports every draft of every aspect of HTML5, w/ a
Javascript parser that runs at twice the speed of Chrome, and we wrote a new
H264/WebM codec that doesn't require a GPU and can do HD video on a 286".

It just seems like for all the advantages that using an _advanced_ language
presumably gives, the software I see is simply "competitive". Maybe it will be
the best in some spaces, but within the range that one would expect the best
to be if everyone used C, for example.

And even among those who know these _advanced_ languages really well, we don't
see them fighting for them in their organization the way one might think given
all they should presumably provide. Think Norvig, Steele, Abelson, Meijer,
etc...

~~~
pnathan
My observation is that quite often, systems built with the 'advanced'
languages are more sophisticated and are much closer to cutting-edge researchy
ideas. That also tends to correlate with 'niche' and 'small company'. The
essential complexity of the problem must be surmounted. If performance is the
gate, C is still the best.

If development time, algorithms, and ability to wrap the language around the
problem is the gate, an advanced language is going to be better.

According to the Alioth Shootout, OCaml, Haskell, and SBCL are in shouting
range of C/C++ speeds. Link:

[http://shootout.alioth.debian.org/u64q/which-programming-
lan...](http://shootout.alioth.debian.org/u64q/which-programming-languages-
are-fastest.php?gcc=on&gpp=on&ghc=on&ocaml=on&sbcl=on&fsharp=on&calc=chart)

Therefore, if I was selecting an 'advanced' language for a performant real-
world system, I would select one of those.

~~~
kenjackson
_My observation is that quite often, systems built with the 'advanced'
languages are more sophisticated and are much closer to cutting-edge researchy
ideas. That also tends to correlate with 'niche' and 'small company'._

I agree, but I think this is the problem. If _advanced_ languages are better,
its surprising that it doesn't manifests itself in virtually any way that one
can measure.

For example, if you're a CTO deciding which language to use, there is
virtually no data to suggest using an _advanced_ language is advantageous
except religious arguments. Which is odd given they're supposed to confer both
a superior language and superior developers.

Where's the beef? If I'm building a skyscraper, I'm using steam shovels, not
standard shovels. The data makes it clear which is more effective. There's no
remotely similar argument to be made for _advanced_ languages.

~~~
pjscott
It might help to look not at languages, but at attributes of languages. For
example, garbage collection has gone from an expensive feature in "advanced"
languages to something used in almost every programming language. This is
compelling evidence that garbage collection is, in general, a good thing.

Or how about the idea of having special syntax for some common data types,
like lists and dictionaries and (sometimes) sets? This kind of thing is
spreading and becoming more popular, because it really does seem to make
people's jobs easier.

Some more up-and-coming language attributes include type annotations, more
immutability by default, and Erlang-style message passing concurrency. And
maybe support for asynchronous I/O, either with JavaScript-style anonymous
functions or with coroutines. Some of these things really can make certain
programming tasks dramatically easier.

The religious arguments tend to be anchored to languages, but there's some
real information if you look past that to a deeper level.

------
kunalb
I've been looking into Haskell for web development—in particular, the snap
framework. Did you consider using other functional languages before choosing
OCaml, as in does OCaml have any specific advantages for web dev?

~~~
victorNicollet
I wish I could say the choice of OCaml among all available functional
languages was objective, rational and well-deserved... the fundamental reason
is that my knowledge of OCaml is orders of magnitude greater than my knowledge
of Haskell, F# or Erlang (three languages I would have considered using as
well). I do find OCaml more adapted to the way I think, but the way I think
probably ended up the way it is because I have been using OCaml a lot.

I can do a fairly adequate analysis of OCaml-versus-PHP or OCaml-versus-C#
because I'm familiar with both sides of the equation, but I wouldn't be able
to do an honest comparison of OCaml and Haskell.

~~~
gtani
these ask reddit's are pretty good. Good Lang A vs B comp's are _very_ rare.

[http://www.reddit.com/r/ocaml/comments/fmpl8/i_have_yet_to_l...](http://www.reddit.com/r/ocaml/comments/fmpl8/i_have_yet_to_learn_a_functional_programming/)

[http://www.reddit.com/r/haskell/comments/fmp66/i_have_yet_to...](http://www.reddit.com/r/haskell/comments/fmp66/i_have_yet_to_learn_a_functional_programming/)

and this guy's universe of FP languages:

[http://www.slideshare.net/brweber2/functional-concepts-
for-o...](http://www.slideshare.net/brweber2/functional-concepts-for-oop-
developers-presentation)

slide 12: haskell, clean, F#, ML/ocaml, lisp, scheme, scala, clojure, erlang,
XSLT

------
gregwebs
Great article! I program Rails by day, but lately have been working with the
haskell Yesod framework: <http://docs.yesodweb.com/book/basics>. It even has
type-safe urls.

I would disagree that lack of popularity of language is not a technical
problem- it is because there is less community code available.

------
gchucky
It's been cached at [http://www.nicollet.net.nyud.net/2011/02/objective-caml-
web-...](http://www.nicollet.net.nyud.net/2011/02/objective-caml-web-
programming/)

~~~
deno
Really? I get 408 Timeouts.

Anyway you can access it at:
[http://webcache.googleusercontent.com/search?q=cache:http://...](http://webcache.googleusercontent.com/search?q=cache:http://www.nicollet.net/2011/02/objective-
caml-web-programming/&hl=en&strip=1) as well. And I believe OP is working on
bringing the site back online.

~~~
gchucky
Just after posting that link it stopped working for me. Strange.But yeah, your
cache link is better.

~~~
deno
Network creators admit[1] that the architecture of CoralCDN isn't very well
suited for supporting content availability (as opposed to helping with
handling load & bandwidth usage).

For example, at any point in time, content can be removed from cache—before
completing its usual 24h lifecycle—to accommodate resource usage for different
sites.

[1] "Experiences with CoralCDN: A Five-Year Operational View"
<http://www.coralcdn.org/docs/coral-nsdi10.pdf>

------
pestaa
Is it down for me only?

~~~
victorNicollet
No, y'all managed to kill me server >_< I'll try to bring it back from the
dead.

EDIT: it's back (or at least, looks like it). The traffic is being drained to
a static copy of the page, so don't be surprised if comments you post on that
page don't appear.

I'll be back with an actual (cache-based) solution soon, hopefully.

~~~
marceldegraaf
I couldn't resist asking: is the article hosted by an OCaml application? ;-)

~~~
victorNicollet
Interesting question :P, but no: it's a vanilla 3.0.x Wordpress on a RPS
server. The performance issue appears to be the server swapping like mad.

~~~
bradleyland
<http://wordpress.org/extend/plugins/wp-super-cache/>

<http://rimuhosting.com/howto/memory.jsp>

Scroll down to RESOLVING: HIGH APACHE MEMORY USAGE

EDIT: I realized after I posted that simply posting two links might seem
snarky. I don't mean to be. I know these links because I've been in the same
spot you are. I think we all have. That's how we learn :)

~~~
victorNicollet
Thanks for the links, I actually applied the second one on my own, without
much success. Right now, I'm looking at a server with no swapping, normal
memory usage, low processor usage, no IOwait, but serving HTTP requests at the
speed of a dead snail nailed to an ice cube.

I'll try to install the cache plugin as soon as I retrieve control over my
server.

~~~
bradleyland
To get a picture of what's going on, try logging in to your shell and install
htop. It's a great little utility that shows you load averages, memory usage
(broken down in to used, buffered, and cached memory in real time. Very handy.

------
djb_hackernews
Take the opportunity to learn OCaml, then in a year go make the big bucks on
Wall Street implementing trading systems for hedge funds.

------
fleitz
If you're using OCaml for webdev, may I ask why you chose that over F# +
ASP.NET?

~~~
SkyMarshal
Prefer a FOSS stack to the MS platform, to get the obvious out of the way.

