I love you ruby, `unless`...

An article, posted 4 months ago filed in sorting, ruby & programming.

I'm quite familiar with writing ruby code. I've even expressed my love for the language long time ago. But some constructs still bug me. One of them is unless…

I've seen variants of this code:

temperature = 36.7
unless temperature > 37.2 || temperature  35.5 && temperature < 37.2
  puts "Healthy temperature. Temperature is within the normal range."
end

or perhaps even nicer:

if (35.5...37.2).include?
  puts "Healthy temperature. Temperature is within the normal range."
end

Continue reading...

Sorting text

An article, posted 5 months ago filed in sorting, ruby, programming, database, order, databases & sql.

There are a few hard problems in computing. Correctly handling time, naming, preventing off by one errors… sorting text may not be one of them but recently we ran into a discussion where I couldn't make up my mind anymore. Hence, this post's topic: sorting text.

The problem

How do you sort the following words:

  • cheese
  • Ape
  • Drums
  • dent
  • Beer

If you'd ask ruby I'd get:

 %w[cheese Ape Drums dent Beer].sort

Results in:

  1. Ape
  2. Beer
  3. Drums
  4. cheese
  5. dent

Which in my useless and ramshackle programmer's brain translates to, well why not, it is sorted right?

But then we moved the data into a database which was correctly set up with a proper locale for 'collation', a term that I've seen but never meant anything to me until this problem. Collation is:

> the assembly of written information into a standard order.

(thanks Wikipedia - Collation)

Databas…

Continue reading...

murb blog