English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Style and organization of code
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-03-15 (22:39)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Style and organization of code
On Wed, Mar 14, 2007 at 05:25:37PM -0500, ian wrote:
> Say I have a function called "solveHardProblem". 

Ack!  studlyCaps is horrible and unreadable (I know - I'm currently
involved in a project which uses them).  Try "solve_hard_problem"

> solveHardProblem relies on
> several helper functions, which are not going to be useful to any other
> functions in the program.  So, my first instinct would be to define all the
> helpers using let blocks within the definition of solveHardProblem.
> But that would make the definition of solveHardProblem really long -- several
> screens of text -- which I've been taught to avoid.

You've been taught wrong.  There are some studies that show that long
functions actual reduce error rates - see Steve McConnell's book Code
Complete for references.

> Is it wrong to use a module to hide those functions if the module
> signature will contain only that of solveHardProblem?

Not wrong at all.

> 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?

You don't need to create a separate .mli (in fact, you sometimes


Richard Jones
Red Hat