[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v4 16/16] qapi: Prefer '"str" + var' over '"str%
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v4 16/16] qapi: Prefer '"str" + var' over '"str%s" % var' |
Date: |
Thu, 14 May 2015 10:25:40 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
On 05/14/2015 10:09 AM, Markus Armbruster wrote:
> Eric Blake <address@hidden> writes:
>
>> Use of python's % operator to format strings is fine if there are
>> multiple strings or if there is integer formatting going on, but
>> when it is just abused for string concatenation, it looks nicer
>> to just use the + operator. This is particularly true when the
>> value being substituted is at the front of the format string,
>> rather than the tail.
>
> I quite agree in cases such as
>
> - discriminator_type_name = '%sKind' % (name)
> + discriminator_type_name = name + 'Kind'
I could always split this into the obvious cases vs. the questionable
ones, if that helps.
>
> I have doubts in cases such as
>
> - return "qmp_marshal_output_%s(retval, ret, &local_err);" % c_name(name)
> + return "qmp_marshal_output_" + c_name(name) + "(retval, ret,
> &local_err);"
>
> I find the old code makes it easier to grasp the result. Admittedly
> subjective.
Yeah, that's a judgment call.
>
>> Update an error message (and testsuite coverage) while at it, since
>> concatenating a non-string object does not always produce legible
>> results.
>
> The new expected test output shows improvement.
Also might be worth splitting into its own patch, rather than buried in
the noise of cleanups.
>
>> Signed-off-by: Eric Blake <address@hidden>
>
> I'll take 01-15 now, and have a second look at this one later, okay?
Yeah, I kind of figured that might happen. Works for me :)
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH v4 02/16] qapi: Rename identical c_fun()/c_var() into c_name(), (continued)
- [Qemu-devel] [PATCH v4 02/16] qapi: Rename identical c_fun()/c_var() into c_name(), Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 05/16] qapi: Simplify c_enum_const(), Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 10/16] qapi: Support downstream enums, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 12/16] qapi: Support downstream simple unions, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 14/16] qapi: Support downstream alternates, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 11/16] qapi: Support downstream structs, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 15/16] qapi: Support downstream events and commands, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 16/16] qapi: Prefer '"str" + var' over '"str%s" % var', Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 13/16] qapi: Support downstream flat unions, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 03/16] qapi: Rename _generate_enum_string() to camel_to_upper(), Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 04/16] qapi: Rename generate_enum_full_value() to c_enum_const(), Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 01/16] qapi: Fix C identifiers generated for names containing '.', Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 09/16] qapi: Make c_type() consistently convert qapi names, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 08/16] qapi: Tidy c_type logic, Eric Blake, 2015/05/14