From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlbiW-0002Vz-CZ for qemu-devel@nongnu.org; Mon, 12 Oct 2015 07:56:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZlbiV-0008KA-Gw for qemu-devel@nongnu.org; Mon, 12 Oct 2015 07:56:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37522) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlbiV-0008K6-BO for qemu-devel@nongnu.org; Mon, 12 Oct 2015 07:56:35 -0400 From: Markus Armbruster References: <1444313344-16196-1-git-send-email-berrange@redhat.com> <1444313344-16196-2-git-send-email-berrange@redhat.com> <561699D7.1010105@redhat.com> <87pp0ozbmp.fsf_-_@blackfin.pond.sub.org> <20151012100004.GH21855@redhat.com> <561B8A5D.7030908@redhat.com> Date: Mon, 12 Oct 2015 13:56:32 +0200 In-Reply-To: <561B8A5D.7030908@redhat.com> (Paolo Bonzini's message of "Mon, 12 Oct 2015 12:24:29 +0200") Message-ID: <877fms1erz.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] Stick to loops List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Pavel Fedin , qemu-devel@nongnu.org, Andreas =?utf-8?Q?F=C3=A4?= =?utf-8?Q?rber?= Paolo Bonzini 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 :)