-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: What code conventions to use? #4
Comments
The last two are solved by |
refmt isn't even consistent with itself though This is how it formats ml and reason, respectively: let _ =
match Background.Refmt.refmt input with
| ("Failure",error) -> cb error None None
| (conversion,outText) ->
(match conversion |> (Js.String.split "to") with
| [|inLang;outLang|] -> cb outText (Some inLang) (Some outLang)
| _ -> ())
type 'a case =
| StrictEqual of 'a* 'a
| NotStrictEqual of 'a* 'a
| Equal of 'a* 'a
| NotEqual of 'a* 'a switch (Background.Refmt.refmt input) {
| ("Failure", error) => cb error None None
| (conversion, outText) =>
switch (conversion |> Js.String.split "to") {
| [|inLang, outLang|] => cb outText (Some inLang) (Some outLang)
| _ => ()
}
};
type case 'a =
| StrictEqual 'a 'a
| NotStrictEqual 'a 'a
| Equal 'a 'a
| NotEqual 'a 'a; And chained pipe operators is pretty broken:
But the convention and what refmt does SHOULD of course be the same. |
We can't do much for the ocaml formatter; we currently don't control/have the energy to make it work well (plus, it doesn't even preserve comments). Pipe being broken is indeed bad, but it should be considered as a refmt bug. Formatting conventions should be filed to the reason repo as issues. |
Sorry, I didn't mean for this to be an issue to discuss and establish every detail of convention, but rather to point out some frequently asked questions that ought to be answered by an FAQ. And as you point out, |
hey no need to be sorry, I was trying to be mean or anything lol |
(Sorry,) I might be part canadian (I'm kind of in the right latitude at least) |
Sorry, I'm Canadian too |
Ok let's see
Rough draft of answer. Do the answers make sense? |
Regarding 10. Non-optional labeled functions doesn't need an extra unit argument, but @bobzhang once told me it's an OCaml convention to do so still. I don't know why, but I've been doing that for the 11: Same question, when the two forms are equivalent, which should be preferred? |
Another convention question: Should the "exit" branch(es) of a pattern match come first or last? E.g. match get_opt foo with
| Some value ->
(* do something with value
* over several lines
*)
| None -> () vs. match get_opt foo with
| None -> ()
| Some value ->
(* do something with value
* over several lines
*) The latter is clearer, especially if there's nested matches, but sometimes the "exit" branches will be a wildcard match, in which case it has to come last. Should that then be the convention just for consistency, or should it be contextual? |
|
Yea I'm not saying This is somewhat similar to the imperative dilemma: if (thing) {
/* do things with thing */
} vs. if (!thing) {
return;
}
/* do things with thing */ (I prefer the latter for imperative code) I've no problem with not instantly getting this answered though, I'm just putting it somewhere for safekeeping :) |
|
Another one to ponder: There are several conventions among functional programmers for how to name variables when destructuring a list:
We should probably try to standardize on one of these. |
forEach
) or ml-y (for_each
)? Reason is going for js-y, and the npm ecosystem is obviously js-y, yet many bindings seem to go for ml-y naming.IModule
,Module_Sig
orMODULE
let f : int -> string = fun x ->...
overlet f (x: int): string = ...
?|
indented or leveled with the enclosing structure in variant defintions, match expressions and piping?The text was updated successfully, but these errors were encountered: