Regular Expressions Cookbook and Mastering Regular Expressions

I have a copy of Mastering Regular Expressions by Jeffrey E. F. Friedl on my bookshelf. I bought it a long time ago to try to improve my skills at using regular expressions to search text and check input against desired norms. While that book is clear and well written, I am sometimes a bit impatient and it was taking too long for me to figure out how to do the things I wanted to do and I got distracted or busy before I read enough to complete the task (I ended up using Google and finding what I needed quickly). I have to admit that I still don’t have the regular expression skills I want to have, although this book promises to teach them to me. Someday it may do so.

When I heard that O’Reilly had an upcoming regular expressions offering to add to their Cookbook series, I was interested, but was finishing up my own title in the series. Once my task was finished, I talked to some friends at the publisher and they kindly sent me a review copy of Regular Expressions Cookbook by Jan Goyvaerts and Steven Levithan. Now that I have had time to read through the book, I can say that it exceeds my expectations and hopes.

What I was looking for was a book that would teach regular expressions while giving concrete examples of real life use cases that I could immediately put to work. This book is filled with them.

Chapters one and two lay the foundation by covering the basics of what regular expressions are, using them to search and replace, match text, and other basic skills. This is good, but where the book really sets itself apart is in chapters three through eight, which are overflowing with useful recipes for things like validating ISBNs, finding URLs within text, stripping leading zeros or matching IP addresses (IPv4 and IPv6). The book has an obvious organization scheme, a ton of useful recipes, and a useful index. Finding what you want or need is very easy to do, and unless your needs are especially unique or esoteric, you will probably discover exactly what you require in the book.

The best part of the book is that every example uses a clear format that sets the stage for an easy discovery of needed information.

First, a problem is stated, such as in chapter four’s item, 4.1 Validate Email Addresses, which says, “You have a form on your website or a dialog box in your application that asks the user for an email address. You want to use a regular expression to validate this email address before trying to send email to it. This reduces the number of emails returned to you as undeliverable.”

Next, a solution is defined, with code examples, accompanied by a description of the particular details that are vital to comprehend when implementing the solution. Next, each recipe has a section for further discussion that leads to a deeper understanding of the regular expression being used and the context in which it is being used.

Especially wonderful is that every recipe has very specific and clear code examples for use with Perl, PCRE (the “Perl Compatible Regular Expressions” library for C, which isn’t identical to Perl’s use of regular expressions, even though it tries), .NET, Java, JavaScript, Python, PHP, and Ruby with notes on which specific release versions or variations of each are covered. When differences exist in the implementation in these environments, those differences are clearly noted and discussed. This feature will make life much easier for people who need to use regular expressions in more than one language context and is a feature of the book I appreciate greatly.

The other regex book on my shelf will remain there until that mystical moment “when I have time to study it.” This book will be used regularly as a reference.

Disclosures: I bought my copy of Mastering Regular Expressions, but was given my copy of Regular Expressions Cookbook free by O’Reilly as a review copy, I also write for O’Reilly and have a book in their Cookbook series.

Footnotes in Gaza

Henry Holt and Company recently sent me a complementary advance, prepublication review copy of Joe Sacco’s history in graphic novel format Footnotes in Gaza.

This may be one of the most heart-wrenching books I have ever read. This well-researched history relies on both interviews with eyewitnesses and official documents to provide the information for its powerful telling of a bloody event in 1956 in Gaza when 111 Palestinians were shot dead by Israeli soldiers and many others wounded and scarred. Some call it a massacre, others a dreadful mistake. No one disputes the number of dead nor the painful events of one incident in a long and difficult struggle.

This book is written from the perspective of a historian who is seeking the facts of an event that happened a full 50 years before the research began and shows his struggles with differing accounts, even from people on the same side of the conflict, and the difficulty, or perhaps impossibility, of separating the events of previous generations from the events of the current day. The people involved are human, fallible, full of pain and longing for safety, security and a life of peace.

To tell the story, Joe Sacco uses powerful drawings and shows an impressive understanding of the comic/graphic art style. Every word and image are vital. Not one moment of the reader’s time is wasted. My full attention was on the book from the moment I picked it up until I (grudgingly) had to put it down to do something else. This was true until I finished reading the final page. The author spent a significant amount of time in the Gaza Strip, living in refugee camps and towns with Palestinians. He conducted many interviews and took hundreds of photos while staying in people’s homes and walking the very streets where the events occurred. This dedication shows in the final project which is written and drawn with a voice and perspective that is unparalleled in my research on the region (which is extensive).

