Archive for the 'Technology' Category



Regex syntax and semantics varies

Regex engines do differ in syntax and semantics. This is one reason why you can’t just find an expression with Google and use it in your code – without fully understand it.

Try for example the following in JIRB, the interactive JRuby tool:

irb(main):001:0> require 'java'
=> true
irb(main):002:0> java.util.regex.Pattern.compile("a$").matcher("a\nb").find
=> false
irb(main):003:0> "a\nb"[/a$/]
=> "a"

What happened?

The regex /a$/ matches the letter a just before something checked by a dollar sign assertion. The assert criteria is, by default, not the same in Ruby and Java. In Java, by default, the dollar sign matches at the end of the whole text and before any final line breaks. In Ruby, the dollar sign match at the end of every single line.

Here’s what the three lines of code above means:

  1. First, we need to include the Java libraries by writing require 'java'. This might not be necessary, depending on your setup.
  2. We compile a Java regex and test if part of the string of ‘a’ and ‘b’ with newline in-between can be matched. It can’t.
  3. We compile the same regex in Ruby and test if part of the string of ‘a’ and ‘b’ with newline in-between can be matched. It can.

This is just one of many examples. If you are going to use regexes in your program, you need to understand them. It’s as simple as that.

Pomodoro Technique Illustrated -- New book from The Pragmatic Programmers, LLC

Regex slides

Slides from my regex session at Turku Agile Day are now available below and at Slideshare:

If you can’t see the whole picture due to Slideshare’s embed limits, click ‘zoom’ -> ‘zoom to page’ in the Slideshare tool bar above.

What constitutes a Timebox, anyway?

What constitutes a Timebox, anyway?

I use the term Timebox when the following applies:

  1. I determined beforehand a particular point in time when it starts.
  2. I determined beforehand a particular point in time when it ends.
  3. I determined beforehand a particular activity that I will focus on.

A successful Timebox is when I start at the time that I had determined (1), end at the time that I had determined (2) and only focus on the task that I had determined (3). As Timebox considered, it is irrelevant what, how much and with what quality I produce.

There are alternatives to limit the time.

  • We can restrict the scope: pick blueberries in the woods until the bucket is full.
  • We can limit the quality: search the greengrocery until you have found a really good tomato.
  • We can limit the cost: shop christmas gifts until your wallet is empty.

All four approaches have pros and cons.

Pomodoro Technique Illustrated -- New book from The Pragmatic Programmers, LLC

Recursive Regexes

Oniguruma supports recursive regular expressions. They can e.g. be used for matching a generative grammar like the following:

  1. expression -> expression + term
  2. expression -> expression - term
  3. expression -> term
  4. term -> ( expression )
  5. term -> digit

I wrote the following regex that corresponds to the grammar above:

  • /^(?<expression>(?<term>\d|\(\g<expression>\))([-+]\g<expression>)?)$/

Note that \g<expression> is invoked recursively – like rule number 4 in the grammar. I chose to only allow single digit numbers to make the expression crisper as example. This could of course easily be changed to general integers, floats or imaginary numbers.

Here goes some testing:

irb(main):001:0> r = /^(?<expression>(?<term>\d|\(\g<expression>\))([-+]\g<expression>)?)$/
=> /^(?<expression>(?<term>\d|\(\g<expression>\))([-+]\g<expression>)?)$/
irb(main):002:0> "2+4"[r]
=> "2+4"
irb(main):003:0> "2+45"[r]
=> nil
irb(main):004:0> "2-3(4+3)"[r]
=> nil
irb(main):005:0> "2-3(+3)"[r]
=> nil
irb(main):006:0> "2-31(+3)"[r]
=> nil
irb(main):007:0> "2-3+(+3)"[r]
=> nil
irb(main):008:0> "2-3+(4+3)"[r]
=> "2-3+(4+3)"

Expressions that return nil are obviously not correct.

Pomodoro Technique Illustrated -- New book from The Pragmatic Programmers, LLC

Regex process: Copy-Paste-Generalize

Regular Expressions is a flexible tool for matching strings of text. They can be really crisp and elegant, but how can you design them? Below is a design process.

Name

Copy-Paste-Generalize

Intent

Go from an idea to a flexible and generalized regular expression.

Applicability

You have a text example and you know what you want to extract. But, of course, you want your regular expression to be generalized enough to match other candidates.

Consequences

The Copy-Paste-Generalize pattern is easy to get you started and then you can develop your regular expression in an iterative and structured way.

Mechanics

  1. Copy a text example
  2. Paste it as your initial regular expression
  3. Generelaize the expression step by step until it matches any possible candidate

Other Names

