The way ocamlformat formats

If you’re an emacs user, it’s a problem. One wants one’s formatting to be done automatically inside the editor as one types. That also detaches one from formatting considerations, btw. I don’t think about how to format my OCaml code either. Most people, I think, use such tools at this point.

I am an Emacs user but I save often :wink:

Let me again be direct. If you want to persuade people to use a tool that they aren’t interested in and that they think does things they don’t want, telling them things like “you’ll get used to it” and “there’s a way you can work with it that’s only modestly inconvenient” is going to drive people further way, not persuade people.

Imagine if you had a restaurant, and you tried to lure diners in with “after a few months of eating here regularly, you’ll get used to our food!” and “the chairs aren’t nearly as uncomfortable as you might initially expect, and by bringing a cushion with you when you come here, you can get things to the point where you barely notice that.” Sadly for you as the restaurateur, your customers have to want to eat there, and such talk doesn’t make them have the least interest. Maybe this wouldn’t be the worst approach if your customers were forced somehow to use your services, but as they have a choice, you’re not going to win this way.

2 Likes

When ocp-indent has been released a few years ago, everyone was complaining because the indentation style was different from what they used to apply in their code. Exactly like everyone is complaining in this thread about ocamlformat’s style. It has been (and is still) not easy to convince people to run ocp-indent on their whole codebase to have something coherent.

ocp-indent doesn’t satisfy the community standard. It created a new standard that replaced the default emacs indentation scheme. And basically no-one is using the configuration options of ocp-indent.

So yes, pushing ocamlformat to adopt a style that is common will maybe help in the very short term. With old ocaml developers that don’t want to change their style. Newcomers are already happy with ocamlformat. But it doesn’t worth fighting on this common style too long. In the long term, people will get used to the defaults and be happy with them. Or they won’t be happy and won’t use ocamlformat. Same as what happen with ocp-indent.

refmt has the same issue btw. It is opiniated and produces horrible code sometimes. It even used to drop some {} and make the developers life troublesome. None of those issues have been blocking its adoption by the reason community.

1 Like

Do you have a source for that? I certainly use ocp-indent’s configuration, for otherwise I’d dislike its style. I would expect the same level of configuration from ocamlformat, without it adding or removing ( around then/else or similar changes, before I considering using it.

3 Likes

No source except my experience looking at and modifying libs that are on opam. Sure there are some users. JSC has its style too. But I dont often see ocp-indent configuration file.

And some of the most painful sticking points were changed and various configuration option added, in order to ease adoption, before it gained more mainstream usage in the community. :slight_smile:

I don’t even understand why the ocamlformat people insist on fighting that battle.

4 Likes

Is there a battle being fought? A lot of configuration options have been added to ocamlformat from the PRs I’ve seen. There are a lot of code formatting options already listed here and a PR mentioned above by @gpetiot to change one of the biggest complaints listed here about putting separator punctuation first on a line.

1 Like

FWIW I use an .ocp-indent file in all my projects (personal and work) with just two tweaks:

match_clause = 4
max_indent = 2

(full, commented version here)

These two settings and the accompanying comments were copied from an example in the ocp-indent project itself.

The whole ocp-indent experience has been frictionless.

3 Likes

Nope.

This total OCaml newcomer tried both tools and liked the defaults of ocp-indent immediately while gasping in horror upon seeing what ocamlformat did to their code.

I’m absolutely fresh here and don’t know all nuances of course. But IMO the authors and fans of ocamlformat defaults should just admit “that’s how we like it” and not pretend they are doing anything else. No shame in being honest.

2 Likes

I personally don’t care about the style, and when the autoformatting is set, you don’t pay attention to it at all.
From my point of view, no matter what the defaults are, a lot of people won’t be happy with the default values. The current defaults are what they are and we can’t change them all from one release to another or the sudden change of behavior might scare the existing users. It’s still possible the defaults might change but slowly.
In the meantime, you can change the options’ values for your projects, and we regularly add more options to try to accommodate most users.

3 Likes

Personally, I’m happy to drop my own preferences and just go with the flow regarding formating styles. Not having to think about it and enforcing consistency seem like valuable enough features to me, especially when working in collaboration with other people.

8 Likes

Indeed, I’m with @jeremiedimino on this, and most MirageOS libraries will move to ocamlformat eventually. Note that the mechanical formatting is getting steadily better as the edge cases are being found and dealt with. The forthcoming 0.9 release has many, many fixes over the 0.8 version currently in opam.

And as a reminder, please do test out the master branch and create issues on the ocamlformat tracker or it’s hard to find these corner cases. Beginner, advanced, it doesn’t matter – ideally the majority of styles should be configurable via profiles eventually.

In return, there are cool incoming tools like https://github.com/hhugo/merge-fmt which will make the use of formatting tools and git pretty seamless with respect to merges and so on.

3 Likes

Relevant discussion happening at the same time in another place about another language formatter:
https://discourse.elm-lang.org/t/how-does-elm-format-work-for-the-elm-community/3241

Extracted from the discussion:

But a difference is that elm-format was there much earlier on in the ecosystem.

Another quote:

That’s another difference with OCaml format. Overall, it results in cleaner diffs.

2 Likes