js_of_ocaml icon indicating copy to clipboard operation
js_of_ocaml copied to clipboard

[FEATURE REQUEST] Labelled arguments

Open superbobry opened this issue 9 years ago • 3 comments

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.

superbobry avatar Jul 29 '16 13:07 superbobry

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.

fxfactorial avatar Jul 31 '16 10:07 fxfactorial

@superbobry, I like the idea. Feel free to submit a PR.

hhugo avatar Jul 31 '16 10:07 hhugo

@hhugo bringing this into the main APIs would probably break a lot of code, would you like a separate labelled module a la StdLabels?

superbobry avatar Aug 01 '16 15:08 superbobry