Endless Regular Expressions

Regular expressions are an extremely useful tool for processing text. But since a regular expression is a small program that is interpreted or compiled, it requires the same care as other parts of your code. If you're a careful coder, you won't write code that executes endlessly. Neither should you write regular expressions that execute endlessly.

You should avoid the commonly used regular expression operators * and + (which match zero-or-more and one-or-more items respectively). Replace these with length-constrained versions {0, n} and {1, n} where n is some value that is as small as possible while still being large enough for your specific use.

We could say that it's negligent to use * or + in code that operates on untrusted text and leave other uses of * and + to your own good judgement, but that's too complicated for me, so I'll say:

Never use * or +. Replace with length-constrained versions {0, n} and {1, n}.

However, using length-constrained operators is not the only thing to consider when protecting yourself from regular expression denial-of-service (ReDoS) attacks because you can still write expressions that take exponential time even with constrained lengths.

The behavior described in the ReDoS article doesn't just apply when there are malicious actors or when the regular expression is being supplied by a user. For a real-life example of a regular expression performance problem found in normal conditions see Carpe Aqua.

If your regular expression locks up your machine or your regular expression never stops executing or runs endlessly, you can use your understanding of what can cause exponential running time to correct your regex to avoid the bug. Length constraints may help all by themselves if you can create them with n <= 5, but you may also need to adjust the expression.

The workaround used in the Carpe Aqua post is not the right solution to the problem. The regex causing the problem needs to be fixed. The parentheses matching shows classic hallmarks of being an "evil regex" subexpression and there isn't a length constraint that can be applied to the existing expression that will have a small enough value for n such that exponential behavior will cease being a problem. The approach to matching parentheses needs to be removed or replaced. In .NET code a better solution would be to use balancing groups.

Franklin Booth, American Illustrator

Franklin Booth was an American commercial illustrator working in the first half of the 20th Century. He developed his highly detailed pen-and-ink style consisting of thousands of lines of varying thickness and density by copying illustrations he saw in magazines.

Artwork by Franklin Booth

Unknown to him at the time, the style he copied was produced by wood engraving rather than pen-and-ink. Wood engraving was a part of the process for producing prints in that period and the style had developed through a combination of artistic and practical considerations. Booth refined and developed this style in his chosen medium even as the printing technology moved forward.

Booth's art evokes the era in which he lived. Art Nouveau influences are apparent in the sweeping curves of the trees, clouds, and flowing fabrics that are so characteristic of his work. He had a real mastery over the viewer's sense of scale. His figures are often dwarfed by majestic trees, roiling skies, or epic architecture. Lovely.

EB White on Writing Charlotte's Web

Letters of Note has a delightful piece from EB White, the author of Stuart Little and Charlotte's Web, explaining why he wrote the latter:

A farm is a peculiar problem for a man who likes animals, because the fate of most livestock is that they are murdered by their benefactors. The creatures may live serenely but they end violently, and the odor of doom hangs about them always. I have kept several pigs, starting them in spring as weanlings and carrying trays to them all through summer and fall. The relationship bothered me. Day by day I became better acquainted with my pig, and he with me, and the fact that the whole adventure pointed toward an eventual piece of double-dealing on my part lent an eerie quality to the thing.

...

Anyway, the theme of "Charlotte's Web" is that a pig shall be saved, and I have an idea that somewhere deep inside me there was a wish to that effect.

It's a fantastically mature and compassionate view of the relationship between the farmer and the farmed. Not a vegetarian perspective, but far more positive than my excerpt suggests. Go read the whole thing to get a sense of White's joy in the natural world and his respect for spiders.

Netflix for Books? It's Called a Library!

"Wouldn't it be great if there were some kind of Netflix for books? You could just, like, borrow a book and then give it back when you were done reading it so someone else could read it."

"Dude, it's called a library. "

There are public libraries in almost every part of the United States and Europe. They are typically free to sign up, free to check out materials, and have strong privacy controls so that your reading habits are less likely to be exploited. Many libraries provide magazines, CDs, DVDs, Blu-ray, and even streaming media in addition to printed books. A good number provide online reservation systems so that you don't need to spend time searching the shelves. You may need to wait a while for popular new releases to become available, but for a service that is both free and convenient, that's a small price to pay.

Some of my fondest childhood memories come from spending time in the library digging through Asterix and Tintin books.

The Seattle Public Library website is at http://www.spl.org/. There's likely to be an equivalent for the libraries in your area.

Goo Goo Dolls 'Magnetic' Album Cover is a Jony Ive Redesign

Magnetic album cover

