Most active commenters
  • another_twist(4)

←back to thread

Learn OCaml

(ocaml-sf.org)
203 points smartmic | 15 comments | | HN request time: 1.026s | source | bottom
1. another_twist ◴[] No.44402433[source]
Is OCaml still worth learning these days ? Feels like plenty of languages are evolving quite well and most things can be done in imperative langs like Go/Java with pretty concise code and certainly better perf.
replies(6): >>44402448 #>>44402524 #>>44402790 #>>44404250 #>>44405117 #>>44408867 #
2. fulafel ◴[] No.44402448[source]
Functional programming is about clarity of expression and reduced cognitive load.

Aside from FP, the Ocaml type system is better than the mentioned ones. From one hand type inference means you have to write out types much less, and from the other hand the type system is more powerful and lets you express more things than Go/Java.

replies(1): >>44402601 #
3. yawaramin ◴[] No.44402524[source]
Both claims are debatable.

Pretty concise code: Go code is full of `if err != nil {...}` song and dance and they seem pretty committed to keeping it that way. Java is stuck with decades of decisions and libraries made in their early days because they can't break backward compatibility. Eg, all the standard library collection types are mutable. And of course, both of them have the 'null pointer' problem, which OCaml doesn't.

Meanwhile OCaml has had the same main type-level tools (record types, variant types) and techniques (pattern matching, first-class functions) since the very beginning and those are still the workhorse till this day.

Certainly better perf: I'd say that really depends on how much tuning has been done. OCaml applications by default are fairly performant and with OCaml 5's multicore support and effect handlers will unlock even more performance wins.

replies(1): >>44402593 #
4. another_twist ◴[] No.44402593[source]
Go is definitely full of these issues. Java has pretty good perf out of the box due to JIT. The libs may be old but they do their jobs really well. Some common ones like Guava are updated as new features become available. Tbh the collections being mutable isnt really an issue since it gets the job done and reasoning about these things isnt that hard. However I do prefer immutability wherever I can get it.
replies(3): >>44403731 #>>44405727 #>>44417715 #
5. another_twist ◴[] No.44402601[source]
Cant argue with this one. FP code is so much easier to reason about. I was looking at this more from a practical perspective.
6. zulban ◴[] No.44402790[source]
No. Not even a little.

Look at the latest stack overflow developer surveys. It will tell you how much the international community chooses to use (or not) ocaml. To your question, that's people deciding whether it's worth learning.

replies(1): >>44402932 #
7. another_twist ◴[] No.44402932[source]
Yeah but most of the time you learn a language because it changes your way of thinking. I want to pick OCaml for my next project, almost did. But decided against since Java had an ecosystem, tooling and really good performance.
replies(2): >>44403177 #>>44433283 #
8. kzrdude ◴[] No.44403177{3}[source]
Yes for your general education I think you should learn a functional language. This is how I think about it, at least.
9. Quekid5 ◴[] No.44403731{3}[source]
> Tbh the collections being mutable isnt really an issue since it gets the job done and reasoning about these things isnt that hard.

Have you worked in language with immutable collections by default? It's night and day -- no more defensive copies, no more weird ImmutableList wrappers (Guava) which will (interface-wise) say they're mutable but will throw at runtime, no worrying about multithreading, cheap subsequences, etc. etc.

The difference is so stark that I would literally choose a worse[0] language(!) over a better one if it had immutable collections by default.

EDIT: Since you mentioned Java in a sibling comment -- give Scala a try and try working with the collections there.

[0] Within reason, of course :)

10. lmm ◴[] No.44404250[source]
> Is OCaml still worth learning these days ?

If you haven't learnt anything like it, yes.

> most things can be done in imperative langs like Go/Java with pretty concise code

Which is why learning OCaml will make you a better programmer even if you then go back to Go/Java. You'll most likely never learn how to do those things without taking that step.

> and certainly better perf.

If you implement the same algorithm in both, it will be faster in Java. But you're more likely to find the better algorithm working in OCaml.

11. IshKebab ◴[] No.44405117[source]
I would say no. Anything you can do in OCaml you could just as well do in Rust and Rust has many many advantages over OCaml. Vastly bigger ecosystem, Windows support that isn't an afterthought, much better documentation, the syntax is quite a lot friendlier, etc.

Really the only reason I can think to use OCaml over Rust is the compile time, which is quite impressive and significantly better than Rust's. But I don't think that's enough to put up with the other downsides.

I don't think the borrow checker is a factor. OCaml has aspects that are equally painful to learn.

Also if you know Rust you won't really learn much by learning OCaml except "oh that's where that Rust feature came from". Rust stole all the good features from OCaml.

12. akkad33 ◴[] No.44405727{3}[source]
Why are all java apps super slow like Intellij and require you to play around with heap memory with things like xmx min max etc? I write Java code for a living and it's so dependent on frameworks to do many basic things where you can't really reason about the code. Subtle bugs can come from mutability here, nullability there, hidden state in another place and most coding styles rely on these and use them because it is so easy to do. It's possible, but not idiomatic to write immutable stateless code in Java. Coding in Java is now much more pleasant with records, optionals, sealed interfaces and streams, but it's interweaved with old coding styles so that it negates most benefits of the new patterns
13. abathologist ◴[] No.44408867[source]
Indeed it is.
14. throw234234234 ◴[] No.44417715{3}[source]
YMMV but I find Java perf less even with the JIT than OcAml/F# .NET/etc for tuned code which generally is what matters when performance is a concern. The auto-boxing, lack of proper generics, etc really make it hard to do re-use in a performant way especially around math like apps, especially if they use any of the "Big" boxing types. There's too much heap allocation you can't avoid. Better than say Node/Python but even F# in .NET will generally do better here in my testing with inline templating/stack types/spans/etc.

Languages with immutability/lazy seq/etc support built in can be tuned faster than a library (compiler help around sequences/streams rather than pure library based ones), and again the lack of stack types can make some of these immutable collections much slower/take up more memory than other language targets. There's algorithms I can't use in Java which I can use in .NET/Rust/C++/etc without memory penalty or lots of unsafe/hacky code.

15. zulban ◴[] No.44433283{3}[source]
"Yeah but most of the time you learn a language because it changes your way of thinking."

For you and I maybe, but no. This is the HN bubble speaking. Most people learn a programming language to get a job or to do something they want to do.

I learn CS for fun too but I hold no illusions about the rest of the world.

"But decided against since Java had an ecosystem, tooling and really good performance."

Correct. Ocaml is not practical for projects or businesses. That's why you didn't pick it.