new book

Oct. 11th, 2006 02:30 pm
hugme: (RG - gravity reverse)
[personal profile] hugme
I just read 'wicked cool shell scripts' and there is really nothing wicked or cool about it... it's crap

it's presented in an advanced format... so you want to be a pretty decent shell scripter already if you want to read it... but the scripts themselves are very basic.. nothing special. no awesome commands, no neat options... just very basic scripts that any 1/2 way decent scripter could figure out before they could copy it from the book

On top of that the author Dave Taylor has some really bad scripting habits... one of my big pet peeves is this:

grep foo | awk '{ print $bar }'

ok, what you are doing is searching for something then reformatting it with awk. you are running a program, taking it's output and passing it to system memory, then running another program and handing it that output... what a fucking waste of resources considering awk has a BUILT IN SEARCH naively!!

look:

awk '/foo/ { print $bar }'

was that so hard? passing grep to awk is a nasty bad habit... maybe we should rename the book 'nasty bad shell scripts'

here is another bad habit:

if [ foo = bar ] ; then foobar ; fi

ok.. what you have here are 2 if commands... yes TWO!!! the '[' character IS a command. you are wrapping an if around another if. another bad scripting habit... here is what it should look like:

[ foo = bar ] && foobar

much better... only one if command

now you may as "what does it matter.. it's not that much more resources to just do another if command." and you are partially right... if you just run this if command once, chances are you aren't going to see a difference in resources at all. BUT! I have a script that parses text files, there are over 200 files and each file is around 5000 lines... that is around a million lines of code, I have a while loop that runs for each line, inside that loop there were 3 if commands. I thought this would be a good test so those 3 if commands I tried both ways, once with the double 'if' and once with the single... the double 'if' took 16 minutes to run, not bad.. automated script... runs at 3 in the morning.... without the double 'if' commands? three and a half minutes. I write VERY fast code btw ;-)

remember 'while' and 'until' are always faster than 'for' - and 'awk' is powerful but 'cut' is fast...

maybe I should write a shell scripting book... "how not to write shitty scripts" I think that would sell...
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

hugme: (Default)
hugme

April 2011

S M T W T F S
     12
3456789
10111213141516
17 181920212223
24252627282930

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Apr. 8th, 2026 09:51 pm
Powered by Dreamwidth Studios