Skip to content
February 15, 2012 / zlost

Fast native methods for javascript collections

I’ve been really lucky lately because any javascript I write on the job need only work on WebKit browsers. This has allowed me to use some of the newer native methods defined for collections.

Here’s a gist demonstrating the most useful ones.

If you are one of the poor souls still supports IE or whatever, the excellent underscore.js library wraps these native methods in such a way that calling a wrapper method in an interpreter that implements the native method delegates the work to the native version, and falls back to underscore’s javascript implementation otherwise.

Since underscore.js uses native collection methods when available, its each and map methods are preferable to jQuery’s, which are implemented as straightforward javascript for loops regardless of the availability of native implementations in all modern browsers.

Node users can directly invoke the native methods with impunity, as Node is built on the excellent V8 VM which natively supports all of the aforementioned methods.

January 15, 2011 / zlost

How to avoid over-thinking social interaction

Immediately after a social interaction is resolved, without being bogged down by each detail, make a quick judgment if the interaction was a success or a failure. By definition, the distribution should be 50-50.

If a given interaction was declared a success, avoid analyzing it. Sure, there may have been one or more awkward missteps during the course of the interaction, but this is not the place to expend you focus. Focus instead on the other 50%, the failures.

Try to ascertain key points in the interaction that, if handled differently, would have a profoundly improving effect on the overall outcome of the interaction.

As your experience with social interaction improves, gradually increase the success-to-failure ratio.

November 17, 2010 / zlost

Communities from which I’m happy to be apart #1: Java

You know your language is stagnating when is reporting upcoming lambdas as a key point on the future roadmap. I for one can’t wait for JDK 7 JDK 8.

Also, why couldn’t they have just followed the C# implementation of lambas from the start?

November 1, 2010 / zlost

More Ruby Metaprogramming

Following is a follow-up to this foul-titled file</alliteration>. It began life as a mere edit, but I soon realized that it may be either a) worthy of its own post, or b) a good way to make this blog appear apparently more active than it in fact is. Besides changing themes, that is.

All joking aside, for those of you not interesting in going back and reading that post, I think the following can stand on its own.</ado>

This no longer seems weird to me. Maybe I’be gotten used to the idea, or maybe I’ve achieved a better understanding of why this is true. Internalized it, perhaps.

If I may take a stab at expressing it in words… And it’s my blog so I guess so:

All objects are instances of the Object class. Everything that has a name in ruby is an object.

Class.instance_of? Object # => true
Object.instance_of? Class #=> true

And furthermore:

Class.instance_of? Class # => true

What a lovely triangle we’ve discovered.

[edit] Make that a square:

Object.instance_of? Object # => true

June 14, 2010 / zlost


I suspect that my recent updates to the About page will at least partially explain the recent lack of activity around these parts.

May 18, 2010 / zlost

Ruby Metaclass Mindfuck

class Foo; end
f =

f.kind_of? Foo # => true
f.kind_of? Object # => true

# so far so good... now let's get in to metaclasses

Foo.kind_of? Class # => true

Class.instance_of? Object # => true
Object.instance_of? Class # => true


mind.blown? # => true

April 6, 2010 / zlost

On making decisions

“Fortune favors the bold.”

“Measure twice, cut once.”

Taken in the general sense, both of these nuggets of folk wisdom are applicable in a multitude of situations. But in a way, they contradict each other. Should I just go for it or should I mull it over first? Should I take the contemplative or impulsive approach? The thoughtful or the assertive one? Careful reasoning or intuition?

Like so many other interesting questions, the answer to this one is “Well, it depends.”

Obviously, if you have plenty of time to think about something, you might as well make use of that time to make sure you make the optimal decision, and if you have very little time, you have no choice but to react instinctively. But there can be other dimensions to the problem. For example, how difficult it would be to atone for a wrong decision. It’s generally a good idea to think long and hard before burning any bridges. Furthermore, some situations degrade over time, meaning the sooner you make the decision, the better off you’ll be, but you still don’t want to make the wrong decision under all this pressure.

Deciding between the contemplative and intuitive approach is in itself a decision that that can be made using either the contemplative or intuitive approach. And so can that decision. Sadly, it’s turtles all the way down.

So what can we conclude from all of this? Not all decisions can be made the way a computer would make them, or your stack will surely overflow. The best I can come up with is to develop a heuristic, play it by ear, and learn from your mistakes. Try to strike a balance between the two approaches. The contemplative approach is usually safer, but overuse it and many a golden opportunity will simply zoom past while you’re too busy in your own head. There’s a time and a place for noodling, but not when an attractive stranger is making eyes at you from across the room.