From: Romain Bardou <romain.bardou@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] We need a rich standard library distributed with OCaml, really
Date: Thu, 27 Aug 2015 12:35:17 +0200 [thread overview]
Message-ID: <55DEE7E5.1020104@inria.fr> (raw)
In-Reply-To: <CAPFanBFK6y=5+TLDU0oo_z3Ts-LO22m6PZjytQW415LqGO041g@mail.gmail.com>
> There remain the issue that having several "base libraries" risks
> fragmenting the community in incompatible islands of software usage.
> It is true that shoving stuff into the compiler distribution is a way
> to resolve this excess of choice by authority, but it is manifest that
> no one currently wants to bear this authority and the responsibilities
> that come with it. (Except possibly on very localized issues, as the
> `result` type that is being integrated in 4.03+dev).
>
> I think the way forward is to have smaller independent packages that
> do not require so large a buy-in and consensus. We could have *one*
> package that provides many useful functions for lists, and one
> separate package with many useful functions for strings. In this style
> Daniel Bünzli beautifully documented small packages, or David Sheets
> doing-one-thing libraries would be role models to follow. This wasn't
> an option when Batteries or Core were started, because the packaging
> story was too confused, but it is now and we should take advantage of
> it. Given time (and help?) I hope to evolve Batteries towards this
> model.
I agree about smaller, independent packages. This is a very general API
design principle: avoid coupling (the fact that using a module implies
using another). This may be the main reason I avoid external libraries.
For instance, Martin Jambon's Yojson depends on biniou, cppo and
easy-format. I believe Martin is an awesome programmer but this
particular point just baffles me as there is absolutely no need for
*any* external dependency to solve such a simple problem (JSON parsing,
pretty-printing and AST constructors). I understand that Martin wants to
reuse its own code and be able to integrate Yojson easily with other
libraries of his, and that is great. For him and users of his other
libraries. Not for those who just want a JSON parser and have had to
install all dependencies manually on Windows.
Lwt is another example. While it is obviously an awesome library, using
it is not a decision to take lightly.
There is something that I love about Yojson though: the main type (the
JSON AST) uses polymorphic variants. This means that it is possible to
write a library which is capable of integrating with Yojson without
actually depending on it. You just copy-paste the type definition and
use it. Then your user can use any JSON parser and printer. He can use
Yojson, or another library which happens to use a supertype. Worst case
scenario, he takes 5 minutes to write functions to convert the Yojson
AST to and from another JSON library's type.
Writing code which can integrate with another library without actually
depending on it will scare users less and make more people use your
library. Here are some more examples.
- Use standard library types like option, list, or array instead of
trying to generalize to some enumeration concept.
- If the previous point is not possible because the enumeration is too
big to be constructed before use, consider providing an iter function.
Such a function can be easily used with a library such as Simon Cruanes'
sequence library, but your library does not need to depend on it.
- Functors allow your code to depend on any implementation.
Unfortunately functors are a pain both to write and to use. One of the
promises of the module system is to be able to replace a module with
another one with the same signature, but how many times have you seen
that being done in practice (without functors)? The build system and
namespace issues do not help you to do that. Especially if you want to
replace the dependency of a third-party library. Say, use a library
which depends on Lwt but make it use your implementation of Lwt instead,
without having to manually reconfigure and recompile the library, just
by using the compiled version from opam. This is even harder if your Lwt
implementation does not provide the same interface as Lwt except for the
part which is used by the library.
Coupling is not bad just between libraries. For instance, you may be
tempted to write a function "split_list" to split a string into a list,
by using another function "split_pair" which splits a string into a pair
(at the first occurrence only). But an independent implementation of
split_list is much more efficient (if split_pair copies the two
substrings), can more easily be sent to the toplevel for testing, and
can be copy-pasted easily between programs (until you decide to put it
into a library). But more importantly, if you need to change
"split_pair" for some reason, you will have to check all functions which
use it, including "split_list". Yes, sharing code allows to share bug
fixes. But it also makes it easier to break stuff accidentally.
--
Romain Bardou
next prev parent reply other threads:[~2015-08-27 10:35 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-27 2:52 Hongbo Zhang
2015-08-27 6:59 ` Christoph Höger
2015-08-27 7:18 ` Anthony Tavener
2015-08-27 8:17 ` Gabriel Scherer
2015-08-27 10:35 ` Romain Bardou [this message]
2015-08-27 19:55 ` Martin DeMello
2015-08-27 20:10 ` Yotam Barnoy
2015-08-27 23:24 ` Drup
2015-08-28 13:23 ` Philippe Veber
2015-08-27 20:17 ` Raoul Duke
2015-08-27 23:10 ` Martin Jambon
[not found] ` <20150827174554.14858.6618@localhost>
2015-08-27 18:42 ` [Caml-list] Fwd: " Emmanuel Surleau
2015-08-27 21:17 ` [Caml-list] " Paolo Donadeo
2015-08-27 21:51 ` Oliver Bandel
2015-08-27 21:56 ` Oliver Bandel
2015-08-27 22:04 ` Oliver Bandel
2015-08-28 0:50 ` Hongbo Zhang
2015-08-31 16:06 ` Stéphane Glondu
2015-08-31 16:14 ` Francois Berenger
2015-08-31 16:44 ` Hendrik Boom
2015-08-31 18:04 ` Ian Zimmerman
2015-08-31 17:26 ` Stéphane Glondu
2015-09-01 15:06 ` Anil Madhavapeddy
2015-08-31 17:34 ` Oliver Bandel
2015-09-01 13:46 ` Gabriel Scherer
2015-08-27 8:07 ` Sébastien Hinderer
2015-08-27 8:20 ` Daniil Baturin
2015-08-27 9:34 ` Edouard Evangelisti
2015-08-28 9:07 ` r.3
2015-08-27 8:12 ` Francois Berenger
2015-08-27 11:57 ` Drup
2015-08-27 14:17 ` Yaron Minsky
2015-08-27 16:00 ` Jesse Haber-Kucharsky
2015-08-28 0:33 ` Hongbo Zhang
2015-08-28 1:53 ` Daniel Bünzli
[not found] ` <20150828.140826.2157566405742612169.Christophe.Troestler@umons.ac.be>
2015-08-28 12:38 ` Thomas Braibant
2015-08-28 13:00 ` [Caml-list] opam license field (was Re: We need a rich standard library distributed with OCaml, really) Daniel Bünzli
2015-08-28 13:06 ` David Sheets
2015-08-28 14:01 ` [Caml-list] We need a rich standard library distributed with OCaml, really Oliver Bandel
2015-08-31 15:26 ` Hendrik Boom
2015-08-28 14:35 ` Alain Frisch
2015-08-29 19:02 ` David MENTRÉ
2015-08-31 12:37 ` Jon Harrop
2015-08-31 15:05 ` Emmanuel Surleau
2015-08-31 17:31 ` Oliver Bandel
2015-08-28 15:02 ` Simon Cruanes
2015-08-28 15:27 ` Gabriel Scherer
2015-08-28 15:51 ` Oliver Bandel
2015-08-31 18:40 ` Ashish Agarwal
2016-03-27 20:54 ` Jon Harrop
2016-03-27 21:21 ` Simon Cruanes
2016-03-27 23:48 ` Yaron Minsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55DEE7E5.1020104@inria.fr \
--to=romain.bardou@inria.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox