include(:english)

December 28, 2012

Brian Ford wants discussion about Ruby to be in English.

I also want Japanese programmers to use English more often.

Some Japanese programmers said to me that they can’t attend overseas conferences, because their English is not good enough. That made me very sad.

Many programmers still make bug reports in Japanese.

Some Japanese programmers are trying to improve their English. At Sapporo RubyKaigi, many programmers attended try(:english). At Minami.rb, there are sessions to study English.

I think some Japanese people want to use English, but are unable to. Do you need help?

Can non-Japanese Ruby programmers help Japanese Ruby programmers use English?

Japan.binders.full?(&:women) => true

November 26, 2012

(For Japanese readers: Not familiar with “Binders full of women?” Click here)

Once upon a time, I wondered if it was inevitable that programmers were predominantly male. Visiting another country disabused me of that notion. Surprisingly enough to me, that country was Japan.

Before visiting Japan for RubyKaigi 2011, I had the perception that while Japan was a technologically advanced country, it still remained socially very conservative, and that sexism existed to a much larger extent than in western countries such as Australia, the UK and the US.

In defiance of my expectations, I found that there were many women speaking at RubyKaigi, and also involved in the organization of the event. When I dropped in on ordinary meetup groups during subsequent visits to Japan, such as Ruby Sapporo and Minami.rb, I also noticed a high proportion of female attendees.

How could I explain this?

One possibility is that my perceptions of Japan were wrong. That would be interesting in and of itself.

But there’s an even more interesting possibility. What if sexism existed in the general Japanese community, but the Japanese Ruby community decided to behave differently? That we can decide what our community is like?

I have found the Japanese Rubyist community to be diverse in other ways as well.

I’ve found the Japanese Ruby community to be diverse in what programming languages they know. For example, when I showed off the ["1", "2", "3"].map(&method(:Integer)) trick to a Ruby meetup group, one of the attendees remarked that there’s something like that in Haskell.

In one way, this diversity is forced upon them – many of them don’t use Ruby in their day jobs. Instead, they use Ruby in their spare time. But I doubt that they’re using Haskell in their day jobs, either.

The Japanese Ruby community is making a strong effort to interact with western countries conference-wise. Virtually every piece of information about international RubyKaigis is posted in English as well as in Japanese. Talks at RubyKaigis are translated live from Japanese into English, and vice versa.

In RubyKaigi 2011, attendees were given conversation sheets, with a list of phrases they could say in English and Japanese. There were also anti-bocchi boards, which organized lunch between strangers. I took advantage of this to have lunch with Japanese Rubyists, and was often the last to finish lunch because I was talking so much with them.

At Sapporo RubyKaigi, the organizers accepted my proposal, which was about the Japanese language. The aim of that talk was to encourage other people to learn Japanese. In the same session as my talk was Yoko Harada’s talk “Why Don’t You Go To Conferences In US?” Harada also organized try(:english), an event where Japanese Rubyists practiced English with native speakers.

To be honest, there have been challenges. Some Rubyists I’ve talked to say that they’d like to come to Australia, but that it’s too expensive. Others have laughed when I suggested that they come to RubyConf Australia – not at me, but at themselves, because they feel that their English is too bad (a lot better than my Japanese, let me tell you!).

One regret I have is that not many Japanese Rubyists go to nearby asian countries, and not many people from Japan’s neighbours come to RubyKaigi.

I’m thinking TJRCINSWAN: The Japanese Ruby Community Is Nice, So We Are Nice!

In Ruby, &method passes you!

October 3, 2011

Most Rubyists would know what the following does.

[1, 2, 3].map(&:to_s)

It takes the array of numbers, calls to_s on each item, and returns an array of the return values.

But what if you want to do the opposite? Rather than calling a method on the object, what if you want to call a method with the object as a parameter? Simple!

["1", "2", "3"].map(&method(:Integer))

Wait … what?

I’m sure you all understand how it works, because you already use map(&:to_s), and none of you would use something you don’t understand, right?

Who am I kidding?

I’ll explain how map(&:method_name) works, and then how map(&method(:method_name)) works.

