3 ms·
I really wanted to settle on OCaml as the "real programming language" that I would learn for any "serious programming" I had to do. I couldn't make it stick (in
by girzel 5y ago
I really wanted to settle on OCaml as the "real programming language" that I would learn for any "serious programming" I had to do. I couldn't make it stick (in part because I don't actually do any "serious programming") precisely because of the syntax.
There's too little of it! OCaml seems to take a "you don't need syntax except when you need syntax" approach, which I found very destabilizing. One of the major online OCaml tutorials said something like "If it doesn't work the way you expect, try adding parentheses", and I thought "Oh hell no. In a Lisp I know exactly how many parentheses I need: all of them". I prefer not having to think about it, and letting the parentheses become invisible to me.
But otherwise I have a deep and irrational fondness for the language, and still wish I'd been able to make it stick.
- Zababa 5y ago> One of the major online OCaml tutorials said something like "If it doesn't work the way you expect, try adding parentheses" That sounds like what I did with C++ with * and & when I didn't understood them. Do you think it's a lack of exprience/comprehension on your part, or that some parts of the syntax are fundamentally flawed?
- girzel 5y agoWell anything can be chalked up to lack of experience -- I'm sure if I was programming OCaml every day it wouldn't be an issue. Nor would I try to categorically claim the syntax is flawed! But so much of the syntax, particularly around function calls, is simply a long row of whitespace-separated tokens, and I feel like my brain has to do extra work to parse what's what, and figure out associativity, and constantly remember what the ~ and the ? are doing. This[1] section of the tutorial makes perfect sense when you read it, but that doesn't mean you can easily scan a long function call with a lot of arguments, and instantly see what's happening. The block-level syntax is great. But it got to the point where if I didn't write/read OCaml for a few days in a row, I forgot how it worked. And that's simply calling a function, nothing esoteric. [1]: https://ocaml.org/learn/tutorials/labels.html#When-and-when-not-to-use-and https://ocaml.org/learn/tutorials/labels.html#When-and-when-...
- Zababa 5y agoTo quote the tutorial you linked: > The syntax for labels and optional arguments is confusing, and you may often wonder when to use ~foo, when to use ?foo and when to use plain foo. It's something of a black art which takes practice to get right. So I don't think it's just you.
- johnisgood 5y agoLabels and labeled optional arguments, they were pretty straightforward to me when I was a newbie. I came from C. OCaml was the type of language in which I just wrote something and it worked on the first, or at worst on the second try without even having to look up the syntax. I would never be able to read Haskell, for what it is worth, even though in OCaml I mix imperative, functional, and OO; I use whichever makes the most sense. In a project I typically use all three.
- vphantom 5y agoOn parentheses, this is one of the main reasons why I integrated ocamlformat with my editor: I write explicit parentheses around everything and I let the formatter remove the superfluous ones. No surprises or guesswork that way.