This process has many names. E.g. Mehran Habibi call something similar “The Pull Technique” in his book Java Regular Expressions.

Example

Pomodoro Technique Illustrated info page at Amazon.com

Pomodoro Technique Illustrated info page at Amazon.com

Amazon.com presents a sale rank of all books. The list is updated frequently and every book’s current rank can be found at the book’s info page. Suppose I want to match the current rank for my book Pomodoro Technique Illustrated. First I download an example text: the current page at Amazon:

  • lynx -dump http://www.amazon.com/Pomodoro-Technique-Illustrated-Minutes-Pragmatic/dp/1934356506

I use Lynx (btw: by far the greatest web browser the world has ever seen) in CLI mode. The result is a rain of lines from Pomodoro Technique Illustrated‘s info page at Amazon. I better grep something to make my example text smaller:

  • lynx -dump http://www.amazon.com/Pomodoro-Technique-Illustrated-Minutes-Pragmatic/dp/1934356506|grep -i rank

The result is:

  • * Amazon Bestsellers Rank: #23,032 in Books ([89]See Top 100 in

Great! This includes what I want to match. What I’ve done so far is the Copy part of this process. Next goes the Paste. I add an extremely simple Regular Expression and put it in a Ruby one-liner:

  • lynx -dump http://www.amazon.com/Pomodoro-Technique-Illustrated-Minutes-Pragmatic/dp/1934356506 | ruby -pe 'puts $1 if $_[/Bestsellers Rank: #(23,032) in Books/]; next'

As a matter of fact, the expression that resides between the dashes is just a Paste of what I got from the Lynx dump. And the result of this line is:

  • 23,032

…and that’s because of the parenthesis.

Copy done. Paste Done. Let’s start to generalize. Next time I run this, I might get another rank than 23,032. Digits can be captured with the meta sequence \d. This implies the next iteration:

  • lynx -dump http://www.amazon.com/Pomodoro-Technique-Illustrated-Minutes-Pragmatic/dp/1934356506 | ruby -pe 'puts $1 if $_[/Bestsellers Rank: #(\d\d,\d\d\d) in Books/]; next'

Instead of cascading the \d, I can use the limiting repetition operator:

  • lynx -dump http://www.amazon.com/Pomodoro-Technique-Illustrated-Minutes-Pragmatic/dp/1934356506 | ruby -pe 'puts $1 if $_[/Bestsellers Rank: #(\d{1,3},\d{3}) in Books/]; next'

The text in between “Rank” and the number may change. It would be more robust to describe it as non-digits:

  • lynx -dump http://www.amazon.com/Pomodoro-Technique-Illustrated-Minutes-Pragmatic/dp/1934356506 | ruby -pe 'puts $1 if $_[/Bestsellers Rank[^\d]*(\d{1,3},\d{3}) in Books/]; next'

This expression will only work when the rank is between 1,000 and 999,999. Just in case this book gets extremely popular, let’s generalize the number part:

  • lynx -dump http://www.amazon.com/Pomodoro-Technique-Illustrated-Minutes-Pragmatic/dp/1934356506 | ruby -pe 'puts $1 if $_[/Bestsellers Rank[^\d]*([\d,]*)/]; next'

The expression has become pretty compact and robust. I stop here:

  • Bestsellers Rank[^\d]*([\d,]*)

Challenge

Even though it’s only a example above, you may know how to make the Regular Expression or the Ruby/Bash code even more crisp. If you do, feel free to append a comment below.

Pomodoro Technique Illustrated -- New book from The Pragmatic Programmers, LLC

Do you ALWAYS respect the timebox?

Timbox and Flow

Timbox and Flow

Hi Staffan! Do you ALWAYS respect the 25 minute timebox when you’re in the zone? Can’t this break your flow?

Yes, I always respect the timebox:

  • A short break won’t make me forget everything. I can go on from exactly the point where I left.
  • The break means that I can recharge my brain. Goal free play encourages background processing and right brain thinking. If I put enough effort in last iteration, it will even be guilt free play, which helps me avoid procrastination.
  • Humans love rhythm. From the day we were born to the day we die, our life is filled with rhythms. They make us feel safe and helps us to have sustainable pace.
  • Flow means totally focused on one task. It doesn’t necessarily mean that I’m doing the most important task. Sometimes flow means efficiency, without effectiveness. To recurrently take a short break and then asses if I’m doing the most important thing will help me navigate in task land.
  • When I’m in the flow, I’m so focused so I’m not really aware that I’m in the flow. When the timebox is finished, it’s impossible to immediately say if I should continue or not.
  • To take a break when arousal is high, makes me eager when it’s time to start the next timebox.

