Learning Japanese the Rubyist way
- Step 1: How to read Japanese characters
- Step 2: Japanese and OO
- Step 3: Japanese and functional
- Step 4: Writing Japanese programming language in Ruby
- Ruby Advent Calendar
Have you ever thought about learning Japanese, but it looks too difficult to learn?
Surprisingly, Japanese and Ruby share some common features and concepts. This is a shortcut version of my presentation called “Japanese and Ruby” which I presented at LRUG.
When you finish reading this post, hopefully you find Japanese language less magical, and may even add “Learn Japanese” to one of your 2011 new year resolutions.
Learning a new language always has a bit of steep learning curve. Go and get some coffee before you start!!
Step 1: How to read Japanese characters
One of the first big hurdle when learning a language is to remember all characters. This is not a issue if you are learning a language based on alphabet, but many non western languages have their own character sets.
To make the matters worse, Japanese uses three different character set, Kanji (Chinese character), Hiragana, and Katakana. Hiragana and Katakana each has 46 characters and there are a lots of Kanji (possibly 50,000, though we use ONLY 2000 ~ 3000 in daily use).
Here is the mapping of Hiragana, Katakana, and Alphabet.
(The diagram is from Wikipedia)
The point here is not to overwhelm you with the amount of information, but to let you think “WHY” Japanese uses 3 character sets.
Originally, Japanese did not have its own character set, so we used to borrow characters from China (Kanji). Since Chinese grammar and Japanese grammar are completely different, it was not easy to map all these Kanji into Japanese sentence.
That’s when Hiragana and Katakana were born to supplement Kanji. Hiragana is often used as a glue to combine words into sentence where Kanji alone is not good enough.
For example “行” is a Kanji character which means “to go”. Japanese has many different ways to change the ending of verb (eg: goes) end we use Hiragana to supplement.
Here are the examples.
|行かない||Ikanai||I do not go|
|行こう||Ikou||Let's go, the more casual way|
|行きましょう||Ikimasho||Let's go, the more polite way|
|行け||Ike||Go, very non polite way|
NOTE: If the above examples do not look like Japanese, you have an encoding issue. Make sure that your browser encoding is set to UTF-8
Katakana, on the other hand, was often used alongside with Kanji so that people can understand how to pronounce the Kanji. Nowadays, Katakana is often used to represent new words which came from foreign countries.
(Trivia. The above example is expressed with html5 ruby tag )
(Another Trivia. Before multibyte became common, Japanese computers were only able to handle Alphabet and single-byte Katakana (eg: ﾙﾋﾞｰ), instead of multibyte (eg: ルビー). Some banks’ ATM slips still use this single byte Katakana)
Even though they are the conventions, you can use Kanji, Katakana, and Hiragana interchangeably.
The following 3 all mean “Cherry blossom bloom” and pronounce the same “Sakura Saku”
(Trivia. The world “Karaoke” is the combination of Kanji “Kara”(空 , means “Empty”) and English “Oke” Orchestra.)
Here is the quick recap of what you learnt so far.
- Kanji came first to import Chinese words
- Hiragana was created to suit for domestic use
- Katakana is used to adopt new words
Doesn’t this “There are many ways to achieve one thing” concept familiar with Ruby’s philosophy?
- Ruby came first to bring concept of OO & Functional
- Ruby was created to suit for every day scripting use
- Ruby keeps evolving by adopting new concepts (Fiber, Multinationalization/M17N, Refinements etc)
Step 2: Japanese and OO
Satoshi Nakashima is a well known Japanese blogger who used to work at Microsoft as one of the development team members who shipped Windows 95 and Internet Explorer.
He was once asked “Are there anything it helped to create Windows 95 as a Japanese?” He initially did not come up with anything, but then thought that Japanese grammar structure is more suited to Object Oriented programming. To explain his thought, I will explain you some basic Japanese grammar.
English and Japanese has very different grammatical order.
English grammar structure is called “SVO”(Subject - Verb - Object), while Japanese one is called “SOV”(Subject - Object - Verb)
If I put “I eat bacon” in Japanese order, it is going to be “I bacon eat”(Watashi ha bacon wo tabemasu “私はベーコンを食べます”)
At first glance, English order is clearer as “what you do”(verb) comes next to “who does it”(subject). It’s almost like command line options (eg: git clone url).
The problem of command line options is that there are so many choices that it’s hard to figure out which command you are supposed to use.
On the other hand, Japanese grammatical order is more similar to GUI. You often (right-mouse) click an object you are interested, then it suggests the possible actions. This is much more user friendly because you do not have to know all the possible actions and its argument options.
As you already know, Ruby is one of the best scripting languages to express OO (though you can write in procedural, or “command oriented way” if you wish)
# Procedural open("box") open("car") open("file", "foo.txt") # OO Box.new.open Car.new.open File.open("foo.txt")
In the above example, they both do exactly the same thing, but the implementation will be quite different. For procedural example, I imagine that you have to keep adding nested “if” statement as logic becomes more complicated. On the other hand, the logic of OO way is kept isolated within each class.
Step 3: Japanese and functional
I often says Japanese is a politician’s language.
What does this mean?
My definitions of politicians’s are
- they do not commit to anything unless necessary
- they mean different things depending on context
In Japanese grammar, there is a term called “Postpositional” (“Pre-positional” is often used in English, such as for you, after dinner, and so on).
Postpositional is used to decide the role of noun which it supports. This enables you to change the order of structure very flexibly, chain as many sentence as you like, and also let you omit subject.
Here are some examples of what I just said.
|Japanese||English||How to pronounce||Structure||How it is ordered if written in English|
|私はベーコンを食べます||I eat bacon||Watashi ha bacon wo tabemasu||SOV||I bacon eat|
|ベーコンを私は食べます||I eat bacon||Bacon wo watashi ha tabemasu||OSV||Bacon I eat|
|ベーコンを食べます||I eat bacon||Bacon wo tabemasu||OV||Bacon eat|
And this is the example of chaining too much sentence together.