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

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.

2 thoughts on “today’s kata

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

  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: Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s