Live data from Hacker News

My thoughts on OCaml

osa1.net

11–20 of 230 posts

Re: My thoughts on OCaml

#11
post #3

Why would a company use ocaml? I’ve worked in software now for most of my life, from small to the biggest companies. I’ve watched teams with senior developers use non mainstream languages to build services and just about every time those devs get board again, leave the team, leaving them stuck with this system that’s hard to develop and different from the rest of the orgs, eventually resulting in a complete rewrite.…

I'm sure some companies out there might find a competitive advantage for using exotic languages and tech stacks.

But I get the impression the more common scenario is that the engineers were bored and given the chance, wanted to play with something new and shiny.

It also depends on the company's prestige. A company like Jane Street using OCaml? Considering both their prestige and the amount they pay, I'm sure they will have no problems hiring. Nor will their alumni have problems getting hired elsewhere.

Some no name startup or even some "innovation lab" inside a boring cludgy Fortune500? Yeah, no thanks.

Re: My thoughts on OCaml

#12
I think you should give F# a shot instead.

1. No standard and easy way of implementing interfaces

No problem in F#, you have interfaces, abstract classed, ...

2. Bad standard library

In F# you have access to the full .NET standard library and ecosystem. There are also quite a lot of libraries that are especially designed to take advantage of F# (SQL libs for example).

3. Syntax problems

3.1 OCaml doesn’t have a single-line comment syntax.

It's `//` for single line and `(* comment *)` for n line comments in F#.

3.2 It has for and while, but no break and continue. So you use exceptions with a try inside the loop for continue, and outside for break.

Same in F#, use recursion.

Generally F# solves some of the issues but definitely not all of them. Some are just in the nature of the Standard ML syntax I guess.

4. Rest of the package is also not that good

- NuGet is a decent/good package manager. - Easy to install a complete dev env. - sane build system (MSBuild) - Great out of the box support in JetBrains Rider/ Visual Studio (for Mac/ Windows) or via a VS Code plugin (Ionide).

Re: My thoughts on OCaml

#13
The last paragraph show this article for what is is. That's an Haskell fan trying to discredit Ocaml and doing it very poorly.

It takes a special kind of writer to write an incorrect sentence about the expression syntax while quoting the actual definition from the specification which contradicts what's written just after.

I generally disagree about the complaint regarding the syntax. If you indent the code properly and use parentheses as you should and the language invites you to do, none of this is ambiguous. That's bad code not bad language design.

Re: My thoughts on OCaml

#15
> Another example is the sequencing syntax ; and productions with as the right-most symbol:

    let test1 b =
      if b then
        print_string "1"
      else
        print_string "2"; print_string "3"
> Here print_string "3" is not a part of the if expression, so this function always prints “3”.

Well, yeah. Here's the equivalent Java code:

    void test1(bool b) {
        if (b) print_string("1");
        else print_string("2");
        print_string("3");
    }
You've chosen to use a single-statement "else" form _without_ "bracketing" it with `begin` and `end`:

    let test1 b =
        if b then
            print_string "1"
        else begin
            print_string "2";
            print_string "3"
        end
...which is equivalent to this Java code, where you _also_ would have to "bracket" the else-block:

    void test1(bool b) {
        if (b) print_string("1");
        else {
            print_string("2");
            print_string("3");
        }
    }
You could argue that Java (and C, and C++, and Javascript, and...) has the same "ambiguous parsing problem", then -- except that it doesn't, and the author is just thrown off by `begin`/`end` as block delimiters instead of curly braces, which might be a sign that they've also never seen Ruby before, or Elixir, or Pascal, or....

Re: My thoughts on OCaml

#16
post #3

Why would a company use ocaml? I’ve worked in software now for most of my life, from small to the biggest companies. I’ve watched teams with senior developers use non mainstream languages to build services and just about every time those devs get board again, leave the team, leaving them stuck with this system that’s hard to develop and different from the rest of the orgs, eventually resulting in a complete rewrite.…

MirageOS and microkernels.

Re: My thoughts on OCaml

#17
post #8

[flagged]

Yeah, I'm not sure I understand the author's complaint. OCaml has modules, associated types, anonymous modules, GADTs, polymorphic variants, and row polymorphism. All of which are kind of like interfaces.

As far as I can tell, the complaint is maybe that ocaml doesn't have something exactly like C#/Java interfaces (which I think is a fair assessment). So maybe the author is lamenting that they can't just rewrite their java code in every language?

Although, they also mention rust traits. Which at first blush look very similar to c#/java interfaces (at least closer than anything ocaml has). However, at least in my experience, rust traits don't quite fulfill the same niche as c#/java interfaces because rust cares a lot about when you can figure out the size of your objects. So every time I tried to use them like I would a C# interface, I wound up regretting the decision.

Ultimately, this article feels like a superficial "I don't like ocaml" blurb. There is a lot to be warry of with respect to ocaml. Although, the fact that ocaml still exists as a niche language with a lot of very significant maintenance and active development (effects + multithread recently landed), shows that the author did not pay sufficient attention.

Re: My thoughts on OCaml

#18
ReasonML and ReScript are a (more or less the same) new syntax on top of OCaml. ReScript only targets JS, while ReasonML targets both JS and the native archs OCaml supports. Facebook and Bloomberg are using ReScript internally, afaik. Messenger.com is written in it. Facebook also maintains React bindings to ReScript.

https://rescript-lang.org/

https://reasonml.github.io/

Re: My thoughts on OCaml

#19
1. To print values, nowadays you just derive pretty printers automatically.

2. Syntax? yes, it's not C-like... you'll get used to it in a few days.

3. Lack of interface? would be helpful to see a concrete example of what the author finds limiting. You have modules, functors, includes, objects, first-order modules... Personally, I find that plain modules are simple and go a long way.

It's not perfect, but I find that nowadays Core/Dune/Opam/Merlin gives you a very decent developer experience.

Re: My thoughts on OCaml

#20
post #8

[flagged]

Someone mind explaining how these help? I'm unfamiliar with OCaml, but looking at the documentation of modules, I don't understand what they have to do with interfaces in the OOP sense(EDIT: or, rather, ad-hoc polymorphism), which I'm pretty sure is what the author meant.

The point as I understand is that interfaces in the OOP sense try to mimic what modules do. Therefore OCaml not having them is not a serious accusation since everything you try to accomplish with interfaces / design patters you can and should be able to do with modules. Here is the article explaining the concept: https://www.pathsensitive.com/2023/03/modules-matter-most-fo... but I have to note that I never worked in OCaml so this is just my theoretical understanding.
Post reply on HN