Live data from Hacker News

OCaml Syntax Sucks (2016)

xahlee.info

61–70 of 140 posts

Re: OCaml Syntax Sucks (2016)

#61

I 100% agree. The lack of clear scoping and function call grouping syntax just turns it into a word soup. It becomes difficult to parse for humans and I spend a stupid amount of time just getting the semicolons, begin/ends, etc. right. It's like... when you mismatch brackets or braces in a C-style language, except to resolve the problem you can't just find the bracket that's highlighted in red and count; you have to…

That can be indeed very confusing when you initially learn the language. However there are 3 things that can help:

* An auto-formatter (ocamlformat integration in your editor, or ocaml-top) that shows how the actual nesting looks like

* You can add ;; at the end of a top-level function to get a syntax error at a better location

* Use the LSP integration of your editor which will show you where the error is as you type, so you catch the problem early

Re: OCaml Syntax Sucks (2016)

#62

Worked on an ocaml codebase for two years. My advice is: choose a different language. It's just not a great dev experience in general

What were the main issues you came across? What language would you prefer if you had to start from scratch and had the choice to go with anything else?

Re: OCaml Syntax Sucks (2016)

#63

The more I used ocaml the more I found beauty in the syntax. It’s very ergonomic in many ways: 1. It’s whitespace insensitive, which means I can code something up really messy and the code formatted will automatically fix it up for me. 2. In general there aren’t a ton of punctuation characters that are very common, which is great for typing ergonomics. Don’t get me wrong, there are still a lot of symbols, but I feel…

2. In general there aren’t a ton of punctuation characters that are very common, which is great for typing ergonomics. Don’t get me wrong, there are still a lot of symbols, but I feel compared to some languages such as Rust, they’re used a lot less. I never really seen someone put that into words. I always feel a certain kind of weird when I look at a language with tons of punctuation (Typescript is good example).

I think typing ergonomics are overlooked as well. CSS has the most verbose syntax for variables I've had to use regularly e.g. `var(--primary-color)` which I find unpleasant to type when experimenting. And I actually like the lack of brackets and commas in OCaml for function e.g. you write `add_numbers 1 2` instead of `add_numbers(1, 2)`. Brackets and commas in particular require you to navigate left/right a lot to add them in the right place while iterating and give confusing errors when you get them wrong.

Would be curious if there's work into a programming language that was optimized for minimal typing while iterating.

Re: OCaml Syntax Sucks (2016)

#64
post #19

Earlier quoted context omitted.

You might like Scala. It has much of the good parts of OCaml or F#, but also lets you write imperative code freely when you want. The `for`/`yield` syntax for async is very nice IMO, or you can write Javascript-like promise chaining directly if you want.

Some interesting things happening in the structured concurrency / "Direct style" space. It looks like it could become a powerful and readable way to compose (asyncy type) things. Simpler code, usable stack traces, better traceability, less function colouring concerns. It's early days in that regard, with some folks doing some really interesting things: Odersky himself / the Ox project.

With OCaml 5 and effects it might be possible to use direct style, and rely on effect handlers to schedule IO. Here is an example of how structured concurrency in OCaml could look like https://ocaml.org/p/picos_std/latest/doc/Picos_std_structure...

Re: OCaml Syntax Sucks (2016)

#65
It's a strange take that a possibility to write unformatted code means syntax sucks.

I've read other articles and there is other weird stuff. Like Java has perfect syntax because on one line you could do so less. In the mean time modern "functional" (or "monadic") style java is a chained mess with ridiculously long lines.

Re: OCaml Syntax Sucks (2016)

#66
I've recently started a mini-project in OCaml, having some Haskell background.

The worst thing so far is that you have to declare and define functions before using them. This results in unimportant utility functions being at the top, and the most important functions being at the bottom of a file.

I haven't had much issue with let bindings, however that might be because my functions are fairly simple for now.

Re: OCaml Syntax Sucks (2016)

#67
post #56

I believe OCaml's syntax does suck, but I don’t think this article gives a compelling argument as to why. Missing an `in` turns a let expression into a top level binding and kicks a syntax error often a long way down the file, making it very hard to identify the cause. The relative precedence of let, if, match, fun, and the semicolon is unintuitive and hard to remember, making me want to add loads of unnecessary and…

If anything, OCaml's error messages are something that sucks, especially for newcomers. The `Error: Syntax Error` message that points to an empty last line in the file leaves you doing the parser work, in a language that you don't understand.

Re: OCaml Syntax Sucks (2016)

#68
post #52
post #9

The title is a little inflammatory. The critique is specifically about Ocaml’s handling of let-bindings. AFAICT OP thinks the syntax sucks because: 1. there’s no marker to indicate the end of let scopes 2. functions are bound with the same syntax as constants He asserts that this is confusing. In practice - for the many issues I have with Ocaml! - neither of these are actual issues, in my experience, once code format…

> functions are bound with the same syntax as constants Apparently, the author hasn't come around to understanding that functions are just another constant.

TBF he has such notion:

> because a 0 arity function without side-effect is just constant.

Re: OCaml Syntax Sucks (2016)

#69
post #65

It's a strange take that a possibility to write unformatted code means syntax sucks. I've read other articles and there is other weird stuff. Like Java has perfect syntax because on one line you could do so less. In the mean time modern "functional" (or "monadic") style java is a chained mess with ridiculously long lines.

> In the mean time modern "functional" (or "monadic") style java is a chained mess with ridiculously long lines.

I have seen many devs that prefer the Java imperative style over more functional chained style. Could be an outcome of leetcode style interviews or that most CS programs start with C/python/Java style languages but it's not uncommon to see that preference especially among junior devs

Re: OCaml Syntax Sucks (2016)

#70

I've recently started a mini-project in OCaml, having some Haskell background. The worst thing so far is that you have to declare and define functions before using them. This results in unimportant utility functions being at the top, and the most important functions being at the bottom of a file. I haven't had much issue with let bindings, however that might be because my functions are fairly simple for now.

I've always liked this - it follows the structure of a good academic essay
Post reply on HN