News for hackers. Stuff that matters.
Re:OCaml at First Glance by acjohnson55 on Monday August 29, 2022 @09:36AM (#32638049)
My biggest frustration with OCaml is having to deal with all of that cruft. I've learned many languages over the years, and I think I've just reached the point where I've lost patience with having to deal with what I would consider substandard syntactic elegance.
Re:OCaml at First Glance by tialaramex on Monday August 29, 2022 @09:53AM (#32638265)
This sort of thing is why Rust's Editions are great and why Vittorio Romeo's Epochs (P1881) for C++ would have been the right choice.

I like Editions because of the cultural consequences, Rust's community assumes they can fix things and so they set out with that goal, even in cases where Editions won't quite do it - while the C++ community tends to accept the state of the language as a static fact and just "take it". But this sort of thing isn't about the cultural effects, it's a direct technical achievement.

If OCaml had Editions, it could say OK, that syntax was a bit rubbish, here's 2023 syntax which fixes two things everybody hated, get back to us over the next few years and we'll decide if there are further changes needed. Without losing all existing OCaml software or demanding expensive rewrites.

Even better, changes of the sort in Editions are mechanical. It can take a bit of creative work to do it nicely but the transformations can be automated, so people who have "old OCaml" and wish they had "new OCaml" can push a button and get on with their day. Having both this and the feature which keeps old code working unchanged, add up to an experience where the community can move forward, on syntax at least, and not be trapped with yesterday's mistakes.

Re:OCaml at First Glance by zumu on Monday August 29, 2022 @09:58AM (#32638313)
The syntax is a little unorthodox, but just having a literal syntax _at all_ for things like lists/arrays beats having to call `new` on some random class you have to import and then doing a bunch of in place updates to add all the data.
Re:OCaml at First Glance by dmitriid on Monday August 29, 2022 @11:13AM (#32639259)
In this respect C# has knocked it out of the park with shorthand initialisation syntax for arrays and objects. But it's newer and could look at what other languages are doing/not doing in that regard.
Re:OCaml at First Glance by cardanome on Monday August 29, 2022 @10:10AM (#32638471)
I don't mind the cruft. I think a bit of harmless quirks can give a language character.

It actually makes the learning easier. Now that I know the story why, I have memorized how elements are seperated in OCaml for probably the rest of my life. I just need to remember the story.

Plus not reusing symbols for multiple syntactic purposes actually fits nicely into the general Ocaml philosophy. Plus is makes my complexity-hating, minimalist heart happy.

Though I am at that point in my life where I don't really care about syntax that much to begin with. Yes syntactic complexity matters. How fast it can be parsed, how easy macros are implemented, these things can matter but the actual syntax: boring. White-space sensitive or not, curly braces or begin/end and all that stuff is so dull. I am happy with whatever.

Re:OCaml at First Glance by p4bl0 on Monday August 29, 2022 @09:51AM (#32638234)
If using semicolons instead of commas is enough of a showstopper for you it's probably that you just don't have a need for the language :).
Re:OCaml at First Glance by acjohnson55 on Monday August 29, 2022 @09:23PM (#32645656)
Honestly, I'd argue that few people do. At a previous employer, we used it in situations where would have been much better off with a more mainstream language, in my opinion.

Of course, there are few situations that require any particular language.

Re:OCaml at First Glance by p4bl0 on Tuesday August 30, 2022 @04:13AM (#32647900)
Of course. But for example if you are writing a compiler, an interpreter, or anything that has to manipulate something that resembles a structured tree of meaningful data, OCaml is particularly well suited :).
Re:OCaml at First Glance by int_19h on Thursday September 01, 2022 @01:07AM (#32672238)
Any language with ADTs and pattern matching is reasonably suited for that task, and unlike 20 years ago, these aren't obscure features anymore, so there are many options.
Re:OCaml at First Glance by WastingMyTime89 on Monday August 29, 2022 @01:59PM (#32641334)
Yes but OCaml syntax is Pascal inspired. It’s always going to be a lot more elegant that anything inspired by the horror that is the B syntax. It’s just less familiar to people who grew up using C, Java or JavaScript.
Re:OCaml at First Glance by yawaramin on Tuesday August 30, 2022 @11:52AM (#32651834)
One man's 'cruft' and 'substandard syntactic elegance' is another man's 'decades of backwards-compatibility preserved'.

People are of course free to use the newest languages with the shiniest syntax (and many do), it's just that they pay the price by using untested, unproven languages when they could have been using ones which have been battle-tested in production for literally decades.

Re:OCaml at First Glance by toolslive on Monday August 29, 2022 @09:46AM (#32638172)
what's your stance on the curly braces (which is also a consequence of early parser technology) ?
Re:OCaml at First Glance by galangalalgol on Monday August 29, 2022 @10:14AM (#32638518)
What are some good alternatives? I don't find begin and end as easy to spot at a glance if the indentation is off. I'm not sure why I don't like indentation based, but I don't in practice. A good IDE helps me care less, and I don't think I could write python well without a good IDE anyway.
Re:OCaml at First Glance by acjohnson55 on Monday August 29, 2022 @02:52PM (#32641996)
I think they're often helpful for reading, but I admire what Scala did in Scala 3 to eliminate their necessity.
Re:OCaml at First Glance by yawaramin on Monday August 29, 2022 @03:45PM (#32642637)
Scala 3 actually doesn't really eliminate braces in any meaningful way. Sure, they're optional for delimiting traits, classes, and objects. But braces are heavily used for block scoping in Scala too. E.g. a very common pattern:

    retry(Seq(1.second, 2.second, 3.second)) {
      // some action that can fail
    }
This still requires the braces as of right now. I think the syntax changes will just confuse more people than it helps, at least for the time being.
Re:OCaml at First Glance by AzzieElbab on Monday August 29, 2022 @04:40PM (#32643279)
That is a curried parameter in {}. Those braces are not for scoping. They basically define a lambda. You can probably use () instead

you can also use import language.experimental.fewerBraces with nightly builds to write code like this

List(1,2,3).map: c => ...

Re:OCaml at First Glance by yawaramin on Tuesday August 30, 2022 @11:55AM (#32651866)
The braces here absolutely denote a new scope. You can't bind vals inside parentheses, for example. You can inside braces.

> You can probably use () instead

I would rather not as using braces for the final argument has been the Scala idiom for a long time now.

Re:OCaml at First Glance by AzzieElbab on Tuesday August 30, 2022 @10:10PM (#32657542)
I see your point. However you don’t have to define that thunk inline. You can write it separately and just pass it by name retry(…)(thunk). Not sure what signature of the retry method looks like.
Re:OCaml at First Glance by yawaramin on Wednesday August 31, 2022 @09:30AM (#32661825)
You can define it separately but it's often not the idiom. Especially for call-by-name arguments like in this case:

    def retry[A](backoffSeconds: Seq[Int])(action: => A): A
In this case you can't just define a 'val action = ...' because you don't want it to be run immediately, you want to run it inside the 'retry' method only. You could define it as a 'def' but then you're just introducing two different delayed evaluation concepts into this small piece of code. The cleanest way is to just directly pass in the action and Scala ensures it is delayed evaluation thanks to the CBN parameter type:

   retry(Seq(1, 2, 3)) {
     println("Trying")
   }