When you use & (ampersand) in front of the last variable in a method call, you’re saying that what’s passed in shouldn’t be treated as an object, but treated like a piece of code – a proc.

Symbols aren’t procs, but they can be converted into them by Ruby. You can see for yourself by running to_proc and call on it with the following:
# my_proc will be something like #<Proc:0x00000001014c39c8@(irb):35>
my_proc = :reverse.to_proc
# This causes "abc".reverse to be called, which returns "cba"
my_proc.call("abc")

As Ruby calls `to_proc` if an ampersand parameter isn’t a proc, the following

def call_me_three_times(parameter_1)
  puts((yield parameter_1).inspect)
  puts((yield parameter_1).inspect)
  puts((yield parameter_1).inspect)
end

call_me_three_times("abc", &:reverse)

will print the string reversed three times.

Now that the & part is understood, let’s look at the method part.

When you call method(:method_name), you get back an object of class Method that represents the method.
# Integer(string) is a method kind of like String#to_i, but 100% more awesome.
# Look it up if you haven't done so already.
# PS: don't worry about it starting with a capital letter!
# another_proc will look like #<Method: Object(Kernel)#Integer>
another_proc = method(:Integer)
another_proc.call("42") # Returns 42

and as `Method#to_proc` exists, the `call_me_three_times` method will convert the method object into a proc and will run it without any complaints.

When you run `call_me_three_times("42", &another_proc)`, it’ll print 42 (not “42″) three times.

But wait … there’s more!

The method doesn’t even have to be from your own object – it can be something else’s. For example, if you wanted to read in a series of files, you could do

filenames = ["a.txt", "b.txt", "c.txt"]
texts = filenames.map(&File.method(:read))

