# OCaml Style guide?

**URL:** <https://discuss.ocaml.org/t/ocaml-style-guide/1378>\
**Category:** Learning\
**Created:** [January 2, 2018, 9:22pm UTC](https://discuss.ocaml.org/t/ocaml-style-guide/1378 "2018-01-02T21:22:03Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![perry](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/perry/32/518_2.png) [@perry](https://discuss.ocaml.org/u/perry)\
**Post date:** [January 2, 2018, 9:22pm UTC](https://discuss.ocaml.org/t/ocaml-style-guide/1378/1 "2018-01-02T21:22:03Z")

</div>

This might be a FAQ: is there a definitive style guide out there for OCaml?

(If one googles for it, the first hits are from some classes at Cornell and U. Penn, and I don’t think those are “definitive”.)

---

<div class="post-metadata">

**Author:** ![techate](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/techate/32/671_2.png) [@techate](https://discuss.ocaml.org/u/techate)\
**Post date:** [January 2, 2018, 9:40pm UTC](https://discuss.ocaml.org/t/ocaml-style-guide/1378/2 "2018-01-02T21:40:57Z")

</div>

I quite like [https://ocaml.org/learn/tutorials/guidelines.html](https://ocaml.org/learn/tutorials/guidelines.html)

---

<div class="post-metadata">

**Author:** ![perry](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/perry/32/518_2.png) [@perry](https://discuss.ocaml.org/u/perry)\
**Post date:** [January 2, 2018, 10:51pm UTC](https://discuss.ocaml.org/t/ocaml-style-guide/1378/3 "2018-01-02T22:51:05Z")

</div>

Just started reading it. It has a lot of good stuff, though it seems a bit silent on a few things I’d like answers on. (For example, what’s preferred, `begin ... end` vs `( ... )`, and when?) But I’ll should try to read the whole thing before making such comments. 🙂

---

<div class="post-metadata">

**Author:** ![robb](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@robb](https://discuss.ocaml.org/u/robb)\
**Post date:** [January 3, 2018, 12:31am UTC](https://discuss.ocaml.org/t/ocaml-style-guide/1378/4 "2018-01-03T00:31:13Z")

</div>

I’ve found [https://github.com/hammerlab/style-guides/blob/master/ocaml.md](https://github.com/hammerlab/style-guides/blob/master/ocaml.md) to be a useful supplement to @techate’s link above.

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [January 3, 2018, 3:21am UTC](https://discuss.ocaml.org/t/ocaml-style-guide/1378/5 "2018-01-03T03:21:05Z")

</div>

There is the ocamlformat ( [https://github.com/ocaml-ppx/ocamlformat](https://github.com/ocaml-ppx/ocamlformat) ) style; the advantage with this one is that it can plug in to your editor and auto-format your code for you, like gofmt, etc.

I think (but I haven’t tried it) Emacs’ tuareg-mode also autoformats your code while you type.

And finally of course, there is refmt which autoformats ReasonML code if you write in that syntax.

---

<div class="post-metadata">

**Author:** ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)\
**Post date:** [March 28, 2018, 9:51pm UTC](https://discuss.ocaml.org/t/ocaml-style-guide/1378/6 "2018-03-28T21:51:13Z")

</div>

Hardly definitive, but we just posted our style guide here:

> **[Jane Street Open Source](https://opensource.janestreet.com/standards/)**
>
> A collection of Jane Street Open Source libraries

---

<div class="post-metadata">

**Author:** ![Khady](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/khady/32/469_2.png) [@Khady](https://discuss.ocaml.org/u/Khady)\
**Post date:** [March 29, 2018, 12:19am UTC](https://discuss.ocaml.org/t/ocaml-style-guide/1378/7 "2018-03-29T00:19:38Z")

</div>

I think there is a typo here, a missing `|`:

```
match/with expressions

Put ‘ ’ before the first pattern, e.g.:

```

![image](https://us1.discourse-cdn.com/flex020/uploads/ocaml/original/1X/604d744ff014479282c2c4b15758abf50aaf5bbb.png)

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [March 29, 2018, 12:53am UTC](https://discuss.ocaml.org/t/ocaml-style-guide/1378/8 "2018-03-29T00:53:01Z")

</div>

Another one:

```auto
let position_change function

```

In general, this is a nice and sane guide. Will be a great benefit to incoming OCamlers. The Xen one is also fairly good [https://wiki.xenproject.org/wiki/OCaml\_Best\_Practices\_for\_Developers](https://wiki.xenproject.org/wiki/OCaml_Best_Practices_for_Developers)

---

<div class="post-metadata">

**Author:** ![Levi\_Roth](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/levi_roth/32/2268_2.png) [@Levi\_Roth](https://discuss.ocaml.org/u/Levi_Roth)\
**Post date:** [March 29, 2018, 6:10pm UTC](https://discuss.ocaml.org/t/ocaml-style-guide/1378/9 "2018-03-29T18:10:28Z")

</div>

Under “Directory Names,” there’s a sentence that looks like it was meant as an editor’s note:

> Is there guidance for organizing projects around lib/ and bin/ directories?

---

<div class="post-metadata">

**Author:** ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)\
**Post date:** [March 30, 2018, 11:47am UTC](https://discuss.ocaml.org/t/ocaml-style-guide/1378/10 "2018-03-30T11:47:00Z")

</div>

Thanks all for pointing out the issues. Should be fixed now.

y

---

<div class="post-metadata">

**Author:** ![ins](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ins/32/923_2.png) [@ins](https://discuss.ocaml.org/u/ins)\
**Post date:** [March 30, 2018, 1:06pm UTC](https://discuss.ocaml.org/t/ocaml-style-guide/1378/12 "2018-03-30T13:06:47Z")

</div>

Just reporting another typo I noticed:

 ![11%20AM](https://us1.discourse-cdn.com/flex020/uploads/ocaml/original/1X/79a3e77d1cd66cc4cffe9b28ecbc5055f9f126b4.png)

The `order` argument to `List.iter` in the second code snippet should be `orders` (to match the first code snippet).
