* coding style question on indentation
@ 2011-07-01 11:20 Sathya.Perla
2011-07-01 11:52 ` Ben Hutchings
2011-07-01 15:23 ` Joe Perches
0 siblings, 2 replies; 5+ messages in thread
From: Sathya.Perla @ 2011-07-01 11:20 UTC (permalink / raw)
To: netdev
Hi,
Which of the following styling is preferable when a function invocation spans more than one line:
a) Aligning the next line with the first argument by inserting a few spaces after the tabs - as in:
dma_unmap_page(&adapter->pdev->dev,
dma_unmap_addr(rx_page_info, bus),
adapter->big_page_size, DMA_FROM_DEVICE);
Documentation/CodingStyle says "spaces are never used for indentation", but I see
scripts/Lindent inserting spaces after tabs for alignment.
OR
b) Just using tabs without needing to align as above:
dma_unmap_page(&adapter->pdev->dev,
dma_unmap_addr(rx_page_info, bus),
adapter->big_page_size, DMA_FROM_DEVICE);
thanks,
-Sathya
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: coding style question on indentation
2011-07-01 11:20 coding style question on indentation Sathya.Perla
@ 2011-07-01 11:52 ` Ben Hutchings
2011-07-01 15:23 ` Joe Perches
1 sibling, 0 replies; 5+ messages in thread
From: Ben Hutchings @ 2011-07-01 11:52 UTC (permalink / raw)
To: Sathya.Perla; +Cc: netdev
On Fri, 2011-07-01 at 04:20 -0700, Sathya.Perla@Emulex.Com wrote:
> Hi,
> Which of the following styling is preferable when a function
> invocation spans more than one line:
>
> a) Aligning the next line with the first argument by inserting a few
> spaces after the tabs - as in:
>
> dma_unmap_page(&adapter->pdev->dev,
> dma_unmap_addr(rx_page_info, bus),
> adapter->big_page_size, DMA_FROM_DEVICE);
My preference, for what it's worth.
> Documentation/CodingStyle says "spaces are never used for indentation", but I see
> scripts/Lindent inserting spaces after tabs for alignment.
I think that's meant to apply to indentation at the start of a statement
or declaration, not when wrapping.
> OR
>
> b) Just using tabs without needing to align as above:
>
> dma_unmap_page(&adapter->pdev->dev,
> dma_unmap_addr(rx_page_info, bus),
> adapter->big_page_size, DMA_FROM_DEVICE);
Popular but ugly in my opinion.
Some people also use a single extra tab to indent after wrapping,
whether or not the line break is within a parenthesised expression or
argument list.
Ben.
--
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: coding style question on indentation
2011-07-01 11:20 coding style question on indentation Sathya.Perla
2011-07-01 11:52 ` Ben Hutchings
@ 2011-07-01 15:23 ` Joe Perches
2011-07-05 19:54 ` Chris Friesen
1 sibling, 1 reply; 5+ messages in thread
From: Joe Perches @ 2011-07-01 15:23 UTC (permalink / raw)
To: Sathya.Perla; +Cc: netdev
On Fri, 2011-07-01 at 04:20 -0700, Sathya.Perla@Emulex.Com wrote:
> a) Aligning the next line with the first argument by inserting a few spaces after the tabs - as in:
>
> dma_unmap_page(&adapter->pdev->dev,
> dma_unmap_addr(rx_page_info, bus),
> adapter->big_page_size, DMA_FROM_DEVICE);
My preference as well, but your example may not be correct.
I think this better:
1 2 3 4 5 6 7 8
12345678901234567890123456789012345678901234567890123456789012345678901234567890
dma_unmap_page(&adapter->pdev->dev, dma_unmap_addr(rx_page_info, bus),
adapter->big_page_size, DMA_FROM_DEVICE);
maximally fill to 80 cols, then wrap with maximal tabs using spaces
if necessary to align args after opening parenthesis.
In this case, 2 tabs, 7 spaces.
It is your code though, do what you think best.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: coding style question on indentation
2011-07-01 15:23 ` Joe Perches
@ 2011-07-05 19:54 ` Chris Friesen
2011-07-05 20:01 ` Joe Perches
0 siblings, 1 reply; 5+ messages in thread
From: Chris Friesen @ 2011-07-05 19:54 UTC (permalink / raw)
To: Joe Perches; +Cc: Sathya.Perla, netdev
On 07/01/2011 09:23 AM, Joe Perches wrote:
> I think this better:
>
> 1 2 3 4 5 6 7 8
> 12345678901234567890123456789012345678901234567890123456789012345678901234567890
>
> dma_unmap_page(&adapter->pdev->dev, dma_unmap_addr(rx_page_info, bus),
> adapter->big_page_size, DMA_FROM_DEVICE);
>
> maximally fill to 80 cols, then wrap with maximal tabs using spaces
> if necessary to align args after opening parenthesis.
> In this case, 2 tabs, 7 spaces.
I think the most flexible is to use hard tabs to align the continued
line to the same level of indentation as the parent line, then use
spaces for "pretty" alignment. That way, it all lines up regardless of
how many spaces the viewer has set for the equivalent size of hard tabs.
Chris
--
Chris Friesen
Software Developer
GENBAND
chris.friesen@genband.com
www.genband.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: coding style question on indentation
2011-07-05 19:54 ` Chris Friesen
@ 2011-07-05 20:01 ` Joe Perches
0 siblings, 0 replies; 5+ messages in thread
From: Joe Perches @ 2011-07-05 20:01 UTC (permalink / raw)
To: Chris Friesen; +Cc: Sathya.Perla, netdev
On Tue, 2011-07-05 at 13:54 -0600, Chris Friesen wrote:
> On 07/01/2011 09:23 AM, Joe Perches wrote:
> > I think this better:
> > 1 2 3 4 5 6 7 8
> > 12345678901234567890123456789012345678901234567890123456789012345678901234567890
> > dma_unmap_page(&adapter->pdev->dev, dma_unmap_addr(rx_page_info, bus),
> > adapter->big_page_size, DMA_FROM_DEVICE);
> > maximally fill to 80 cols, then wrap with maximal tabs using spaces
> > if necessary to align args after opening parenthesis.
> > In this case, 2 tabs, 7 spaces.
> I think the most flexible is to use hard tabs to align the continued
> line to the same level of indentation as the parent line, then use
> spaces for "pretty" alignment. That way, it all lines up regardless of
> how many spaces the viewer has set for the equivalent size of hard tabs.
True, but none of the common editing tools do this.
You could produce and publish emacs/vi modes for this
and then teach checkpatch to understand this mode and
not complain about the spacing if it matters that much
to you.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-07-05 20:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-01 11:20 coding style question on indentation Sathya.Perla
2011-07-01 11:52 ` Ben Hutchings
2011-07-01 15:23 ` Joe Perches
2011-07-05 19:54 ` Chris Friesen
2011-07-05 20:01 ` Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).