Richard W.M. Jones
2015-Aug-27 14:53 UTC
Re: [Libguestfs] [PATCH v2 02/17] v2v: factor out opening input VM
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. 'let rec .. and ..' defines mutually recursive functions that can call each other. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Roman Kagan
2015-Aug-27 17:59 UTC
Re: [Libguestfs] [PATCH v2 02/17] v2v: factor out opening input VM
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. Roman.
Richard W.M. Jones
2015-Aug-27 18:21 UTC
Re: [Libguestfs] [PATCH v2 02/17] v2v: factor out opening input VM
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
Reasonably Related Threads
- Re: [PATCH v2 02/17] v2v: factor out opening input VM
- [PATCH v3 01/13] v2v: factor out opening input VM
- [PATCH v2 02/17] v2v: factor out opening input VM
- [PATCH v3 02/13] v2v: factor out overlay creation
- [PATCH v2 04/17] v2v: factor out populating targets list