#!/usr/bin/perl -w -i -p
if ( s/^ (\s*) } \s* (els(e|if|eif))\b \s*/$1}\n$1$2 /mxs ) {
s/\s+$//; # Strip trailing whitespace while we're at it
$_ = "$_\n";
}
so now you can just say "./uncuddle `find . -name '*.pm'`"
To be clear what cuddled elses are, it's this:
if ( ) {
...
} else {
...
}
instead of
if ( ) {
...
}
else {
...
}
The key is that having the else outdented shows that it's a point of the flow of control. It all the more important if you get into elsifs.
if ( A ) {
...
} elsif ( B ) {
...
} elsif ( C ) {
...
} else ( D ) {
...
}
instead of the more clear
if ( A ) {
...
}
elsif ( B ) {
...
}
elsif ( C ) {
...
}
else ( D ) {
...
}
Yes, it adds one more line to the screen. I'm OK with that.
To cuddle or not to cuddle (Score:1)
Re:To cuddle or not to cuddle (Score:2)
--
xoa
What convinced you? (Score:1)
But I'm interested in cases where someone gave up a stylistic choice like that, because it may be that there really is a reason to prefer one over the other.
Thanks,
Ben
Re:What convinced you? (Score:2)
--
xoa
Re:What convinced you? (Score:2)
Re:What convinced you? (Score:2)
--
xoa
Re:What convinced you? (Score:2)
Cuddling does gain you a few things (Score:2)
But the code following the condition is indented so I don't see what uncuddling would gain you when it comes to visual clarity. Furthermore, by cuddling them it becomes obvious that the various if/elseif/.../else cases are really part of one bigger statement where only one of the indented code-blocks is ever executed.
Finally, the lines you save by cuddling could make
Re:Cuddling does gain you a few things (Score:2)
Re:Cuddling does gain you a few things (Score:1)
Etymology? (Score:1)
I couldn't find any reference to this use on Wikipedia, M-W or dictionary.com .
Re:Etymology? (Score:1)