All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Pavel Fedin" <p.fedin@samsung.com>,
	qemu-devel@nongnu.org, "Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] Stick to loops
Date: Mon, 12 Oct 2015 13:56:32 +0200	[thread overview]
Message-ID: <877fms1erz.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <561B8A5D.7030908@redhat.com> (Paolo Bonzini's message of "Mon, 12 Oct 2015 12:24:29 +0200")

Paolo Bonzini <pbonzini@redhat.com> writes:

> On 12/10/2015 12:00, Daniel P. Berrange wrote:
>> I don't think your example here is a reasonable comparison when you consider
>> the full extent of this patch series. You are only having to iterate over a
>> single data structure here. At the end of this patch series we have to
>> iterate over multiple data structures spread across the object instance
>> and class hierarchy, so writing a 'next' like method is not as trivial
>> as you suggest with this comparison.
>> 
>> > Higher-order functions are a wonderful tool if the language is equipped
>> > for them.  In Lisp, for instance, you'd have everything in one place and
>> > no need for the awkward marshalling and unmarshalling of arguments,
>> > thanks to nested functions.
>> > 
>> > In C, stick to loops.  That's what the language supports.
>> 
>> You're really arguing against use of function callbacks in general with
>> this comparison to LISP. I don't think that's really practical in the
>> real world, as any integration with event loop needs callbacks, which
>> share al the same limitations as callbacks used with this foreach()
>> style iterator. Given this I don't think banning use of callbacks in
>> one specific scenario is really beneficial in general - its really
>> just a personal style choice.

You're right, I do think callbacks in C are relatively awkward.  But
then you're attacking a strawman --- I did not advocate *banning*
callbacks.  That would be silly indeed.  I did advocate for using them
*sparingly*.

There are cases where callbacks are simply required, and you quoted one.

There are cases where callbacks compete with other techniques, and I
quoted one.

> I agree with Eric that in general loops are better than callbacks.

Me.  Eric's innocent :)

> However, there are cases where iterators are just as awkward to write.
> Considering that we have very few iterations on properties, I think your
> patches are fine.

Mind, I didn't actually object to them.  I merely voiced my reasoned
opinion on idiomatic iteration in C: stick to loops.

Just to deter strawmen: that's a rule of thumb, not a law :)

  reply	other threads:[~2015-10-12 11:56 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-08 14:08 [Qemu-devel] [PATCH v3 0/5] qom: more efficient object property handling Daniel P. Berrange
2015-10-08 14:09 ` [Qemu-devel] [PATCH v3 1/5] qom: introduce object_property_foreach method Daniel P. Berrange
2015-10-08 16:29   ` Eric Blake
2015-10-09  8:31     ` [Qemu-devel] Stick to loops (was: [PATCH v3 1/5] qom: introduce object_property_foreach method) Markus Armbruster
2015-10-12 10:00       ` Daniel P. Berrange
2015-10-12 10:24         ` [Qemu-devel] Stick to loops Paolo Bonzini
2015-10-12 11:56           ` Markus Armbruster [this message]
2015-10-13 12:09         ` [Qemu-devel] Stick to loops (was: [PATCH v3 1/5] qom: introduce object_property_foreach method) Daniel P. Berrange
2015-10-08 14:09 ` [Qemu-devel] [PATCH v3 2/5] qmp: convert to use object_property_foreach iterators Daniel P. Berrange
2015-10-08 16:35   ` Eric Blake
2015-10-08 14:09 ` [Qemu-devel] [PATCH v3 3/5] vl: convert machine help to use object_property_foreach Daniel P. Berrange
2015-10-08 19:06   ` Eric Blake
2015-10-08 14:09 ` [Qemu-devel] [PATCH v3 4/5] qom: replace object property list with GHashTable Daniel P. Berrange
2015-10-08 15:05   ` Pavel Fedin
2015-10-08 19:13   ` Eric Blake
2015-10-08 14:09 ` [Qemu-devel] [PATCH v3 5/5] qom: allow properties to be registered against classes Daniel P. Berrange
2015-10-08 19:35   ` Eric Blake
2015-10-08 15:12 ` [Qemu-devel] [PATCH v3 0/5] qom: more efficient object property handling Eric Blake
2015-10-08 15:27 ` Pavel Fedin
2015-10-08 15:48   ` Daniel P. Berrange

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=877fms1erz.fsf@blackfin.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=afaerber@suse.de \
    --cc=p.fedin@samsung.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.