[Libguestfs] [PATCH v2 02/17] v2v: factor out opening input VM

Richard W.M. Jones rjones at redhat.com
Thu Aug 27 18:21:12 UTC 2015


On Thu, Aug 27, 2015 at 08:59:16PM +0300, Roman Kagan wrote:
> On Thu, Aug 27, 2015 at 03:53:55PM +0100, Richard W.M. Jones wrote:
> > On Tue, Aug 11, 2015 at 08:00:21PM +0300, Roman Kagan wrote:
> > > Opening the source VM and amending the properties in its internal
> > > representation in accordance with command-line options fit nicely into
> > > two isolated functions.
> > 
> > Better to write this as:
> > 
> >   let rec main () =
> >     ...
> > 
> >   and open_source ... =
> >     ...
> > 
> >   and amend_source ... =
> >     ...
> > 
> >   and inspect_source ... =
> >     ...
> > 
> > so it's consistent with how all the other sub-functions are
> > done in the same file.
> 
> I actually went the other way around: I moved all callees ahead of
> callers, with main() at the end.  This is typical of many programming
> languages, including C and Python (the ones I code in most), and I find
> it easier to navigate.  Especially so since the file culminates in a
> coda where that main() called, so it looks more logical going from
> callees to callers.

I gathered that by the time I'd got to the end of the first 14
patches.  This is top down vs bottom up, and we've generally (but not
religiously) got a preference for top down through the rest of the
code.  See eg:
https://github.com/libguestfs/libguestfs/blob/master/src/launch-libvirt.c#L258

Anyway if you move all these functions into a Common module then
the whole issue goes away.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v




More information about the Libguestfs mailing list