This, and other events in the region, deserve far more attention than they receive, but not merely from the angle of politics and warring opinions. These are not covered in this book. Rather, what needs to be seen and understood is how real people and their lives are affected. This book shows that in a way that never succumbs to sappy attempts to provoke pity. It is a dispassionate and clear sharing of personal memories from diverse sources of one main event, often pointing out moments of disagreement or comments that could not be corroborated. It is the events, not any attempt to manipulate the reader, which provokes the response.

If you only read one book about history and foundations for current day conflicts in the Middle East, read this one. I give it my highest recommendation. I will also warn you that it is the first book in a very long time that genuinely moved me to tears, so be prepared.

The Book of Genesis Illustrated by R. Crumb

After my review of another of their books, I asked W.W. Norton & Co., Inc. to send me a review copy of The Book of Genesis Illustrated by R. Crumb. They didn’t respond. However, I saw the book in a bookstore and was so impressed that I went ahead and bought it for myself.

There are two notes on the cover that immediately grab attention.

The first says “adult supervision recommended for minors,” and I agree, at least as far as younger kids go, solely because the book of Genesis itself is filled with stories and themes that children will not fully comprehend or that they are not developmentally ready to deal with, just as a parent wouldn’t let a child watch an intense movie alone or perhaps at all while they are young, something like Schindler’s List for example, because there are things they don’t need to confront or know about quite yet. That doesn’t have anything to do with the quality of the content. There is also some nudity and violence in the book, and although it is of the pen and ink comic illustration variety and merely illustrating what is clearly described in the text, some may not be comfortable with children seeing it in some of the contexts in this narrative.

The second note says “the first book of the Bible graphically depicted! Nothing left out!” This is the first time I have ever seen a graphic version of any portion of the Bible that both included the complete text and also chose not to add anything like dialogue to “help the narrative” or “assist comprehension.” As a result, there is no editorializing whatsoever, neither positive nor negative. The text is presented as it is with illustrations along the way.

I have a feeling that religious people could be offended because R. Crumb is known not to be a religious person. Those fears are not well founded as this text is treated respectfully and with no sense of judgment or editorial comment whatsoever implying anything negative about any belief system. What is presented in the illustrations is what is clearly stated in the text.

It is just as likely that non-religious people could be offended because an illustrator and artist of such quality and stature has chosen a religious text as his subject matter. Those fears are not well founded as this text is stated to have been chosen because of its historical importance and with no sense of judgment or editorial comment whatsoever implying anything positive about any belief system. What is presented in the illustrations is what is clearly stated in the text.

For many readers, the most important facet of this review is the question of whether this work stands up as a piece of art. I wholeheartedly believe it does. Some may not prefer R. Crumb’s style, and this is a pretty typical example of what he has focused on doing for years, but I don’t think anyone could complain that he has not done it well. The illustrations are focused, clear, emotive, and powerful. At times he demonstrates his cultural perspective as a modern-era westerner and some of the motifs are almost clichéd (eg. God is pictured as an old man with long white hair and a flowing beard wearing a white robe, almost Gandalf the White like, but with more hair, a bigger beard, and a larger halo of light around him), but those are the exception, and they don’t progress from overused but commonly understood symbols into caricature or parody. Most of the time the illustrations are interesting with what appear to be culturally appropriate styles of dress and terrain. The bottom line for me is that the illustrations never detract from the story; they add to it by making things more clear.

This is one I will definitely recommend, but in the case of children, only with parental consent.

Nelson Mandela: The Authorized Comic Book

I had very high hopes for this official history of a well respected world leader. The publisher, W.W. Norton & Co., Inc. sent me a review copy last fall and I was immediately impressed with the artwork. Unfortunately, I wasn’t as impressed with the writing.

The history contained in the book is accurate to the best of my knowledge, and Mandela’s life is certainly interesting enough for me to force my way through reading the entire book, but the narrative style is dull and unsuited to the graphic novel format, where one could tell the story much more effectively using images and dialogue instead of treating the artwork as mere illustrations to accompany walls of text.

