From: micha <michael.wohlwend@gmx.de>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Style and organization of code
Date: Thu, 15 Mar 2007 10:03:05 +0100 [thread overview]
Message-ID: <20070315100305.2712ee03@localhost> (raw)
In-Reply-To: <1173931272.31293.15.camel@rosella.wigram>
Am Thu, 15 Mar 2007 15:01:12 +1100
schrieb skaller <skaller@users.sourceforge.net>:
> On Wed, 2007-03-14 at 17:25 -0500, ian wrote:
> > I'm looking for a guidebook or just some rules of thumb on how to
> > organize my OCaml code.
>
> > But that would make the definition of solveHardProblem really long
> > -- several screens of text -- which I've been taught to avoid.
>
> Yeah, this is a problem with functional programming .. i have
> functions that are hundreds of lines long.
>
> Generally you want to factor out functions with minimal coupling
> to the enclosing function's environment, and leave them in
> if they're heavily coupled.
>
> Furthermore if that helper is reasonably general OR it has
> some semantics which are separately understandable .. you can
> put that function in a separate file for additional decoupling.
>
> > Is it wrong to use a module
> > to hide those functions if the module signature will contain only
> > that of solveHardProblem?
>
> That's the normal thing to do.
>
> Furthermore if that helper is reasonably general OR it has
> some semantics which are separately understandable .. you can
> put that function in a separate file for additional decoupling.
>
> This has the downside that Ocaml's namespace management is weak,
> so your function is now fully public.
>
> But smaller modules are more pleasing and easier to manage,
> so it is probably worth while.
>
> In particular if you use 'open Module' a lot, then the
> dependencies both ON and OF that module are more refined
> and explicit. This is also a reasonable first order approximation
> to measuring the 'coupling' between components.
>
> > And say you DO choose to use a module... The OCaml documentation
> > says that the compiler can automatically infer the signature
> > without the need to create a .mli file for it. Does anyone
> > actually use that feature in practice, or is creating a sig
> > hard-wired to the act of creating a struct?
>
> I personally never do this: there is always an mli file for
> every ml file -- even if the build script makes it by copying
> the mli file.
>
next prev parent reply other threads:[~2007-03-15 9:03 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-14 22:25 ian
2007-03-15 3:21 ` [Caml-list] " Tom
2007-03-15 1:03 ` ian
2007-03-15 8:02 ` Gabriel Kerneis
2007-03-15 8:09 ` Maxence Guesdon
2007-03-15 8:20 ` Gabriel Kerneis
2007-03-15 10:11 ` ian
2007-03-15 20:04 ` Martin Jambon
2007-03-15 3:44 ` Chris King
2007-03-15 3:50 ` Chris King
2007-03-15 4:01 ` skaller
2007-03-15 9:03 ` micha [this message]
2007-03-15 13:38 ` dynamically finding libraries Vu Ngoc San
2007-03-15 17:10 ` [Caml-list] " Eric Cooper
2007-03-15 17:29 ` slightly OT: anyone reading this list with Mutt? Eric Cooper
2007-03-15 18:44 ` [Caml-list] " Stefano Zacchiroli
2007-03-15 19:00 ` caml-list
2007-03-15 19:44 ` ls-ocaml-developer-2006
2007-03-15 22:39 ` [Caml-list] Style and organization of code Richard Jones
2007-03-29 0:49 ` Jon Harrop
[not found] <20070315224000.674E3BC82@yquem.inria.fr>
2007-03-15 23:08 ` David Allsopp
2007-03-15 23:48 ` Richard Jones
2007-03-16 3:51 ` Quôc Peyrot
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=20070315100305.2712ee03@localhost \
--to=michael.wohlwend@gmx.de \
--cc=caml-list@yquem.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