From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id E38BD8E78 for ; Wed, 13 Jan 2016 08:57:43 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 12 Jan 2016 23:57:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,288,1449561600"; d="scan'208";a="880340237" Received: from yliu-dev.sh.intel.com ([10.239.66.49]) by fmsmga001.fm.intel.com with ESMTP; 12 Jan 2016 23:57:41 -0800 From: Yuanhan Liu To: dev@dpdk.org Date: Wed, 13 Jan 2016 15:58:49 +0800 Message-Id: <1452671929-29617-1-git-send-email-yuanhan.liu@linux.intel.com> X-Mailer: git-send-email 1.9.0 Subject: [dpdk-dev] [PATCH] doc: coding style: use linux kernel style for indentation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jan 2016 07:57:44 -0000 Using two tabs for "if" (or "while") statements is a bit weird to me. Also, using one tab unconditionaly for function definitions and prototypes doesn't look great. Here I'd suggest to use the indentation style the Linux kernel project prefers: to align with the open brace with tabs and additonal spaces (when necessary). Example: static int rte_eal_foo_bar(int a_long_argument_1, int another_long_argument_2, struct foo *yet_another_long_argument_3) ret = rte_eal_foo_bar(a_long_argument_1, another_long_argument_2, yet_another_long_argument_3); if (really_long_variable_name_1 == really_long_variable_name_2 && var3 == var4) { x = y + z; ....; } Cc: Thomas Monjalon Cc: Siobhan Butler Cc: John McNamara Signed-off-by: Yuanhan Liu --- doc/guides/contributing/coding_style.rst | 38 ++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/doc/guides/contributing/coding_style.rst b/doc/guides/contributing/coding_style.rst index ad1392d..23cd060 100644 --- a/doc/guides/contributing/coding_style.rst +++ b/doc/guides/contributing/coding_style.rst @@ -339,9 +339,11 @@ General * Do not put any spaces before a tab for indentation. * If you have to wrap a long statement, put the operator at the end of the line, and indent again. -* For control statements (if, while, etc.), continuation it is recommended that the next line be indented by two tabs, rather than one, - to prevent confusion as to whether the second line of the control statement forms part of the statement body or not. - Alternatively, the line continuation may use additional spaces to line up to an appropriately point on the preceding line, for example, to align to an opening brace. +* For control statements (if, while, etc.), function definitions and + function prototypes continuation lines, it is recommended that the + next line be indented by tab and additional spaces when necessary + to align to the opening brace. For others, it's also okay to be + indented by tab only. .. note:: @@ -350,17 +352,29 @@ General .. code-block:: c while (really_long_variable_name_1 == really_long_variable_name_2 && - var3 == var4){ /* confusing to read as */ - x = y + z; /* control stmt body lines up with second line of */ - a = b + c; /* control statement itself if single indent used */ + var3 == var4) { /* confusing to read as */ + x = y + z; /* control stmt body lines up with second line of */ + a = b + c; /* control statement itself if single indent used */ } if (really_long_variable_name_1 == really_long_variable_name_2 && - var3 == var4){ /* two tabs used */ - x = y + z; /* statement body no longer lines up */ - a = b + c; + var3 == var4) { /* align with above opening if statement */ + x = y + z; /* statement body no longer lines up */ + a = b + c; } + /* The continuation line is indented with two tab + 1 space */ + static int + rte_eal_foo_bar(int a_long_argument_1, int another_long_argument_2, + struct foo *yet_another_long_argument_3) + { + ... + } + + /* The continuation line is indented with two tab + 7 spaces */ + ret = rte_eal_foo_bar(a_long_argument_1, another_long_argument_2, + yet_another_long_argument_3); + z = a + really + long + statement + that + needs + two + lines + gets + indented + on + the + second + and + subsequent + lines; @@ -510,9 +524,9 @@ Prototypes .. code-block:: c static char *function1(int _arg, const char *_arg2, - struct foo *_arg3, - struct bar *_arg4, - struct baz *_arg5); + struct foo *_arg3, + struct bar *_arg4, + struct baz *_arg5); static void usage(void); .. note:: -- 1.9.0