[Rear-users] bash style

Schlomo Schapiro schlomo at schapiro.org
Tue Jun 21 18:37:46 CEST 2011


Hi Dag,

congratulations, you convinced me!

Am 19.06.2011 13:48, schrieb Dag Wieers:
> On Sun, 19 Jun 2011, Schlomo Schapiro wrote:
> 
>> I am really against using [[ ]] in places where it behaves like [ ].
>> The reason
>> for that is that [[ carries the danger of unplanned pattern matches.
>> And [[ code
>> && code ]] is not a reason to change [ code -a code ], it adds no
>> benefit and
>> even carries the risk of confusing the && within the [[]] with the &&
>> that can
>> be normally used.
> 
> [[ is faster than [ or test. What's more it offers more possibilities
> (like pattern matching) and it supports overriding normal precedence
> (using '( )') which [ or test make this very awkward.

sschapiro at dev4003:~$ time for (( k=1 ; k<1000000 ; k++ )) ; do [ $k -gt
500 ] ; done

real    0m21.427s
user    0m20.881s
sys     0m0.512s
sschapiro at dev4003:~$ time for (( k=1 ; k<1000000 ; k++ )) ; do [[ $k -gt
500 ]] ; done

real    0m13.286s
user    0m12.833s
sys     0m0.436s
sschapiro at dev4003:~$ time for (( k=1 ; k<1000000 ; k++ )) ; do (( k >
500 )) ; done

real    0m13.905s
user    0m13.525s
sys     0m0.348s


I actually was surprised...

> 
> If we are only considering bash programming, it's _the_ choice for doing
> testing (together with arithmetic testing using '(( ))'). Most of the
> bash programming guides actually advise to use [[ ]] and (( )) constructs.
> 
>     http://mywiki.wooledge.org/BashPitfalls
>     http://mywiki.wooledge.org/BashFAQ/017
>     http://mywiki.wooledge.org/ArithmeticExpression
> 
> But as always, one needs to know what one is doing.

Yes, definitively. Thanks a lot for providing these links.

> 
> 
>> Even though it is against my personal taste I am ready to go over that
>> and use [
>> over test, IF the majority of the list prefers it that way.
>>
>> Also, please use tabs and not spaces.
> 
> Once again this is something Jeroen and I see differently, the use of
> tabs is very irritating, especially if you want to do proper and
> consistent indentation. I would advise to use the following vim options:
> 
>     set tabstop=4
>     set shiftwidth=4
>     set expandtab
>     set listchars=tab:»·,trail:·
>     set list

OK, I am also ready to go with this. With vim I actually have one
remaining problem: When I paste somthing indented with the mouse lines
get stupidly indented and look like a staircase. Apparently when pasting
with the mouse each indent adds up to the previous indent. Any ideas?

> 
>     http://www.jwz.org/doc/tabs-vs-spaces.html
>     http://www.iovene.com/61/
> 
> Tabs vs spaces is a discussion that's as old as computers.

I know and thanks for providing these links, they helped.

Kind Regards,
Schlomo

PS: Feel free to commit your long-waiting convert-all-tab-to-spaces
patch... :-)




More information about the rear-users mailing list