Live data from Hacker News

OCaml Syntax Sucks (2016)

xahlee.info

121–130 of 140 posts

Re: OCaml Syntax Sucks (2016)

#121

Another thing I personally hate about OCaml's syntax is the order of generic parameters being backwards. I know why it's like that, but it still doesn't make any sense to me both as a programmer and as a non-native english speaker.

It's definitely quirky in its inconsistency, but type 'a Tree = | Node of ('a Tree, 'a Tree) | Leaf of 'a Is saying "The possible cases for the type describing an 'a Tree are: a Node of two other 'a subtrees, or else a Leaf of an 'a." Then when you concrete-ize it, you have an "int Tree" or a "string Tree". This is a little clearer with thinking of the List datatype: this is a number list, that's a string list, that'…

> This is a little clearer with thinking of the List datatype: this is a number list, that's a string list, that's a grocery list, this is a guest list...etc.

That's what I was referring to when I said "as a non-native english speaker". In my native language I would say those in a way that's more similar to "a list of numbers", etc etc.

> One nice thing in F# is that there's an ability to "standardize" how you write generics to look more like the (admittedly arbitrary) way that C# or Java or C++ write them:

Arguably this order (type then generic arguments) is not that arbitrary because this is effectively a type level function, so it makes sense that it uses the same order. However the angle brackets are indeed arbitrary, and IMO to be more consistent the same syntax as function application should be used. For practical purposes though this may make a type's syntax too similar to an expression, so it may not be the best choice (unless you're in a language where types are actually values)

Re: OCaml Syntax Sucks (2016)

#122

Earlier quoted context omitted.

I feel like ReasonML should have the capacity to help bridge the gap for people learning ocaml if it weren't so hidden.

I wish they would update their blog![0] The last post is from Aug. 2018, which definitely gives the impression that the project is dead. But it's not dead, if you look at their GitHub.[1] [0] https://reasonml.github.io/blog/ [1] https://github.com/reasonml/reason

Shame on me; I have a few draft posts that never got the chance to publish. My non-native english doesn't fully help ^^

Expect some of them to be published at the end of the year or early january!

Re: OCaml Syntax Sucks (2016)

#123

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

Curious to know more, do you think can make a long-form of "why" and a detailed experience? If you have some time, would be massive to compare it with what's the same experience today

Re: OCaml Syntax Sucks (2016)

#124

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

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

Yeah I do have this set up and it's a very good LSP, but unfortunately frequently if you get the nesting wrong the error is like "the entire rest of the file is wrong". It's often not very helpful.

That's not unique to OCaml. C style syntaxes can give "everything after this point is an error" if you get brackets wrong, but it's much easier to figure out what you did wrong.

Re: OCaml Syntax Sucks (2016)

#125

Earlier quoted context omitted.

I wish they would update their blog![0] The last post is from Aug. 2018, which definitely gives the impression that the project is dead. But it's not dead, if you look at their GitHub.[1] [0] https://reasonml.github.io/blog/ [1] https://github.com/reasonml/reason

Shame on me; I have a few draft posts that never got the chance to publish. My non-native english doesn't fully help ^^ Expect some of them to be published at the end of the year or early january!

Glad to hear it!

Re: OCaml Syntax Sucks (2016)

#126
post #12

Earlier quoted context omitted.

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

It's not more reasonable. It explicitely designed to look like JS which is, well, bad. Some of the choices are extremely annoying and overall useless like reintroducing parentheses for function arguments. There is a reason - pun intended - it didn't take off at all with the community.

I recommend Fabble and F#, a language that went the correct course of programming evolution, from braces to indent, instead of the other way around :)

Re: OCaml Syntax Sucks (2016)

#127

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…

var(-- sounds like the person who writes the parser was either too lazy or sucks at his job so they asked the spec writer to give them a break.

Re: OCaml Syntax Sucks (2016)

#128

Earlier quoted context omitted.

> places users at risk Help me out here, what's the threat model here while reading troll programming blogs?

https://doesmysiteneedhttps.com/

You didn't answer my question.

What is the threat model?

Re: OCaml Syntax Sucks (2016)

#129

Another thing I personally hate about OCaml's syntax is the order of generic parameters being backwards. I know why it's like that, but it still doesn't make any sense to me both as a programmer and as a non-native english speaker.

I'm not even an ocaml dev and I prefer how it reads and types to that of C family generics.

Re: OCaml Syntax Sucks (2016)

#130

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…

I also feel an ick when I have to type or read punctuation like this:

    (x) => { ... }
The => and { are directly pointing at each other and it kinda irritates me. Feels non-aesthetic.
Post reply on HN