Re: On Tabs and Spaces
- From
Nikolai Weibull <now@bitwi.se>
- Date
- Oct 17, 2007, 10:21 UTC
- Message-ID
- <dbfc82860710170321l458ebd1cr6bf619cef9bb7300@mail.gmail.com>
- In-Reply-To
- <E29971BA-7306-4570-8383-26D0C9C0B814@mit.edu>
On 10/17/07, Michael Witten <mfwitten@mit.edu> wrote:
Show 30 quoted lines
>
> On 17 Oct 2007, at 3:17:08 AM, Luke Lu wrote:
>
> > But I still haven't seen any compelling arguments against the "all
> > space" case
>
> Overhead!
>
> If you use 8 spaces instead of one tab,
> that's using up 7x more space!
>
> Consider:
>
> # calculates the extra space required to
> # use the given number of spaces/tab.
> size()
> {
> count=`grep -RIo "\`printf \"\t\"\`" . | wc -l`;
> perl -e "print $count*$(($1-1))/1024/1024 . \" MB\n\"";
> }
>
> Then in in a git working tree:
>
> size 8; # 1.28701210021973 MB
> size 4; # 0.551576614379883 MB
>
> In a linux kernel working tree:
>
> size 8; # 61.4902725219727 MB
> size 4; # 26.3529739379883 MBAs already pointed out, this isn't the true waste. Run the following Ruby script to determine the true waste:
------------ cut here ----------- TabWidth = 8
actual_size = 0
expanded_size = 0
ARGF.each_line do |line|
width = 0
line.each_byte do |byte|
width += (byte == ?\t) ? (TabWidth - (width % TabWidth)) : 1
end
actual_size += line.length
expanded_size += width
end
puts (expanded_size - actual_size).to_s
------------ cut here -----------This will give you the actual space waste. Run it like so:
% ruby space-waste.rb /usr/src/linux/**/*.[ch]
(or in a similar manner that doesn't fail due to going over the maximum command-line limit).
According to this calculation the waste is 47808782 bytes, or about 45.6 MiB, for 8-spaces-wide tabs.