ocaml-graphql-server icon indicating copy to clipboard operation
ocaml-graphql-server copied to clipboard

Use Format for pretty-printing instead of Fmt

Open keleshev opened this issue 6 years ago • 4 comments

This is probably a bit random, but I replaced Fmt with the standard Format module. One less dependency, plus if you like printf you might find this more readable.

I hope to get onto something more useful (like block strings) soon

keleshev avatar Feb 09 '19 20:02 keleshev

Looks good, thanks! 👍 I'm happy to merge this when 0.9.0 is merged in OPAM -- just in case there are any last minute changes required before then.

andreas avatar Feb 10 '19 14:02 andreas

what is the advantage hereof? I honestly find the Fmt combinators much easier to read than Format (also, the diff +100 -84 shows that there is actually more code involved).

hannesm avatar Feb 10 '19 14:02 hannesm

@hannesm the advantage is dubious, honestly. Readability is subjective. I find the Format style more readable, but whatever the maintainers find most suited to their needs.

The +100 -84 diff is mostly due to more liberal line breaks:

(* Before *)
Fmt.fmt "%a %s%a%a %a" fmt pp_optype op.optype name variables op.variable_definitions directives op.directives selection_set op.selection_set

(* After *)
fprintf ppf "%s %s%a%a %a"
  (optype_to_string op.optype)
  name
  pp_variables op.variable_definitions
  pp_directives op.directives
  pp_selection_set op.selection_set

I find that Format is adequate, except for hideous names, which you can fix by doing "import as":

let list = Format.pp_print_list

keleshev avatar Feb 10 '19 21:02 keleshev

I don't mind much either way. I hope this can be motivating for further contributions though, so I'm happy to indulge 😄

andreas avatar Feb 11 '19 20:02 andreas