From nobody Fri May 3 02:25:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1574254591; cv=none; d=zoho.com; s=zohoarc; b=HJ7Z03PlrnEtAPBhxbZfg7zvEVUMJ74b1jAPddaKVkN8edSEWIMNl9lClhStO90zRzZkJApf/7op6KpCVd15Eh2sMci6K00zFaReQ6Gn+QnY+Pr6i4a9WCromux2CSWq+P7KcyJlS0crKxfS4+atW43eSJb1ZeAGE7pz22BAcds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574254591; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=PBtQW3JgtcXiZWsJbV2Q+KBMPeHyfg1D42PxExr6LsA=; b=ZfprVXC+Cw6mf0U3FN2aNfmAqnxxN52AEG2PiaqVIf8DKu7Qo0kNJz3tt/h2uCJI7OgkRZ4yP6tGuTiiYMfqmvAEYykNVm+Rs2qKT0/EKHk8ZSaR1pjEZ0NbLoZ/ht6gsjohjRp8SVt+H/P/DQqTudu6IP47SADkmd0lvSj+N+M= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1574254591062184.82922733742987; Wed, 20 Nov 2019 04:56:31 -0800 (PST) Received: from localhost ([::1]:57394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iXPX3-0008Go-TT for importer@patchew.org; Wed, 20 Nov 2019 07:56:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32883) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iXPVg-0007Li-6S for qemu-devel@nongnu.org; Wed, 20 Nov 2019 07:55:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iXPVc-00074M-JH for qemu-devel@nongnu.org; Wed, 20 Nov 2019 07:55:04 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:51032 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iXPVc-00074D-F7 for qemu-devel@nongnu.org; Wed, 20 Nov 2019 07:55:00 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-414-egkVlXrCNaeAbveVTBmOPg-1; Wed, 20 Nov 2019 07:54:54 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 31E9D107ACC5; Wed, 20 Nov 2019 12:54:53 +0000 (UTC) Received: from localhost (ovpn-112-56.ams2.redhat.com [10.36.112.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6702410375DC; Wed, 20 Nov 2019 12:54:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574254499; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PBtQW3JgtcXiZWsJbV2Q+KBMPeHyfg1D42PxExr6LsA=; b=anRInmm7xOeAP9stzx8WzUM5t+iRO0WV0oIey49UxXuhYO7ZVCfi/JHkonT5T5cp0PzR82 Dw7dQA3SrLsGQpr+xbIOeg9PF07ma33eWygbNlu1CSqTW1H0xa4BACaUntKVUDkSvBKxNv irA+mq70M0KrSVLtqtpLPfwAQa2++PQ= From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Subject: [PATCH] RFC: CODING_STYLE: describe "self" variable convention Date: Wed, 20 Nov 2019 16:54:44 +0400 Message-Id: <20191120125444.31365-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: egkVlXrCNaeAbveVTBmOPg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Following the discussion in thread "[PATCH v3 13/33] serial: start making SerialMM a sysbus device", I'd like to recommend the usage of "self" variable to reference to the OOP-style method instance, as commonly done in various languages and in GObject world. Cc: Peter Maydell Cc: Daniel P. Berrang=C3=A9 Signed-off-by: Marc-Andr=C3=A9 Lureau --- CODING_STYLE.rst | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/CODING_STYLE.rst b/CODING_STYLE.rst index 427699e0e4..cb6635af71 100644 --- a/CODING_STYLE.rst +++ b/CODING_STYLE.rst @@ -102,12 +102,38 @@ Rationale: Naming =3D=3D=3D=3D=3D=3D =20 -Variables are lower_case_with_underscores; easy to type and read. Structu= red -type names are in CamelCase; harder to type but standing out. Enum type -names and function type names should also be in CamelCase. Scalar type -names are lower_case_with_underscores_ending_with_a_t, like the POSIX -uint64_t and family. Note that this last convention contradicts POSIX -and is therefore likely to be changed. +Variables are lower_case_with_underscores; easy to type and read. + +The most common naming for a variable is an abbreviation of the type +name. Some common examples: + +.. code-block:: c + + Object *obj; + QVirtioSCSI *scsi; + SerialMM *smm; + +When writing QOM/OOP-style function, a "self" variable allows to refer +without ambiguity to the instance of the method that is being +implemented (this is not very common in QEMU code base, but it is +often a good option to increase the readability and consistency, +making further refactoring easier as well). Example: + +.. code-block:: c + + serial_mm_flush(SerialMM *self); + + serial_mm_instance_init(Object *o) { + SerialMM *self =3D SERIAL_MM(o); + .. + } + +Structured type names are in CamelCase; harder to type but standing +out. Enum type names and function type names should also be in +CamelCase. Scalar type names are +lower_case_with_underscores_ending_with_a_t, like the POSIX uint64_t +and family. Note that this last convention contradicts POSIX and is +therefore likely to be changed. =20 When wrapping standard library functions, use the prefix ``qemu_`` to alert readers that they are seeing a wrapped version; otherwise avoid this prefi= x. --=20 2.24.0