Am I supposed to focus now?

Do you have trouble remembering if you’re in a Pomodoro or not? If you use a mechanical kitchen timer, the ticking sound will remind you. But what if you work in a no-sounds-allowed office?

This is actually a very common problem. Even if you can’t have the ticking sound and the mechanical timer, I do believe that gestures are important. They help your brain to make the transition from free time to focus time and back.

You may put your cell phone on the desk every time you start a Pomodoro and remove it when you end. Or even simpler: take a business card and color it green on the backside with a felt-tip pen. Put the card on your desk. Every time you start a Pomodoro, turn the green side up. Every time you end a Pomodoro, turn the green side down.

  • You can see the card/phone while you’re in a Pomodoro. It reminds you that it’s focus time.
  • The gestures of turning the card will—after a while—be associated with starting and ending a Pomodoro.

Pomodoro Technique Illustrated -- New book from The Pragmatic Programmers, LLC

Po and crazy aunt at software development office

Convergent thinking: Our experiences help us to solve familiar problems. We use logical thinking to find a suitable solution in an efficient way. Unfortunately, our experiences are limited. They are not sufficient to solve all possible problems. When we lack relevant experience, they can instead become a barrier that prevents us from thinking outside the box.

Divergent thinking: With creative thinking, you generate ideas that are not based on your experiences. You don’t judge ideas while you generate them. Then when you have enough good ideas, you use your logical thinking to categorize, judge and prioritize them. But how can you generate ideas that are free from your experiences?

Po: provocative operation

Edward de Bono’s Lateral Thinking technique includes the concept Po. A Po is an idea which moves thinking into new unknown territory. You make a statement and see what the consequences are. The syllable “po” is found in English words like suppose, possible, and hypothesis—words that point forward. De Bono says that provocation goes hand in hand with movement and that’s why Po also can mean provocative operation. With Po you release all the crazy ideas:

  • Po cups have holes in their bottom
  • Po customers will have yellow t-shirts
  • Po blogs don’t have letters

Instead of judging the value and realism in a Po statement, you look for what is interesting about it, what is different in it and what this idea might lead to. Perhaps the crazy idea is a stepping stone to something new and successful.

Atelierista: the crazy aunt

Reggio Emilia is an Italian pedagogy for preschools. Every Reggio preschool has a centrally located place called Atelier. It is a place for experimentation and discovery. What makes Atelier so unique in child pedagogy is the person who works there: the Atelierista—a practicing artist. She has no training in pedagogy; she does not even work as a teacher. Think of her as the crazy aunt. She does things in a way that you really wasn’t taught to do.

“Creativity seems to emerge from multiple experiences, coupled with a well-supported development of human resources, including a sense of freedom to venture beyond the known”, wrote Reggio’s initial idea blacksmith Loris Malaguzzi. What workplaces can see the value in hiring people without any clear relation to the services or products produced—someone who is at the office only to inspire and create new ideas?

Consider this statement. Is it possible in your workplace?

  • Po software development companies has an Atelier with a Atelierista—a practicing artist, without knowledge of software development. She shows us crazy ideas.

Bibliography from Pomodoro Technique Illustrated

There are many references in Pomodoro Technique Illustrated. Below is a list of the books in the bibliography linked to Amazon. In a future post I will also put links to the referred articles and web sites.

How many of these have you read? Do you have any recommended reading for me?

Pomodoro Technique Illustrated -- New book from The Pragmatic Programmers, LLC

The Now List

(This is an excerpt from the book Pomodoro Technique Illustrated)

In 1933 Hedwig von Restorff performed a set of memory experiments. Her conclusion was that an isolated item, in a list of otherwise similar items, would be better remembered. If I read a shopping list with one
item highlighted in azure blue, it’s more likely that I remember the highlighted item than any of the others. This is now identified as The
Von Restorff effect
.

The Now List is not another artifact in Pomodoro Technique® (created by Francesco Cirillo). It’s my name for a concept: what I give my attention to right now. The cardinality of my Now List is binary. Either I focus on 1 activity or 0 activities. It can
never be 2, 3, 4 or any other number of activities. Before I wind up the clock, I choose one single activity. My challenge during a 25 minute Pomodoro is to not give another activity attention for a minute or two.

The Von Restorff effect tells me that I can provoke my memory to store things that I highlight. I may use a highlighter felt-tip pen to mark the current activity on the To Do Today sheet. Or I can explicitly write the
activity title on a slip of paper and put it in front of me.

The Now List

The Now List

Pomodoro Technique Illustrated -- New book from The Pragmatic Programmers, LLC

« Previous PageNext Page »



Follow

Get every new post delivered to your Inbox.