Chained together. Cool Ruby trick, courtesy of Nick Kallen.
Naturally, sorted. Natural sort algorithm adapted from Thomas Hurst’s adaptation of Ned Batchelder’s Python code:
module Enumerable
def sensible_sort
sort_by { |key| key.split(/(\d+)/).map { |v| v =~ /\d/ ? v.to_i : v } }
end
end
There’s also an internationalized version. Anyone wants to take a stab at a Ruby implementation?
Overflow. Sometimes abstractions are better:
I’d expect any competent programmer to be able to read
(low + high) >>> 1and be able to see what it is meant to do. I’d expect a good (and experienced) developer to usecalculateMidpoint( low, high )because it is a little easier to read, but more importantly, much less likely to have subtle bugs in it.
As much as I worry about diminishing skills, (low + high) >>> 1 is a good example for what not to know. It’s a recipe for a classic overflow bug, not beautiful in any way, and one thing I unlearned when I stopped low-level coding in C.
To be or not to be? The rest of the thread is interesting:
All that just screams that many people in IT today do quite obviously not have the necessary basic training. They might learn how to plug Hibernate into an enterprisey Java application and how to battle XML config files, but there does not seem to be a computing 101 course any more. It’s as if a garage mechanic could only read the diagnostic codes from the motor microprocessor but has no idea that there is oil in the engine (or why, for that matter).
There’s a whole class of developers who are able to plug components together but have no understanding of the underlying mechanisms. So you get things like 1+N queries or iterating over and updating individual records, just to name a couple. That’s bad.
But these factory workers that are only able to follow directions and assemble prefabbed components into working products without understanding the product itself or the underlying mechanics … is that no the holy grail of the software industry?
Readable is beautiful. After all, it’s all about working at the right level of abstraction. Andrew Binstock recommends Implementation Patterns.
Picture, Savage Chicken, and felt relevant to this post, but I can’t explain why. So there, enjoy.