File.method(:read) turns the read singleton method of the File class into an object, and then (with the help of Method#to_proc) that object gets passed to map as something that should be executed on each filename.

Downsides

Firstly, you may need to document what &method does. I’ve been programming in Ruby for over three years, and hadn’t come across this trick until I noticed it on Stack Overflow. However, it is mentioned in the Pickaxe, now that I looked it up.

Second, there may be performance penalties for this approach. If hardly anybody has used this approach, it’s unlikely to have been optimized.

Third, making code shorter isn’t always a good thing. It may make smelly code seem less smelly. If you’re doing twenty different things on one line, the answer isn’t to cram things up to make the line shorter, but to refactor that line into something more logical.

Fourth, I haven’t worked out how to abuse this trick fully. Under Ruby 1.9, if foo takes two arguments, I don’t know how to do [["a", "b"], ["c", "d"]].map(&method(:foo)) yet. That code works under 1.8, however.

(Apologies for the awful appearance of the code – I haven’t worked out how to make wordpress use Github gists without adding a plugin)

RubyKaigi 2011, the Small Eigen Collider, and Bear Impact

September 18, 2011

RubyKaigi 2011 was really great. My talk was well received, the other talks were great, the atmosphere of RubyKaigi was wonderful, and I had a lovely time in Japan.

Makoto Inoue translated my talk from English into Japanese. On the day, my talk on the Small Eigen Collider was well-attended, and people asked questions, aided possibly by my offering t-shirts! People tweeted and IRC’d about my talk. Some of them even did so in a language I can read!

The talks

I really enjoyed the talks at RubyKaigi. Some were about implementations of Ruby, such as JRuby and MacRuby. Others were about upcoming features of Ruby, such as method shelters, or running tests in parallel. Eric Hodel gave advice on how to write good libraries, while other talks were about the community, such as Shota Fukumori’s talk on school students doing Ruby. There were also talks on concurrency, such as Elise Huard’s “Actors on stage”.

One talk I’ll remember after everything else is forgotten is the parse.y Famtour. By editing one file, he could redefine the Ruby language. He implemented fuzzy logic, possibly doing an action, but maybe not, based on a boolean. He also created a flexible keyword for de-indenting several layers at once. De-indent two levels? ennnd! Three levels? ennnnnd! Five levels? ennnnnnnnnd! This is what I want in a talk – something completely new and unknown!

This isn’t a very complete write-up of the talks, but I’m hoping that subtitles will be done of the talks so I can watch them again.

RubyKaigi itself

The social experience at RubyKaigi was wonderful and unique. You could create an origami Ruby. For the lightning talks, time running out wasn’t indicated by an iPhone app, but by a lady in traditional clothing gonging you.

For lunch, there was an anti-bocchi board, where you could organize to have lunch with other Rubyists. Some Australia-jin (Aussies) tended to have lunch with other Australia-jin, but I wanted to have lunch with Nihon-jin (Japanese). I was always the last one to finish lunch because I was talking so much. That, and because I’m bad at chopsticks – part way through the meal I’d ask foku o kudasai (fork please)!

The goodies I received were very useful. The fan and sweatband were appreciated considering that RubyKaigi was held during summer and that air conditioning was reduced because of of 3/11-related electricity shortages.

The situation with regards to language varied from talk to talk. Some people talked purely in English, some talked in Japanese but had English slides, while with others you had to rely on live translations. These translations appeared on a screen adjacent to the presentation screen and in IRC.

Sometimes the live translations were excellent, and sometimes they were frustrating. To be honest though, the main time language was an issue was when the subject matter was fairly technical, and I was wanting an excuse to ignore the talk and see what’s going on in twitter, such as RubyKaigi trending for the whole of Japan. Occasionally, there was a bit of Engrish – the most notable was “crap your hands”, which they joked about afterwards.

With regards to translating English talks into Japanese, I was one of the few people who took advantage of RubyKaigi’s offer to do so. To not do so is a missed opportunity!

Books were available for sale. I bought a Japanese book on bioinformatics with Ruby which transliterates as “Ruby de hajimeru baioinfomatikusu”, and means something like “beginning Bioinformatics with Ruby”. One day I’ll be able to understand it, but so far I’ve used it as practice for reading kana (Japanese characters that represent syllables). Neither that book, nor any other book on Ruby and bioinformatics, exist in English to my knowledge.

Events were held before and after RubyKaigi. Before the event was JRubyKaigi. At that event, I was talking with someone about the Ikebukuro Earthquake Museum and its simulations, and the next minute, a real earthquake occurred. One person noted “Demos are always experimental and dangerous!”.

After RubyKaigi was Asakusa.rb, and a Github drinkup. I met with Matz during the drinkup, and I talked with him about the fate of the flip-flop operator in a hundred years’ time. Apparently, it may not exist then. I also went around Tokyo with two Rubyists who were from outside of Tokyo (Cuzic and one other person).

Japan

Manhole from Karuizawa

Even the manholes are beautiful (Karuizawa photo)

I visited a variety of places before and after RubyKaigi. The first place I visited was the Ikebukuro Earthquake Museum. It took me a while to find the place, even with my iPhone, because all I could find was the fire department, and I was too shy to ask them for directions for a tourist. It wasn’t until I saw a sign to the museum inside that I realized that the museum was within the fire department!

The museum was very much practical rather than historical. It had an earthquake simulation, where you started off sitting at a table, and when the earthquake started, you had to duck underneath the shelter of the table. To make it a bit scarier, the lights went out a few seconds in, and you could hear a kettle falling to the ground. The next activity was navigating through a smoke-filled series of rooms. You had to remember to be half-crouching, and cover your mouth with a handkerchief. The following activity was CPR. Of course, the Japanese I said to my mannekin wasn’t that good – I said “genki desu?” when others were asking their dummies something slightly more serious to ask if it was ok. At least it didn’t say “mo-ichi do?” back to me! The final activity involved putting out a fire. I only got to use a fire extinguisher, while others got to use a fire hose!

Some of the information was only in Japanese, but the museum staff were very helpful to me, for example checking that I understood what was going to happen in the smoke-filled rooms exercise. They asked me afterwards why I came, and I explained that I was a scientist. Maybe I’m a little bit odd like that. To be honest though, the museum had the advantage of being close to the Ryokan (Japanese-style hotel) I was staying at, such that I didn’t need to take a train.

I visited the Tokyo National Museum . It had a variety of different artefacts, including pottery, calligraphy, weapons, armour, but the thing that I remember the most was the lacquer-work. The amount of work put into a single box made me feel sad. Was it worth the effort?

While I was with the two out-of-town Rubyists, we visited a maid bar in Akihabura, and browsed a few stores there. We saw the palace gardens, and then we visited Tokyo Tower. It described what there is in Tokyo, and had a exhibit where you could look at a map of Tokyo in earlier times compared to now. There was also a gift store where I bought a pair of tea cups. We then went on to Asakusa.rb.

The next day, I wanted to visit somewhere nice outside of Tokyo, and ended up choosing Karuizawa. It is a resort town, and is a bit cooler than Tokyo because of its elevation. It’s also the only town that’s hosted both Summer and Winter Olympic events: it hosted the equestrian events for the 1964 Tokyo games, and curling for the 1998 Nagano games. I saw a famous waterfall called Shiraito Waterfalls (literally “white strings”), and went shopping, buying some sweets for my Japanese class, and a hand-made doll of a cat wearing a kimono.

Travelling by shinkansen was very nice – you don’t have to book a specific time if you don’t want to, and there’s no security screening, but it has the cool things about flying. You can order food, and there’s a shopping catalogue of all things weird and wonderful. My favourite is a device that allows you to set up a desk from the steering wheel of your car. I’m glad I wasn’t driving while in Japan! According to my iPhone, the shinkansen was clocking speeds of 230 kilometres per hour!

The flight to and from Japan on JAL was also very nice. On my flight from Sydney to Tokyo, they upgraded me to an emergency row for free, and the hostesses were very friendly. I loved the anime demonstration of flight safety, and thought it was more informative than standard demonstrations as well. The meal on the flight to Tokyo had an Australian element to them – they had tim tams as a sweet, and meat pie for afternoon tea. However, I have one pro-tip: if you’re 6 foot 4 inches, and you’re wanting to sleep during your flight back home, don’t book a standard seat on lilliput-jin airlines!

Message saying a train's late due to Bear Impact

Earthquakes cannot stop Japanese trains. All it can do is delay it for a while.

Public transportation in Tokyo was good – information was available in English. The biggest challenge was just logistics, not language: make sure you use the right exit from the station, as the stations are massive, and that you don’t choose a train that goes past your station! While you’re in trains, you can read about reasons for delays with other trains. They were pretty good reasons – one delay was because of an earthquake, while another was due to “bear impact”! I wish Sydney’s Cityrail was that reliable!

Having studied Japanese for 6 months this year, language wasn’t that big a issue. It was a barrier only three times. The first was at a love hotel. I wasn’t able to understand what the receptionist was saying, apart from not being able to get a room. Maybe it’s mandatory that you’re undergoing an illicit affair with someone, whereas I was just a dumb solo tourist that had got locked out of my Ryokan. I’ll never find out. The second was at Mister Donut. I had asked for an interesting-looking drink, but the cashier gave me instructions that I couldn’t understand, so I had to order koka kola kulashikku instead. The third, ironically enough, was with Google transit. I couldn’t work out how to display Romaji names for the train stations or train lines, so I had to rely on the suburb names near the train stations, which were in Romaji. Unfortunately, my Japanese was fairly basic, and I didn’t learn much new Japanese while I was there. Next time I’m there I’ll be good at the language, I hope!

Ennnnnnnnnd!

Zombie chaser – it’s alive!

April 12, 2010

Zombie-chaser is a graphic(al) user interface to mutation testing. Mutation testing involves making modifications to code, and seeing if the unit tests detect these changes and indicate a failure. In the zombie-chaser gooey metaphor, mutated code is represented by zombies. Each successful test is represented as the zombies getting one step closer to you, and a failed unit test kills off the zombie. If you fail to kill the zombie, it gets to eat your brains.

There are two alternatives for the interface. One is a GUI, while the other is a nethack-style interface within the console itself. Like the chaser project, zombie-chaser aims to be compatible with any flavor of ruby on any platform. If it isn’t – if it’s lukewarm on JRuby, if it’s rusty on IronRuby, or if it’s having kittens on LOLRuby, and it’s possible for me to fix it, let me know!

This program incorporates code from chaser and heckle, written by Ryan Davis and Kevin Clark, and code from brains, a game written by Chris Lloyd, Dave Newman, Carl Woodward & Daniel Bogan. The idea of ripping out brains code and producing something different was inspired in part by Zombino, written by Ryan Bigg, and psDooM helped inspire the idea of melding work with a game interface.


Declare War on Everything with Chaser

November 8, 2009

Chaser is a new lightweight mutation tester. Mutation testing involves messing up code that’s being tested, and seeing if the unit tests notice anything’s wrong.

Fake APEC passes by the Chaser

You need to detect when something's wrong

The name is based on The Chaser, an Australian comedy team. They’re best known internationally for a penetration test gone horribly, horribly right.

The main ruby gem that does mutation testing right now is Heckle. The folks from Seattle.rb have done a lot of work on it, but sometimes you’re simply out of luck. It doesn’t work on certain platforms – Windows (correction below), Ruby 1.9 and the like – because it currently relies on ParseTree. One day, I decided that I wanted to be able to do mutation testing on Windows. Like, yesterday. And thus Chaser was born.

Chaser uses plain old metaprogramming. If you’ve got ruby, and you’ve got test/unit, then you satisfy the requirements for chaser. So far, I’ve played with it on Windows, 1.9 and JRuby.

Bug reports, feedback, new features, and fake beards are welcome.

Correction 2009-12-17: Apparently, it is possible to make Heckle work on Windows, if you have a suitable compiler and make a minor change to Heckle’s code.

Extra links: Slideshare notes, and a video presentation thanks to the awesome folk at Ruby On Rails Oceania.

The royalty-free road to knowledge

February 7, 2009

If you start on a random Wikipedia article, and click on the first link within the article, and continue the process until you reach a loop, you end up at Philosophy or a similar article.

The composition of Wikipedia ... or is it? (CC-SA)

The composition of Wikipedia ... or is it? (CC-SA)

Considering that Wikipedia has been criticized as having too many articles on trivial topics, it’s surprising. It’s also freaky – how does Wikipedia know that Philosophy is the “ultimate” thing?

Nonplus describes one possibility, saying “It’s nice to think that the articles tend to proceed up to higher and higher levels of generality and abstraction”, and I’m creating a program to analyse how it “funnels”.

The results so far, although not 100% accurate, are plausible enough to be interesting. It’s claiming that the ultimate page is not Philosophy, but Organism, another abstract concept. Other ultimate pages include Communication, Education and Alphabet.

Analyzing what pages get the most direct links, the top ones include “Where”s, such as the United States and Australia, and “What”s, such as Gene, Plant and Fictional character.

Pages passed through on the way to Organism and other pages are also calculated. 4.3 million out of 4.8 million pages ending up at Organism go through Philosophy, of which 3.8 million went through Indo-European languages. Philosophy links to the British A. C. Grayling via a citation of his work, and United Kingdom links to Terminology of the British Isles via an explanatory footnote. (Nothing in the rules against that … yet) We can see that the British Isles refer to islands, and that some islands are atolls, which are made up of coral, which are marine organisms, studied in marine biology, which study organisms.

The pages that merge together mighty tributaries are also listed. A. C. Grayling, passed by over 4 million pages, only adds half a dozen pages to the total. By contrast, Mathematics and Science, although passed by only a few hundred thousand pages, are noted for merging groups of pages together together.

It’ll be an interesting investigation into collective intelligence. And if it isn’t … well anything that’s free and wiki is fun, right?

When your wireless mouse lacks zap

January 4, 2009

When the batteries of my wireless mouse gave up, I tried seeing if rechargable batteries would work. I put them in, and the red light produced by the laser was visible. But it wasn’t talking with my computer. I tried re-connecting many times, under both Windows and Linux, but it didn’t work.

The next day, I noticed that the light from the laser wasn’t working any more, and therefore the rechargeable batteries had been drained. If the batteries could only last a day, they mustn’t be suitable for mice. So I put some standard batteries into the mice, and both the laser and the communication with the computer worked.

It isn’t always a software problem – sometimes it’s a lot simpler!

About me

September 21, 2008

I’m a bioinformatics ruby programmer by day, and a rails hacker by night, working on The Weather in London.

Update: The Weather in London is now an inactive project.


Follow

Get every new post delivered to your Inbox.