Feb 16, 2014

Benchmarked Sort::Maker's each sort style for my specific purpose

I use various internal and external APIs to build my services. An external API returns content something like below:
    "status": 1,
    "error_msg": '',
    "result": {
        "foo1": { .... },
        "foo2": { .... },
        "foo3": { .... },
        "foo4": { .... }
After retrieving this, I have to sort the result in result.foo1, result.foo2, ..., result.foo100 order. I'm wondering why they don't return this in array, but I must face it as long as the provider is returning values in this way. Although Perl Best Practices insists on using Sort::Maker, I implemented this in my way because this sort wasn't that complicated.
my %tmp_cache; # for orcish maneuver
my @sorted_keys = sort {
    ( $tmp_cache{$a} //= $a =~ s/\A foo(\d+) \z/$1/xr ) <=>
    ( $tmp_cache{$b} //= $b =~ s/\A foo(\d+) \z/$1/xr )
} keys %{ $content->{result} };

# then sorted results are stored in stash to be displayed
$c->stash->{results} = [ map { $content->{result}->{$_} } @sorted_keys ];
Today, I benchmarked each sort type provided by Sort::Maker and found that using Sort::Maker was much faster. The code is as below. It was a bit surprising that my original method with orcish maneuver is13% slower than Sort::Maker's one with orcish maneuver. Needless to say, other sort types are much faster. So my conclusion is that even relatively simple sort should be implemented with Sort::Maker to increase readability, maintenancibility and performance.

Feb 9, 2014

Released Lingua::PigLatin::Bidirectional Ver.0.01

The other day I talked about Lingua::PigLatin and how it works. This module really helped me understand how Pig Latin works, but this module only handled English-to-PigLatin translation. So I created Lingua::PigLatin::Bidirectional. As the name implies, this translates English sentences to Pig Latin, and vice versa.
use Lingua::PigLatin::Bidirectional;
warn to_piglatin('hello');     # ellohay
warn from_piglatin('ellohay'); # hello
My IRC bot uses this module so when I want to pig-latinize some sentences or want to see if my pig-latinization is correct, I talk to this bot and it returns translated sentences.

Feb 2, 2014

How we should teach how to eat soba noodle

Soba eating experience is totally different from that of spaghetti. It's not just a difference between forks and chopsticks, but it involves the difference of table manners so understanding and mastering soba eating can be an indicator how much he or she understands Japanese culture. Then how should I tell westerners, who grew up with a manner of not making noise while eating pasta, how to eat soba?
Lately I found a good article, "The sound makes the experience," which approaches this problem from both cultural and technical aspects. It describes the reason to make noise as a very polite gesture to acknowledge cook how much you enjoy your meal. And then it describes the technique as follows:
For me, the best way to conceive of the proper slurping technique is like when you are eating a very hot slice of pizza. You take a small bite, and because it's hot, you start to suck in air while chewing. This allows you to eat the food while it is still very hot, while you are breathing in. This is the same manner in which you should eat soba in Japan.
This helped me a lot. For Japanese like me, it is very difficult to teach this kind of basic skills because we all acquire them during our childhood and do not remember how we learned. Even worse, We can't understand why they can't do it.
This leads me to a conclusion that Japanized foreigners are better teachers than Japanese ourselves. I'll catch up those foreign media to learn how I should teach Japanese culture.

Why I think Glocks are not for everyone... especially sport shooters

When I say 'I hate Glocks' to my friends, I'm not just talking about its plastic frame and Good Ol’ ‘merica. I'm at age of 28, and I think I'm not old enough to say that. I'm not even American, after all. Actually I know Glocks have some cool features and that's why I carefully say 'Glocks are not for everyone.' I'm going to explain why I think that way.

Premise: Its Uniqueness

Glock's company history is briefly introduced on a web page, Timeline | GLOCK USA. It started its activity as a plastic and steel parts manufacturer and then, in 1970s, shifted its field to military industry including knives. When this company started gun manufacturing after 1980, it brought its invention of nylon-based polymer, Polymer 2, to gun industry. That's Glock 17. So its origin and design policy are totally different from those of other gun manufacturers with long history such as Colt, Winchester and Smith & Wesson. This critical difference includes weight balance and safety mechanism.

Weight Balance

When I lived in Oklahoma -- BTW, that's why I call myself Oklahomer -- I visited H&H Shooting Sports every other week for sport shooting. My favorite choice of full-size handgun was Sig Sauer P226 and second was Colt M1911. Comparing to those 2 handguns, Glocks are extremely light. The weight of cartridges in magazine don't differ a lot so the lightness of front half stands out. It makes difficult to handle the recoil and aim of the second shot.
I know lightness is important for those who must carry gun with them on daily basis such as police officers, but it doesn't profit me.

Its Mechanical Simplicity and Handling Complicity

Glock's safety mechanism, which is called Safety Action system, is pretty simple and unique. It's all about trigger and it doesn't include anything like M1911's manual and grip safety or P226's decocking lever, which I think is the biggest difference concerning safety.
I understand this Safety Action system is a reliable mechanism, but it's just a mechanism. *WE*, humans, make mistakes. To avoid misfire, I believe we need decocking lever or at least cocking indicator. Of course it should be O.K. as long as the shooter, such as law enforcer, handles only Glocks and has enough time for continual training. For others, like sport shooters, who handles various guns and can't afford to train daily basis, I think they should choose guns with more common safety mechanism that involves cocking indicator and decocking lever.


As I described above, Glocks are very unique in terms of its lightness and safety mechanism. I believe this can benefit law enforcers with adequate training and need of portability, but can disbenefit ocasional sport shooters.
By the way I love Gunny from Full Metal Jacket, lol.