js_of_ocaml
js_of_ocaml copied to clipboard
[FEATURE REQUEST] Labelled arguments
Is there a reason for not using labelled arguments for JS APIs? Some of the wrapped methods take an impressive number of parameters, e.g. canvasRenderingContext2d
ctx##fillRect (node##.x -. width /. 2.0)
(node##.y -. 1.5 *. font_size)
width
(3.0 *. font_size)
Clearly, labelled arguments would improve the readability here.
Another obvious benefit of labelled arguments is API docs readability. Consider the following two methods:
method fillText : Js.js_string Js.t -> float -> float -> unit Js.meth
method fillText_withWidth :
Js.js_string Js.t -> float -> float -> float -> unit Js.meth
Which of the float parameters corresponds to width in the second method? Impossible to tell without looking at the original JS API docs.
Presumably because the DOM apis themselves don't use labeled arguments and those are an OCaml abstraction. You'll probably be told to write your own layer on top.
@superbobry, I like the idea. Feel free to submit a PR.
@hhugo bringing this into the main APIs would probably break a lot of code, would you like a separate labelled module a la StdLabels?