> From: Stephen Hemminger [mailto:step...@networkplumber.org] > Sent: Saturday, 17 February 2024 19.11 > > On Sat, 17 Feb 2024 19:02:30 +0100 > Morten Brørup <m...@smartsharesystems.com> wrote: > > > Not formally... it follows the official DPDK Coding Style [1]. > > > > [1]: > https://doc.dpdk.org/guides/contributing/coding_style.html#general > > > > > Should be: > > > > > > if ((ol_flags & RTE_MBUF_F_TX_TCP_SEG) == 0 && > > > (ol_flags & RTE_MBUF_F_TX_UDP_SEG) == 0) > > > goto clean_txd; > > > > This indentation style is mentioned as an alternative in the guide. > But the example in the guide also uses two tabs for a similar long > comparison. > > > > Personally, I also prefer the style suggested by Stephen, so we might > want to update the Coding Style. ;-) > > > The two tabs is an Intel thing, and I prefer the kernel, line up the > conditional style.
I prefer 4 space indentation, which is sufficient to notice the indentation. 8 spaces seems overkill to me, and quickly makes the lines too long. With the editor configured to show tab as 4 spaces, the kernel alignment style ends up with the same indentation for the condition and the code block: if (a && b) ctr++; Whereas with the "tab as 4 spaces" editor configuration, the double indentation style clearly separates the continued condition from code block: if (a && b) ctr++; On the other hand, complex conditions are easier readable when aligning logically instead of by a fixed number of tabs, e.g.: if (a | (b & (c ^ d)) | (e ^ f) | g) ctr++; Placing the operators at the beginning also makes the code more readable: if (a | (b & (c ^ d)) | (e ^ f) | g) ctr++; I guess that coding styles are mostly a matter of taste. I wonder if any research into coding styles has reached any conclusions or recommendations, beyond mixing coding styles is bad for readability. > We really should have a style that can be describe by clang format. > Other projects like VPP have a target that reformats the code and uses > one of the clang format templates. Automated code formatting seems like a good idea.