Live data from Hacker News

OCaml Syntax Sucks (2016)

xahlee.info

91–100 of 140 posts

Re: OCaml Syntax Sucks (2016)

#91

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 feel the opposite—the typing ergonomics are better with a lower-punctuation language, but the reading ergonomics are substantially worse.

Punctuation is used in written human languages to provide assistance to our brain-parsers—like road signs that help navigate a sentence. Too much punctuation and it becomes a huge problem because it ceases to be meaningful, but have you ever tried reading a Roman inscription written with no spaces or sentence boundaries?

I think programming language punctuation serves the same role—it visually marks out how the parser is going to navigate the code, allowing the reader to use less mental effort repursing code that they initially misparsed. ML-style languages have a simpler syntax than the C family, which means there is some justification for having less assistive punctuation, but I've definitely struggled to navigate OCaml as a result of too little punctuation.

Re: OCaml Syntax Sucks (2016)

#92

Earlier quoted context omitted.

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 a…

> 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.

In other languages, modern IDEs take care of that. For an invocation like `addNumbers(1, 2)`, you would perform code completion after typing “aN”, and the IDE would already fill in matching function arguments from the current scope. The selection (cursor) would be highlighting the first argument, so you can readily replace it. Pressing Tab would move to the next argument. Pressing Enter (or similar) would accept the call expression in the current state and move the cursor behind it. So you only type the actual arguments (if necessary) and otherwise just hit combinations of Tab and Enter, or Ctrl+Space for code completion. You generally don’t type the parentheses or commas yourself.

That being said, I’m in favor of languages with not too much punctuation. But there’s a balance, and too little punctuation can also hurt readability.

Re: OCaml Syntax Sucks (2016)

#93
post #68
post #52

Earlier quoted context omitted.

> 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.

n-arity functions are also constants. 0 is not a special case there. Their behaviour won't change depending on the context from which you call them. A large part of FP is that functions _are_ values.

Re: OCaml Syntax Sucks (2016)

#94
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…

> The title is a little inflammatory.

Xah Lee is not exactly known for moderation. If you’re not familiar, browsing the site may be worth your while. It’s full of inflammatory and sometimes bizarre takes, but I’d be hard pressed to argue that it’s ill informed.

Re: OCaml Syntax Sucks (2016)

#95
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…

> leading people to mess up nested matches frequently. Very often this leads to typing errors. Otherwise it's caught by autoformat (which everyone should be using). But even without that, this is one pitfall every OCaml developer is aware of. I'm not arguing the syntax is perfect, but I wouldn't say it has a serious problem because of that. Never seen that being a problem.

Keyboards are also extremely error-prone. I can't count the times where I mistyped because of that. After each keystroke, people should type a "confirm" character in order to make sure of what they're doing.

Re: OCaml Syntax Sucks (2016)

#96
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…

> The title is a little inflammatory. Xah Lee is not exactly known for moderation. If you’re not familiar, browsing the site may be worth your while. It’s full of inflammatory and sometimes bizarre takes, but I’d be hard pressed to argue that it’s ill informed.

> If you’re not familiar, browsing the site may be worth your while

Not inclined to do this though, his site doesn't exactly seem easy to browse either. Maybe a reflection of his bizarre takes?

Do you have some examples of well-informed articles by him? I found one about "syntax vs semantics" that seems as inflammatory and ill-informed as TFA under discussion here. I'm not inclined to give this person much leniency...

Re: OCaml Syntax Sucks (2016)

#97
post #12
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…

Fortunately, the OCaml compiler is very modular, and there have been efforts to make things more... reasonable. - Reason, a different syntactic frontend for regular OCaml: https://reasonml.github.io/ - ReScript, a language with OCaml semantics that compiles into: JS https://rescript-lang.org/ (I suppose it's a reincarnation of js-of-ocaml).

Worth nothing that the former lead dev of ReScript left to create a WASM-first language call Moonbit (https://www.moonbitlang.com/). The language design is awesome and corrects a lot of the corners that they just couldn't get around in OCAML. A touch early, but really well done.

Re: OCaml Syntax Sucks (2016)

#98

Earlier quoted context omitted.

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 a…

Tangentially there is room for optimizing for non-american keyboards. The accent grave (backtick) you're using in a Markdown-inspired way is utterly annoying to type on keyboards where accents are implemented as dead keys, to be combined with vowels, common on european keyboard layouts. For your example I had to type `, but then look ahead to the a of add_numbers and remember to put in an extra space, so that the ` a…

> The accent grave (backtick) you're using in a Markdown-inspired way is utterly annoying to type on keyboards where accents are implemented as dead keys, to be combined with vowels, common on european keyboard layouts. … Also I find it somewhat illogical: The usage of an accent as a character in itself in programming languages is one of my pet peeves. Just being an ASCII character is not reason good enough to keep using it.

I understand that keyboards behave as they behave, and saying that "well they shouldn't" isn't a real answer. But I also think that it's not true that the backtick character is an accent grave, even if it is treated like one, any more than any other pair of Unicode homoglyphs are the same.

Re: OCaml Syntax Sucks (2016)

#99
post #55

Earlier quoted context omitted.

> something like Golang's concurrency That's wildly overselling it. Closure core async was completely incapable of doing the one extremely important innovation that made goroutines powerful: blocking.

Assuming "blocking" refers to parking goroutines, then blocking is possible. (let [c (chan)] ;; creates channel that is parked forever (go ( The Go translation is as follows. c := make(chan interface{}) // creates goroutine that is parked forever go func() {

No, blocking refers to calling a function that blocks. Core.async can't handle that because macros are actually not capable of handling that, you need support from the runtime.

Call a function that blocks in go, the routine will park. Do that in Clojure and the whole thing stalls.

Re: OCaml Syntax Sucks (2016)

#100

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

Yep. Datatypes, helper functions, and then the good stuff. In every file. It is actually beautiful and easy.
Post reply on HN