こんにちは世界 (Kon’nichiwa sekai!)
The inspiration for this blog post comes from a few places:
Growing up, my first spoken language was Spanish, followed shortly there after by English and French, all three of which I’m fluent in. In the present, I split my time between learning 5 other languages – Japanese, Mandarin Chinese, German, Italian, and Russian.
That begs me to ask the question:
Is there a link between programming languages and spoken languages?
Why yes, yes there is – let’s take a look at Ruby and the Japanese Language.
Japanese has a total of three (3) different alphabets, all of which serve their own purpose:
Most students learn the syllabic alphabets first through memorization and mnemonics, using charts like this one to assist in the memorization:
Thousands of Kanji characters are in existence today – an individual in Japanese is considered fluent when they have mastery of the base 2000 characters. These are generally learned through memorization and constant practice.
Cool – so how does the Japanese language relate to the Ruby programming language?
Based on the definitions of the alphabets, we can see the following comparisons between the Japanese spoken language and the Ruby programming language:
In Ruby: built for domestic ease-of-use (focus on programmer happiness).
In Ruby: continually evolving and adapting new functionality.
In Ruby: merge (import) concepts of Object Orientated / Functional programming.
Furthermore, parts of the Japanese language can be seen as both object oriented (OO) and functional in nature.
Thinking back to when we were learning English, our teachers taught us that sentences are formed in the following order: Subject – Verb – Object (SVO). It’s fair to state that English is an “Object-Oriented Language,” where context revolves around the object in question.
Japanese is quite similar, with the “normal” form of expressions being in the following form: Subject – Object – Verb (SOV). For example, take the following sentence:
Ruby’s primary focus, much like the Japanese language, targets the object as the center of attention. Although the grammatical structure may be different, the intention remains the absolute same.
In terms of code, Ruby also allows us to define functionality in both object oriented and procedural ways:
The example above shows the flexibility of Ruby to implement the same solution using two different grammatical orders. In most cases, when dealing with a complex problem, functionality is encapsulated within a class. Object Orientation proves to be a great aspect of the Ruby language.
Japanese grammar is different in that it is post-positional:
These post-positional words are used to decide the role of the noun which it supports. This would allow a Japanese speaker to change the order of the grammar pretty easily, chaining as many sentences as desired, and even omitting the subject altogether.
Here are some examples:
Where do we see this sort of behavior in Ruby?
Functional programming in Ruby allows for hard-core abstraction and meta-programming, which is something that other programming languages do not support as easily.
One example of a gem that allows you to evaluate Japanese characters and expressions in the Ruby programming language is the japanize gem.
Here’s output to what a command line might look like, along with a test that was written in order to test the interpreter:
Note that this gem is outdated (3 years old), and that other gems exist that establish the morphemes (translation patterns) between English and Japanese for Ruby.
Too often, I overhear people argue over which language is:
As programmers and as citizens of a diverse world, it’s up to us to respect language in general, whether programming or spoken. It should come as no surprise that programming and spoken languages are so similar, as one is used to express the other.