Sunday, August 30, 2015

PyTongue - OSFY article


Teaching programming with non-English languages

Title                     : Teaching programming with non-English languages
Author                 : Arjoonn Sharma
Target Audience  : People who teach programming at various
                               levels and general programming enthusiasts

Any program which must be run needs to be converted to a string of bits in
order to run. This has been true ever since the inception of programmable
computers. If this is the case, then all we need to do is write the proper
string of bits to make any program. Then what do programming languages do?
After all we are not writing bit-strings but are writing text based programs.
The bit-strings are all that a computer needs to run. The programming languages
exist to help us make sense of what we have written. This means that
programming in a language of our own is very much possible. All that is needed
is a method of translating the language to the appropriate bit-string. This is
where PyTongue comes in handy. It lets you teach people who do not know the
Latin script how to program.

For the purpose of teaching programming to children who do not know English I
developed PyTongue. Thus I can teach them Python without having to teach them
English first. Python3 was the choice of language as it has nice Unicode
support throughout and Python by nature has a small learning curve. After a
while people have to learn English as it is the language of the trade. This way
however I can make sure that a child who has the potential to program does not
miss out simply because of a language barrier.

PyTongue has simple logic powering it. It is a transliteration service to be
precise. It takes a program written in one language and transliterates it to
normal Python code which is in English. The new code is then executed.

To get started with PyTongue we must first install Python3 and then install
PyTongue. For this article Ubuntu 14.04 was used.

First we make sure that Python3 is installed. Next we create a directory
`pytongue_folder` and download PyTongue in it.

sudo apt-get install python3
cd ~
mkdir pytongue_folder
cd pytongue_folder
git clone
cd pytongue

In case the `git` command shows an error you can download the `zip` file from
the same link and unzip it. The effect is the same. We need to have a folder
called pytongue. After that we navigate into the folder with

In order to write code in a certain language we need to get the mapping for it.
Some mappings like Hindi, Russian etc are already provided.
Mappings are obtained by running `pytongue-mapgen hi` for Hindi and
so on. The two word short forms are from

A mapping is a word-for-word translation of the basic keywords and builtins
in Python. To create a mapping we need to create a file with the required
language name and write a JSON encoded dictionary having the general structure
of :.

This creates a mapping for the requested language. While it is downloading the
language it prints out the keywords mapped. After this we begin to write a
program. For the purposes of demonstration we will first write a simple 'hello
world' program and then a simple calculator in Hindi.

To write these programs any plaintext editor will do (gedit, vim, notepad etc).
The first line of the program must always be of the format
`# `

# HI
छाप('हैलो दुनिया')

This prints out हैलो दुनिया'

# HI
क = पूर्णांक( इनपुट('एक संख्या दर्ज करें'))
ख = पूर्णांक( इनपुट('एक और संख्या दर्ज करें'))
कार्य = इनपुट('क्या करना है दर्ज करें (+,-,*,/) : ')
अगर कार्य == '+':
    छाप(क + ख)
अगर कार्य == '-':
    छाप(क - ख)
अगर कार्य == '*':
    छाप(क * ख)
अगर कार्य == '/':
    छाप(क / ख)

This prompts you for two numbers and then an operation to perform on them. It
prints out the result of the operation on the two numbers. The translation
created for this program is:-

a = int(input('Enter a number'))
b = int(input('Enter another number'))
op = input('Enter the operation:')
if op == '+':
    print(a + b)
if op == '-':
    print(a - b)
if op == '*':
    print(a * b)
if op == '/':
    print(a / b)

How would someone know what words to use? That is done using the created maps.
The maps are stored as JSON in the languages folder. They are thus editable by
hand. Hence if some translation seems strange to you, you can simply edit by
hand to make it more to your liking. In order to know what a particular
function is called, you simply need to open the particular language file
(`$ gedit ./languages/RU` for russian) and look up the particular
translation pair.

After writing the desired code, we need to run it. Instead of the traditional
`python3` command we would have issued, we run the shell script called

That is all. We have successfully written python in Hindi. For other languages
similar procedures follow. To sum up, we need

1. Mapping of the required language
2. Source code with first line as `# `
3. Run the program with ` .py`

Have fun with the software and let those who may become great programmers
experience programming even without knowing the Latin script.

Wednesday, August 26, 2015


Recently I made available on PyPi, openjudge. This post is about that library.

Programming contests are popular among engineering colleges in India. Even in other colleges, wherever there happens to be a Computer Science department, a programming contest is sure to happen at least once a year.

Attending various contests in my graduation, I fell in love with them. There was no influence, no underhand tricks. Your code spoke for you. In the University of Delhi, there were contests happening left right and all across. Over the course of two years I began to like programming contests.

The cracks began to appear only once we hosted our own. Checking code was a pain. The accepted method was that contestants were asked to write code on paper for the preliminary rounds. They were simple programs and were designed to be easy to check. This was a huge bottleneck. The main rounds were held after about an hour of the preliminary rounds happening.

In the main rounds the institute provided machines and a compiler (sometimes an IDE) for an already declared language. That was a big handicap for us. We had to send teams proficient in multiple languages. This made life horrible and sometimes limited contests for us.

Then came

This website had removed everything we had resented and gone on to produce the perfect mechanism for hosting programming contests. Using the codechef platform however required authority from the Principal and so on. I did not bother.

Being bitten by the 'roll-your-own' bug, I decided to build my own judge. Hence openjudge.

First I had to set up an interface. For that I learnt Django. Then came communication over sockets. After that the problem of multiprogramming and sub processes.

Recently I am struggling with the ability to run these programs in a sandboxed mode. It is an experience which allowed me to grow with the project.

The software now boasts of a capability of handling ~200 participants at the same time. The format we now follow is:
  • Participants get their own machines. If they don't we provide and they cannot complain.
  • No language bars. We support all major languages.
  • A single round of competition. No preliminary and finals. One big code fight
  • A leaderboard for everyone to know who is winning.
Here are a few screenshots.

Tuesday, August 18, 2015


The following is an exchange between man and God... I think. Make what sense you will out of it.

Who are you?
Beyond you.

I can ask anything?
Yes you can.

Why can I not see you?
Because you can see.

Where are you?

Forever is a term of time. I asked for location.
Time is of your making. I answer the best I can.

You are not human?
I am not.

What is the difference between you and me?

You see things in chunks. They are not. You see things. They are not.

Thursday, August 6, 2015


Some years, some days ago
I came across a girl.

Not like any I haven't seen,
a life of another kind.

The wrath of Gods,
titanic and slow to rise,
swells within, dullness dies.

This mute heart screams,
A cry of pine, in my dreams.

I yearn for her,
some years, some days now.