[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: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH v4 16/16] qapi: Prefer '"str" + var' over '"str%s" % var' |
Date: |
Thu, 14 May 2015 18:09:43 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
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 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.
> 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.
> Signed-off-by: Eric Blake <address@hidden>
I'll take 01-15 now, and have a second look at this one later, okay?
- [Qemu-devel] [PATCH v4 00/16] Fix qapi mangling of downstream names, Eric Blake, 2015/05/14
- [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
- Re: [Qemu-devel] [PATCH v4 16/16] qapi: Prefer '"str" + var' over '"str%s" % var',
Markus Armbruster <=
- [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