today’s kata

In Ruby, one easy way to check for palindromes would be to write a method such as this:


class String
 def palindrome?
   self == self.reverse
 end
end

But the C++ part of my brain screams that this is likely to be very inefficient. So, today’s kata: test-drive a palindrome? method for String, ensuring (with tests) that it is much faster than the above.

Advertisements

2 thoughts on “today’s kata

  1. Pingback: Twitter Trackbacks for today’s kata « silk and spinach [silkandspinach.net] on Topsy.com

  2. It’s interesting to perform the same Kata with different design goals. If you are looking for readability and expressing intent then your example is perfect already.

    Optimized version would be: First check length. Then match first and last going inwards.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s