Talking of Magnetic, the 2013 album by the Goo Goo Dolls, the album cover artist, Neil Krug, is really plugged in to the zeitgeist. Magnetic looks like a Jony Ive redesign or the poster for the Ashton Kutcher Jobs movie.

Goo Goo Dolls 'Rebel Beat' and Cognitive Dissonance

I've enjoyed the band Goo Goo Dolls since they released their album Superstar Car Wash back in 1993. I bought their 2013 album Magnetic soon after release. It's solid. Particular favorites are Bringing on the Light (by Takac) and Keep the Car Running (by Rzeznik). Overall a nice pop rock rekkid.

There's a lesson in here about consistency and being able to walk it like you talk it though. The opening track and first single 'Rebel Beat' has the chorus:

Hey you, look around!

Can you hear that noise? It's a rebel sound.

We got nowhere else to go.

And when the sun goes down, and we fill the streets,

You're gonna dance 'til the morning to the rebel's beat.

Sets up some expectations about the music doesn't it? The song better have some of that rebel sound to back up the lyric. Unfortunately, Rebel Beat is firmly at the pop end of the pop rock spectrum. Slickly produced and commercial, it's anything but rebellious. In this case, the lyric spoils a nice tune by creating cognitive dissonance. The music claims one truth and the lyric claims another. They can't both be true. It's uncomfortable to be asked to believe two contradictory notions.

Cognitive dissonance is a powerful force in all areas of life. We look for consistency and honesty everywhere. Confounding someone's expectations is painful to them. You can make perfectly good tea taste terrible by serving it to someone that's expecting coffee. When designers talk about honesty, they're talking about confirming users' expectations and minimizing cognitive dissonance, so that their product feels and tastes good. Get it wrong and you can taint an experience in a way that's hard to recover leaving a user confused and uncomfortable like a robot on the verge of self destruction.

"Rebel Beat ... does ... not ... compute ..."

In this case, the song could have been fixed with a relatively small lyric change prior to release.

Sissinghurst Castle Garden

Sissinghurst Castle Garden is an amazing work of art located in the south-east of England. It was planted in the 1930s on the site of a dilapidated manor house. The garden is designed as a series of rooms. Beautiful brick walls separate planting areas designed around different themes and seasons. An open doorway acts as a frame for the view beyond as well as providing access to the next open air room. A high, central tower allows an aerial view of the entire site.

Sissinghurst

The plantings are exquisite, but for me the thing that makes Sissinghurst so special is the integration between the natural and the manmade. The built structures are in perfect balance between solidity and disrepair.

The exterior walls, gatehouse, and central buildings are robust, regular, and sound despite dating back to the 1500s or earlier.

The inner garden walls are of various heights, without roofs, have footings obscured by shrubs and flowers, and serve as support for climbing plants. In many cases they seem as organic as the foliage that surrounds them.

Sissinghurst wall and clematis

The garden walls denote age, but not decay. Although they provide a reminder of the larger building of which they were once a part, they create a sense of optimism, not loss. The walls are more beautiful for their close contact with nature and seem all the stronger for shedding the burden of their roofs. Rather than being constructed they grow from the ground like the plants they shade, frame, and support.

Olive Almond Feeds

You can find a feed containing the newly published content from Olive Almond at http://www.olivealmond.com/index.xml

Feed icon

Just add the Olive Almond feed to the list of feeds in your feed reader and you'll have access to the same content that's on the website, but in a more convenient form. You won't miss any updates to the site.

To read the feed, you need an app called a 'feed reader' (also known as a 'news reader' or an 'RSS reader').

A feed reader is like a super-efficient web browser. It remembers the sites that you like, lets you know when they've been updated, and remembers which items you haven't got around to reading yet. High quality feed reader apps can download the new and updated information automatically and let you read the articles even when you don't have an internet connection. These are known as 'offline feed readers'.

I highly recommend using an offline feed reader to read Olive Almond and any other web site that interests you. Once you're used to the convenience of an offline feed reader, it's hard to read a web site any other way.

If you need to see what feeds are available on other sites, or you need keywords to help you find feed reader apps and services, look for the words 'feed', 'news feed', 'web feed', 'info feed', 'RSS', or 'Atom'. (RSS and Atom are the main data formats for feeds). Or look for the feed symbol: a dot with two concentric quarter circles that typically appears in white on an orange or red background.

About Olive Almond

Greetings! I'm a designer at Callionica, a small software company based in Seattle.

Information icon

This blog isn't about design - although I'll spend time talking about that. And it's not a blog about technology - that's just one of my core interests.

The Olive Almond website is really about relationships. It's about the connection each of us has to the natural world, the associations we form with each other, our interactions with the society in which we live, and the artistic influences that shape us.

Enjoy!