The bottom line here is that if you are looking for a biography of Nelson Mandela that has good information and nice illustrations, this book is worth your time. If you are looking for a quality graphic novel, using the criteria generally considered for rating items in that format, you will be disappointed. The quality of the art is better than adequate, good even, but the failure to truly adapt the narrative style to the format being used was disappointing. I am glad I read the book for the history it contains, but I ended up giving my copy away after I read it as it is highly unlikely I would read it twice.

Dove & Snake Giveaway

A little while ago I allowed a chapter from one of my books to be reposted in the most recent edition of an independent art and culture ‘zine from Tucson called Dove & Snake.

As a thank you, I have been allowed to offer a free copy of the issue to one of you, my blog readers. I’m not good at contest creation, so I’ll keep this simple. The person whose comment I deem the wittiest will receive a free copy. The comment must be made directly on this blog, not on a site that syndicates my posts like Facebook or LinkedIn or something else, and must be made no later than Wednesday, December 9th at the totally random time of 12 noon my local time. I will choose my favorite and will contact that person directly to get mailing address details (so be sure to use a real email address when you comment if you want to be considered).

So, have at it. The funnier the better. You may post an anecdote, a joke, an observation, or whatever comes to mind as long as it is family/work safe.

Learning Python, fourth edition

Years ago I purchased a copy of the very first edition of Learning Python.It was a small book, about 350 pages, but in 1999 when it came out, it was one of the best introductions to the language that existed. I hadn’t picked up my copy for some time, but I remember well how useful it was when I first bought it. When O’Reilly offered me a free review copy of Learning Python, fourth edition, I figured the differences between the two editions would primarily consist of updates to the content based on the differences in Python release versions, and that I wouldn’t likely learn much more from the new edition. I was wrong, and I will explain how and why below.

This book is HUGE. It weighs in at over 1100 pages and is filled with clear explanations, interesting history, and the most useful description of the foundations of the Python programming language that I have seen. The material was developed by the author, Mark Lutz, over the last decade, during which he has taught hundreds of seminars introducing Python. Lutz compiled the new edition based on the materials taught in a three day training class, complete with quizzes and meaningful exercises. While Lutz was one of the two original authors of the first edition, he is now the sole author of the book and it is obvious that his extensive experience teaching seminars has refined his presentation of Python in ways that will benefit readers of this book. The understanding of student needs shows clearly in the text, which focuses on the core of the language.

Learning Python is based on the new 3.x series of the Python language, but points out the differences between it and the still-supported and sometimes incompatible earlier 2.6 edition, so whichever version of the language you are learning or require you will find the information you need to begin here. Some may ask why cover the old version when the new one has so many improvements, but the answer is simply that there is a lot of legacy code that is not going to be updated soon and so people will need to support that code, which is often incompatible with Python 3.x without some changes.

The book covers many topics, none of which seem unimportant or superfluous. While the page counts seems quite daunting, a closer examination shows there is no need to be intimidated. The page count does not add complexity or difficulty, but actually gives room for clearer and more complete descriptions and definitions alongside practice questions that students will find very useful. The topics include all of the obvious foundational needs starting with history, how to run programs and use some common editors. It moves to core data types and operations, spending several pages clearly defining and describing each and how they are used, before introducing statements and syntax on page 261. I like how the differences between 2.6 and 3.x are clearly shown, such as the change from a print statement in 2.6 to a print function in 3.x and how either is implemented and used as well as the reasoning behind the change. Functions are introduced and discussed, as are modules, classes, object oriented programming, exceptions, and several advanced topics. There are two appendices covering installation and configuration and giving the solutions to the exercises in the book

It has been a long time since I did any programming. My life took a different path. This book has reminded me of how fun it is to write and read code in Python and made me wonder how I might find or create opportunities to return programming to my busy life (but this time around, if I make the time to write anything, it will be in Python 3.x). This book is why.

Lutz has also authored O’Reilly’s Programming Python, which was explicitly designed to be a follow up text to this one, which I have read and which also sits on my bookshelf, but which I have not reviewed (I bought that one a couple years ago and at the time was not writing book reviews.–if there is interest, I’ll review it at a later time).

Disclosures: I bought the first edition, but was given this fourth edition free by O’Reilly as a review copy, I also write for O’Reilly.