views:

275

answers:

8

Hello,

I have written a little script which retrieves pictures and movies from my camera and renames them based on their date and then copies them on my harddrive, managing conflicts automatically (same name? same size? same md5?)
Works pretty well.

But this is ONE script.
From time to time I need to check if a picture is already hidden somewhere in a volume, so I'd like to apply the "conflict manager" only. I guess if I had properly followed the unix spirit of tiny single-task tools, I could do that.

What are the best resources, best practices and your experience on the subject?

Thank you.

Edit : Although I'd love to read unix books and have a deep understanding of the subject, I am looking for the Great Principles first. Plus I tend to limit myself to online resources.

+3  A: 

I would look at the book called The Art of Unix Programming.

Kevin
Yeah, really with a question like this, it's who sees it first. Especailly with such an easy answer:)
Kevin
Accursed iPhone keyboard and injured shoulder! :P
Graham Lee
Seems very good indeed (from the preview)
Polypheme
It is an awesome book especially if you are a windows programmer. It really shows how the mentality is different between windows and unix programmers.
Kevin
+2  A: 

Check out this book:

The Art of Unix Programming by Eric S. Raymond

http://www.amazon.com/UNIX-Programming-Addison-Wesley-Professional-Computing/dp/0131429019

Here is his website: http://www.catb.org/~esr/writings/taoup/

Andy White
I'd appreciate it if you'd list title as well as web site information.
David Thornley
Thank you for the online version! (although the charset is broken for me - therefore I'll refer to http://www.faqs.org/docs/artu/ instead. As referred by Bill The Lizard)
Polypheme
+1  A: 

Start with wikipedia (Dataflow programming)

Dutow
interesting, thank you.
Polypheme
Interesting read.
Christian Witts
A: 

- the art of UNIX programming - is quite a nice book ok "the unix way", in so far as one exists. OTOH if the way is "do as little work as gets your job done", you may already be there. :)

Graham Lee
A: 

I think some of the keys for good gnu code, are:

  • Handling the system signals properly, like deattaching hard drive files if SIGTERM is received.
  • Proper use of pipes and standard input/output
  • Follwing common command line flag rules

I would also recommend this book. Pretty old, but I think is quite clear explaining the principles of unix.

alvatar
+2  A: 

I've found that most code doesn't start out being reusable, it evolves to be. Take your existing code and factor out the "conflict manager" portion into its own function or program, then call that program instead of having it be a part of your original application. After that you'll be able to reuse that part of your code that you have a need to reuse. Sometimes it's impossible to design software up front for reusability because you simply don't know which parts you'll want to reuse.

As for resources, it seems like the store shelves are packed with books for Linux desktop users and system administrators, but it's hard to find good Linux programming books. A few good ones:

Lastly, Eric Raymond has made The Art of Unix Programming available online for free.

Bill the Lizard
Thank you for the online version of what seems to be the best book on the subject! Bookmarked!
Polypheme
What's more, I agree with your point of view about "evolving to be reusable", that is precisely my situation here. Been there already, but it's the first time I'm writing a "unix tool".
Polypheme
You can't go wrong with TAOUP. It's one of those classics that gets referred to by its initials. :)
Bill the Lizard
A: 

The book Software Tools (amazon) by Kernighan and Plauger is a classic on this subject. I think it should be required reading for any serious student of software development.

Bryan Oakley
Has it been updated? My copy describes how to build tools nobody would actually build any more in RATFOR (Fortran with a preprocessor to make it look a little like C). While there's a great deal of wisdom in the book, the presentation is lame by modern standards.
David Thornley
Updated? I doubt it. The example language may be old but the algorithms and philosophy are relatively timeless. I remember working through every example both in F77 and C many years ago and it was a very pivotal experience in my career.
Bryan Oakley
+2  A: 

Personally, whenever I see that the script I'm planning to write will be longer than a dozen lines, I use python instead of shell script. One neat trick with python scripting is that it's very easy to program in a style where you create both "unix spirit" command-line tools and libraries. E.g. for your "conflict manager", create a file (python module) and put the functionality in functions and/or classes, and then at the end you can put a python "main" function (the usual if __name__=='__main__': dance) where you parse command line options (use the builtin OptionParser module for this, it's very nice!) and use the functionality in the functions/classes.

This way you can use the utility both as a stand-alone command line program, or you can import the module in another python script and use the functionality defined there via functions/classes rather than parsing input.

janneb