News for hackers. Stuff that matters.
Re:OCaml Programming: Correct and Efficient and Beautiful by sshine on Friday June 24, 2022 @07:04AM (#31860058)
I spent a lot of time on Standard ML in university.

OCaml was always portrayed as the engineer's alternative for real applications.

I spent some time brushing up on OCaml a few years ago using Exercism.io.

While OCaml is a personal "top tier" language, I'd always prefer Haskell, Rust or Scala.

Type classes / traits just seem to beat a higher-order module system for me.

Re:OCaml Programming: Correct and Efficient and Beautiful by cmrdporcupine on Friday June 24, 2022 @08:32AM (#31860805)
I learned SML/NJ and OCaml around the same time and for some reason I found SML more pleasant. I particularly liked the SML "Basis" library, it felt really well designed to me.

Still, I'd pick either over Scala. Superior compilation times, cleaner syntax, less complex. Haskell also just feels excessively clever.

I had hoped Rust would be "OCaml but for systems programming" and it sort of is, -- but the borrow checker and memory safety features, as neat as they are, add a lot of mental overhead.

Re:OCaml Programming: Correct and Efficient and Beautiful by frou_dh on Friday June 24, 2022 @11:14AM (#31863516)
SML definitely has a more tastefully designed syntax also, and not only because it's a smaller grammar. OCaml syntax is the "scuffed" version of SML syntax, as the kids say!

Unfortunately to be a real-world SML user these days is a very isolating proposition, because although there are some really nice implementations (MLton, PolyML), to a first approximation there are zero libraries.

Re:OCaml Programming: Correct and Efficient and Beautiful by xvilka on Friday June 24, 2022 @01:00PM (#31865670)
SML is the dead end because specification wasn't updated for decades.
Re:OCaml Programming: Correct and Efficient and Beautiful by hedora on Saturday June 25, 2022 @03:38AM (#31873331)
For me, the borrow checked removes a lot of mental overhead. It finds all sorts of subtle concurrency bugs in my code.
Re:OCaml Programming: Correct and Efficient and Beautiful by 3836293648 on Saturday June 25, 2022 @06:27PM (#31879255)
Depends on your starting point. More overhead than GC, most of the time, so much less than C/C++
Re:OCaml Programming: Correct and Efficient and Beautiful by xyproto on Friday June 24, 2022 @07:43AM (#31860337)
I also find it hard to spot why OCaml is the natural "step up" for creating real world applications instead of Haskell, Rust, Clojure or even Kotlin, C++, Python and Go.
Re:OCaml Programming: Correct and Efficient and Beautiful by toolslive on Friday June 24, 2022 @08:05AM (#31860521)
let's see:

    - OCaml vs Haskell: eager vs lazy  (=> memory consumption is more predictable)
    - OCaml vs Rust: OCaml has a GC (=> comfort) OCaml has tco (could not resist this ;) )
    - OCaml vs Clojure: vastly superior typing system. (=> less bugs)
    - OCaml vs Kotlin: no JVM needed.
    - OCaml vs C++: more safety. once it compiles it will not segv.
    - OCaml vs Go: vastly superior typing system. (=> less bugs)
    - OCaml vs Python: vastly superior type system, way better performance.
The biggest risk of doing OCaml (or Haskell or Rust) for extended periods of time is that you will be unable to hide your feeling of superiority towards (fe) a python developer.
Re:OCaml Programming: Correct and Efficient and Beautiful by contificate on Friday June 24, 2022 @08:53AM (#31861005)
I think the languages you selected in your final remark sum it up for me. If one is truly taken by functional programming, much of their mental model starts to revolve around algebraic (inductively defined) data types and structural recursion (aided by pattern matching) over them - such that mentally reducing the set of candidate languages really does become an implicit process of questioning: "does X have ergonomic, statically-typed, discriminated sums?".

Lots of mainstream languages simply fail this test and make it feel like intellectual poverty or that there's extreme, turgid, boilerplate required for a weak imitation of the features (see the idiomatic class-hierarchy encoding of ADTs in large projects - such as LLVM - in C++, for example).

It's absolutely no surprise that more mainstream languages are picking up a match-like construct and lighter encodings of discriminated sums. So, it really comes to what else you wish to be burdened with when compiling an OCaml-like mental model to X in your head: Tagged unions a-la C? Class hierarchies for ADTs in C++? The travesties of std::variant? Monad transformers in Haskell? Lazy evaluation? No static typing at all? Caring about memory management and ownership? Box and Arc-ing recursive components of ADTs? Writing your own arena allocator? Compiling to the JVM? Spotty TCO support?

OCaml is just a nice, fairly simple (at its core, at least), language that captures the essence of the ML family, compiles to native (and bytecode and, transitively, JavaScript), has great tooling (opam, dune, ocamllex, memhir, etc.), great libraries (official LLVM bindings, for example), and a great community. Lots of OCamlers are well aware of other potential languages that somewhat suit their style of programming, they just don't want to be burdened by the other stuff.

Re:OCaml Programming: Correct and Efficient and Beautiful by throwamon on Friday June 24, 2022 @08:51AM (#31860985)
> vastly superior typing system. (=> less bugs)

I have no horse in this race, but claiming it to be "vastly superior" and implying "less bugs" makes it sound like this is a logical consequence, when you're actually staying on one side of an endless debate that to me doesn't have clear winners. For instance, from the little I've learned about Clojure, they claim the lack of a "vastly superior type system" is a feature, not a bug, and it's a result of a fundamental difference in some beliefs about how to write correct software.

From this I wonder how misrepresentative your other comparisons are as well. But don't get me wrong, OCaml is probably my "favorite language I've never actually used" (I've never "actually used" Clojure in "real projects" either).

Re:OCaml Programming: Correct and Efficient and Beautiful by toolslive on Friday June 24, 2022 @09:07AM (#31861172)
Take any open source python project on github (or others) look at the list of issues and count the number of 'NoneType' has no attribute ... instances. All these could have been avoided by a decent type system. I rest my case ;)
Re:OCaml Programming: Correct and Efficient and Beautiful by tgflynn on Friday June 24, 2022 @09:48AM (#31861749)
I don't think I've ever seen anyone seriously argue against the claim that strong typing systems at least prevent many types of bugs. Now people may think that they are more productive in a language with weak types but that's a different consideration.
Re:OCaml Programming: Correct and Efficient and Beautiful by camgunz on Friday June 24, 2022 @11:16AM (#31863561)
This was on HN the other day: https://github.com/hwayne/awesome-cold-showers#static-vs-dyn.... I would probably add a caveat to the listed caveats that testing might not be considered? Like if every dynamically typed code base implements an ad-hoc typechecker with a testing framework, it's a distinction without a difference.
Re:OCaml Programming: Correct and Efficient and Beautiful by laserlight on Friday June 24, 2022 @01:32PM (#31866248)
I’ve passed wrong type of arguments to Python functions and assumed type of the return value wrong countless of times. That has never happened in Haskell. I don’t know how to reconcile my experience with the statement that there’s no evidence that strong typing reduces bugs.
Re:OCaml Programming: Correct and Efficient and Beautiful by camgunz on Friday June 24, 2022 @05:07PM (#31869316)
I program primarily in (untyped) Python (which, I get is technically strongly typed but people don't think in technical terms) these days, and I almost never experience type errors. I guess I could attribute this to a couple things:

- I'm very specific about when I use None

- I'm a big fan of named function arguments

- I like to think my naming of things is pretty good, as are my conventions for parameters

- I try to handle all possible cases (what I mean here is I do and if I don't I made a mistake)

I use tests very sparingly in personal projects, but yet I haven't really felt their absence. If I ever write a piece of particularly hairy code (metaprogramming comes to mind... lord) I'll write a quick script testing some cases and then delete it.

Anyway, all that is to say I think part of dynamic programming is you build an immune system for this stuff.

Re:OCaml Programming: Correct and Efficient and Beautiful by hedora on Saturday June 25, 2022 @03:46AM (#31873352)
Python is OK for throwaway code, but I've mostly seen it used for big systems that people (for whatever reason) didn't think were important enough to write in a real language. The people with that opinion don't share your degree of rigor.

I usually avoid bugs in python code by rewriting in bash (at 1-10% the size of the original python, since bash's error handling can be set to "always do the right thing" with "set euxo pipefail")

If bash is a bad fit for the rewrite, go usually works. I don't work on linear algebra software much these days. Python seems to be a good option for that.

Re:OCaml Programming: Correct and Efficient and Beautiful by camgunz on Saturday June 25, 2022 @12:39PM (#31876660)
Yeah I love Python for quick work and prototyping, and it's great for small web services and as a DSL for data analysis. I suppose I could also envision it as a backend language for a fleet of microservices too.

I think Python gets bailed out a lot because those things turn out to be a lot of programming these days. The people who have a beef w/ Python are those who've worked with it on large, old codebases. This is a tough job for any language though like, raise your hand if you've ever worked on a large, old codebase in C++ or Java that you liked.

Usually when people push microservices I'm quick with Conway's law, saying "this is a tech solution to an organizational problem that won't actually make a difference", and I think I'm right about that. But I think I've been ignoring that a really nice thing about microservices for engineers is you can keep using languages like Python on small codebases, and at least mentally and emotionally avoid the feeling of working on a huge monolith. That counts for something.

Re:OCaml Programming: Correct and Efficient and Beautiful by laserlight on Saturday June 25, 2022 @03:19AM (#31873258)
I’ve similarly developed my own habits. But why spend our effort into developing habits, when we can address the problems across people --- junior and senior --- automatically with a type system.
Re:OCaml Programming: Correct and Efficient and Beautiful by camgunz on Saturday June 25, 2022 @12:33PM (#31876610)
Oh 100% agree. The problem I've run into is my habits aren't others' habits, so we burn time arguing about how best to $CODE, and I rarely walk away from those satisfied or more educated (I'm sure this feeling is mutual haha). I wonder if "immune system" is to "type system" as "my special formatting" is to "use a formatter" here.
Re:OCaml Programming: Correct and Efficient and Beautiful by pharmakom on Friday June 24, 2022 @06:17PM (#31870179)
I think the big win is actually immutable data and pure functions. It just so happens that strong typing tends to come along with these things (e.g. Haskell, OCaml)
Re:OCaml Programming: Correct and Efficient and Beautiful by phyrex on Saturday June 25, 2022 @09:05AM (#31874971)
Clojure is the big outlier
Re:OCaml Programming: Correct and Efficient and Beautiful by fulafel on Saturday June 25, 2022 @01:29PM (#31877040)
And Erlang / Elixir. These are also some of the most widely used FP languages in delivering real world software.
Re:OCaml Programming: Correct and Efficient and Beautiful by water8 on Friday June 24, 2022 @08:29AM (#31860768)
OCaml vs All: Good luck finding developers that will write quality code and not cost a fortune each.
Re:OCaml Programming: Correct and Efficient and Beautiful by yawaramin on Friday June 24, 2022 @12:59PM (#31865660)
If Jane Street can teach OCaml to traders, I can teach it to developers. That's not a concern for anyone other than a sweatshop.
Re:OCaml Programming: Correct and Efficient and Beautiful by akhmatova on Friday June 24, 2022 @02:31PM (#31867259)
If Jane Street can teach OCaml to traders, I can teach it to developers.

You can if they are motivated to learn. Unless you are offering Jane Street levels of compensation; and in return, the candidate is willing to believe, or pretend to believe that company's shtick about OCaml being so categorically superior as a general-purpose development language so as to leave all the others in the dust -- most likely they won't be.

Re:OCaml Programming: Correct and Efficient and Beautiful by yawaramin on Friday June 24, 2022 @05:21PM (#31869481)
Or if, you know, they were hired to work on a project where they get paid a salary. That seems to incentivize most devs.
Re:OCaml Programming: Correct and Efficient and Beautiful by akhmatova on Friday June 24, 2022 @06:43PM (#31870438)
Not "a salary", but a Jane Street salary and resume cred. Otherwise you just won't find that many takers.
Re:OCaml Programming: Correct and Efficient and Beautiful by yawaramin on Friday June 24, 2022 @07:11PM (#31870690)
I can assure you I will and in fact have found plenty of takers for my job postings with a niche language. You just need to word the postings appropriately and be willing to teach people what they don't know.
Re:OCaml Programming: Correct and Efficient and Beautiful by akhmatova on Saturday June 25, 2022 @07:09AM (#31874278)
You just need to word the postings appropriately and be willing to teach people what they don't know.

OK, I'll grant that if you have that "magic skill" then you can in fact recruit developers for niche languages.

Most companies don't, as we know, and frankly it's amazing to me how incoherent their communications are throughout their so-called hiring process.

Re:OCaml Programming: Correct and Efficient and Beautiful by yawaramin on Saturday June 25, 2022 @08:23PM (#31879888)
If having sensible hiring practices is a 'magic skill', then I guess call me Harry Houdini!
Re:OCaml Programming: Correct and Efficient and Beautiful by akhmatova on Monday June 27, 2022 @11:15PM (#31903690)
Per this person's experience (which seems sadly far from atypical), you might as well be:

https://www.benjamistan.tech/2022/06/26/wasting-time-in-tech...

Re:OCaml Programming: Correct and Efficient and Beautiful by toolslive on Friday June 24, 2022 @02:48PM (#31867548)
Actually, what I found more impressive is that they also got them to use emacs.
Re:OCaml Programming: Correct and Efficient and Beautiful by AlexanderNull on Friday June 24, 2022 @07:12PM (#31870695)
Good luck finding high quality cheap developers in any language really. Very few good developers are language specific so unless your HM is an idiot and actively screens out candidates without 10 years of previous experience in the specific framework you're using it won't be a limitation. If you want quality developers you need to offer either 1) lots of money, 2) amazing benefits, 3) interesting problems to work on. For many, an interesting language can provide an edge. I chose my current company because I would be working on Scala here as opposed to Java with the other offers I had. The quality of life improvement of the Scala position was enough to take it over the prospect of writing AbstractFactoryBeanImpl for the next few years.
Re:OCaml Programming: Correct and Efficient and Beautiful by wiseowise on Saturday June 25, 2022 @02:50AM (#31873142)
> Good luck finding developers that will write quality code and not cost a fortune each.

You pick one regardless of language. Not sure what's your point here.

Re:OCaml Programming: Correct and Efficient and Beautiful by akhmatova on Friday June 24, 2022 @08:34AM (#31860826)
It's not getting things done that matters. It's feeling superior to others that matters.
Re:OCaml Programming: Correct and Efficient and Beautiful by shikoba on Friday June 24, 2022 @09:13AM (#31861233)
Hey, it's not a feeling. It's a fact.
Re:OCaml Programming: Correct and Efficient and Beautiful by hutzlibu on Friday June 24, 2022 @11:40AM (#31863923)
It is certainly a fact, that you feel superior.

I would like to confirm that fact, by comparing productive output..

Re:OCaml Programming: Correct and Efficient and Beautiful by wiseowise on Friday June 24, 2022 @01:17PM (#31865980)
Define "productive output".
Re:OCaml Programming: Correct and Efficient and Beautiful by hutzlibu on Saturday June 25, 2022 @06:37AM (#31874111)
Producing code, that primarily solves the real world problem (not aesthetic ones).
Re:OCaml Programming: Correct and Efficient and Beautiful by yawaramin on Saturday June 25, 2022 @08:56PM (#31880058)
What kind of code? People who want to solve real-world problems treat programming languages like tools in their toolbox. In the past week at work I wrote Scala, HTML, JavaScript, YAML, and Terraform. I also remove tons of code from my production systems whenever I get the chance as it solves a real-world problem for me (maintainability of the code base).

'Producing code' to measure 'superiority' is about as useful a metric as counting lines of code to measure productivity.

Re:OCaml Programming: Correct and Efficient and Beautiful by twh270 on Friday June 24, 2022 @10:00AM (#31861918)
Not sure what you mean by "- OCaml vs Kotlin: no JVM needed." as Kotlin has support for native and JavaScript compilation, and WASM via native.
Re:OCaml Programming: Correct and Efficient and Beautiful by pjmlp on Friday June 24, 2022 @11:44AM (#31864005)
Kotlin has a crude support for native, and they had to reboot the implementation as they got clever and went with a memory model incompatible with JVM and JS GCs, thus making code portability an headache.
Re:OCaml Programming: Correct and Efficient and Beautiful by thayne on Friday June 24, 2022 @10:53AM (#31863020)
Maybe it's changed in the year or so since I looked at kotlin, but my impression when I did look at it was support for anything other than the JVM was definitely second class
Re:OCaml Programming: Correct and Efficient and Beautiful by wiseowise on Friday June 24, 2022 @01:26PM (#31866126)
Did you even try it? It still requires Java, Gradle and Kotlin compiler to work. Also, good luck making it work without using Intellij.
Re:OCaml Programming: Correct and Efficient and Beautiful by toolslive on Friday June 24, 2022 @10:56AM (#31863094)
so it's either a JVM or either no libraries?
Re:OCaml Programming: Correct and Efficient and Beautiful by Akronymus on Friday June 24, 2022 @09:55PM (#31871729)
What about ocaml vs f#?
Re:OCaml Programming: Correct and Efficient and Beautiful by frizlab on Friday June 24, 2022 @08:12AM (#31860596)
What about Swift?
Re:OCaml Programming: Correct and Efficient and Beautiful by Zababa on Friday June 24, 2022 @01:34PM (#31866273)
On the server, less ecosystem than OCaml. Long compile times. A big part of its "market share" is taken by Rust instead.
Re:OCaml Programming: Correct and Efficient and Beautiful by KurtMueller on Friday June 24, 2022 @08:50AM (#31860970)
For now, a good language if you want to develop apps for the mac ecosystem.