[Top][All Lists]

[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

> 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?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]