Click here to Skip to main content
12,767,637 members (45,203 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 30 Oct 2014

A Natural Programming Method - Programming with Natural Language

, 30 Oct 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
The method doesn't replace existing Computer Language. Natural Language and Computer Language have to cooperate with each other.



Are English and C different languages? Yes, the former is a natural language, and the latter is a computer language. Do they share something in common? Yes, they do, they are both logical languages. Since they are both logical languages, why don’t we just write English text to run a computer? Why do we program a computer with a computer language rather than a natural language? In the following text, we will be using natural language to program. When we refer to characters, we mean Hanji, aka Kanji in Japanese or Hanja in Korean, and Kana, Hangul. Characters are romanized when present in following text. One cell of a lookup table holds a definition for the table key. A definition is a language element such as a statement, a declaration, and so on.

Below is a dictionary for terms we use in the following paragraphs.

HangulSyllabic blocks of letters as Korean characters
HanjaChinese characters
HanjiChinese characters
Japanese languageA language using Kanji, Hirakana, and Katakana
KanaSyllabic Japanese characters known as Hirakana and Katakana
KanjiChinese characters
Korean languageA language using Hangul and Hanja
Taiwanese languageA language using Hanji and Latin alphabet

Below is another dictionary for the characters we use in the following paragraphs.

ÌNv. to print
LIO̍Kv. to record
n. records
LIO̍K ÌNv. to record the voice and then print it out
SOKv. to speed up the printer
SOK LIO̍K ÌNv. to speed up the printer, record the text, and print it out
SOK TSUÁN ÌNv. to speed up the printer, transfer the text, and print it out
TSUÁNv. to transfer
n. transfers
TSUÁN ÌNv. to transfer the text and print it out

Programming with Natural Language

Let’s have a look at the example code before diving into the details. Below is a lookup table:

LIO̍K: def record end
  ÌN: puts "a short example"; puts "This is a longer example."

The table has two Hanji table keys. For one of the table keys LIO̍K, which means "to record", it has one definition "def exemplify end." For the other table key ÌN, which means "to print", it has two definitions. One is puts "a short example," the other is puts "This is a longer example." They are separated by a semicolon. We can then compose LIO̍K and ÌN to form a phrase "LIO̍K ÌN." Any two given characters can be combined together and remain syntactically correct. No declension or conjugation is required. The pronunciation does change but we don’t cover this topic here. Below is the combined phrase and its correspondent code snippet:

// LIO̍K ÌN 
def record
  puts "This is a longer example"

Why is only one definition of ÌN is combined with LIO̍K’s definition? The selection of one of the definitions is regulated by a lookup rule as shown below:


The rule says, when ÌN is appended after LIO̍K, the 2nd definition of ÌN is selected and 0 means "don’t care" for LIO̍K. And why is ÌN nested in LIO̍K? Because the combination rule for LIO̍K and ÌN is as following:


A Greater Than symbol can mean the 1st character nest the 2nd one.

The English phrase "wise up" means "become aware of or informed about something," according to Oxford Dictionaries. It doesn't mean "become wise and go up." It changes the original meaning of "wise" and "up" to some extend and comes out with a new meaning. When any two characters form a phrase, the latter also somewhat changes the original meaning of the former. We would otherwise use a series of C macros to program the code if the meaning of a phrase is just a simple accumulation of the meaning of the individual word or character.

The Ambiguity

A character can have more than one definition when it is composed in a sentence. The same rule holds true for an English word. The above code snippets are an unambiguous example. Here is an ambiguous English example:

The house can be bought for 10 dollars or 1 million dollars.

The subject "the house" has 2 meanings. For 10 dollars, it means a toy house. For 1 million dollars, it means a concrete house. The lookup table for this English sentence is shown as below:

        The house: acquire(theToyHouse); acquire(theConcreteHouse); 
       10 dollars: pay(10);
1 million dollars: pay(1000000); 
can be bought for: void buy() {}

The lookup rule is as following:

       The house.10 dollars:1.0 
The house.1 million dollars:2.0

The first definition of "The house" will be selected for 10 dollars. The second definition of "The house" will be selected for 1 million dollars. We would then have 2 meanings for this sentence. One is "The toy house can be bought for 10 dollars." The other is "The concrete house can be bought for 1 million dollars." The combination rules is as following:

can be bought for >

"can be bought for" will nest all other statements, which is presented by a Greater-Than symbol. There are no combination rules set for others words in the sentence, so sequential combination is assumed for the other 4 statements:

void buy() {

Not Polymorphic

Polymorphism is a feature of object-oriented programming. Polymorphism allows an object of a derived class to be passed to a polymorphic function which accepts a reference to its base class. The is-a or kind-of relationship is guaranteed through inheritance of class. Thus we say the derived class is substitutable for base class.

The method has nothing to do with polymorphism. It does compose polymorphic code, but it is not involved in dynamic binding. When program code is composed, we are also composing a natural phrase or sentence in parallel. We may as well use the literal meaning of is-a or kind-of relationship to refer to the polysemy or monosemy of a word or character. The relationship is then obviously not guaranteed through inheritance of class, but through polysemy or monosemy of a word or character.

Another Perspective of Code

The method is not intended to replace computer language. In fact, it provides a new perspective of source code.

When we write program in a traditional way, firstly a thought or idea is formed in our brain. We then break down the thought or idea into logical units. The process of breaking down the thought or idea is mostly conducted by induction and deduction. The logical units, such as function calls, variables, or class declarations, are constructed and organized into a working program. Then this well composed program code is ready to be parsed, interpreted or compiled, and then executed.

From another perspective of source code, we can break it up into statements. Each statement in a program code is composed in such a way that it forms a nested or sequential combination with previous or next statement. Given that, each statement can be represented by a word or character. We try to make it easier to understand by assigning only one word or character to each statement, a statement could be represented by a couple of words or characters though. We can then have a sequence of words or characters, which should be in itself a phrase or sentence of natural language.

Not a Mere Translation

A computer language is made of a fixed set of keywords and punctuations. Furthermore, the keywords of main stream computer languages are all English words. There have been efforts made to develop non-English-based computer languages. They are, however, not widely used all over the world. The non-English-based computer languages have non-English keywords. They are suitable for those programmers whose mother tongues are not English.

Do English-based and non-English-based computer languages have something in common? Yes, they are all logical languages. A few of them are mere translations from existing computer languages. By translation, I mean the keywords are translated from English- based computer languages.

The method is not a mere translation from any computer languages. As the title suggests, a programming method has to be operable. We can operate the method to write computer programs. In other words, we write computer programs via this method.

The method is also not a Text Entry Method/Input Method. A text entry method is just a software tool we use to generate a sequence of words or characters by typing on keyboard. The generated sequence of words or characters will then be used by the method. The method can sure co-work with non-English-based computer languages.

Reducing Barriers to Entry

The method is a step further from computer language to human beings. It intermediates between computer language and programmers. Since it intermediates, there has to be a mechanism for it. The words or phrases we type in natural language will be mapped to certain statements in computer language via this mechanism. Since we type in natural language, we understand the source code through natural lexicon and sentences. Since we can understand computer language through natural language, we definitely reduce the entry barriers to computer languages.

When we assign a word or character to a statement, the word or character itself can be regarded as a comment to the statement. It may not be an elaborate one, but it could just co-exist with source code comments. They can refer to each other.

Adaptive Design

When we assign a set of statements to a word or character, what we are actually doing is providing options to it. One of the provided options will be selected according to the context of a natural language phrase or sentence. In other words, the action of selecting means adapting to the context. If the context changes, the selection changes. When code can be adaptive to the context, it can be more flexible and responsive to the context.

We can view source code as 2 parts in terms of adaptation, one part is adaptive and the other is unadaptive. Where does adaptation come from? A software program may be fitted into a variety of hardware. A software program may be even used by different users under different conditions. An adaptive software program can be responsive to the context with the support of its unadaptive program core. The adaptive part of software program makes the unadaptive part flexible and responsive, and the unadaptive part of software program provides core functionality to the adaptive part and support it. Let’s add a new entry TSUÁN to the lookup table:

 LIO̍K: def record end
TSUÁN: def transfer end
   ÌN: puts "a short example"; puts "This is a longer example."

Add a lookup rule like this:


And add a combination rule like this:


We can hence get the code snippet by writing a phrase TSUÁN ÌN:

def transfer
  puts "a short example"

It is obvious that we switch the meaning of ÌN by replacing LIO̍K with TSUÁN, so that ÌN is adaptive and responsive to the changing context of ÌN. We can also add unadaptive code to the snippet. Provided the character SOK means to speed up a virtual printer for printing text, we can add a new entry SOK to the lookup table:

  SOK: def speedUpPrinter end
 LIO̍K: def record end
TSUÁN: def transfer end
   ÌN: puts "a short example"; puts "This is a longer example."

And add 2 entries of combination rules:


The notation Less-Than followed by a Greater-Than means that SOK and LIO̍K forms a sequential combination. In other words, SOK does not nest LIO̍K and SOK is not nested by LIO̍K. The same rule applies to SOK and TSUÁN. In practice, we can usually assume sequential combination for any two adjacent characters and omit the combination rules for them.

Hence for the 2 phrases SOK LIO̍K ÌN and SOK TSUÁN ÌN, we have their relative code snippets:

def speedUpPrinter

def record
  puts "This is a longer example."


def speedUpPrinter

def transfer
  puts "a short example" 

SOK is therefore the unadaptive part of the code.

Co-working with Existing Computer Languages

The method doesn’t replace existing computer language. Natural language will be co- working with computer language. The operations applied on natural languages will be reflected on the combinations of statements of computer languages. The following are examples for the method to co-work with different programming languages, such as the lookup table for Python:

  SOK: def speedUpPrinter():
 LIO̍K: def record(): 
TSUÁN: def transfer():
   ÌN: print 'python code'; print 'longer python code'

The Python code snippet for the phrase SOK TSUÁN ÌN:

def speedUpPrinter():

def transfer():
  print 'python code'

The lookup table for C:

  SOK: void speedUpPrinter(){}
 LIO̍K: void record(){}
TSUÁN: void transfer(){}
   ÌN: printf("c code\n"); printf("longer c code\n");

The C code snippet for the phrase SOK TSUÁN ÌN:

void speedUpPrinter(){

void transfer(){
  printf("c code");

The lookup table for Swift:

  SOK: func speedUpPrinter() {}
 LIO̍K: func record() {}
TSUÁN: func transfer() {}
   ÌN: println("swift code"); println("longer swift code")

The Swift code snippet for the phrase SOK TSUÁN ÌN:

func speedUpPrinter(){

func transfer(){
  println("swift code") 

The lookup table for XML Markup languages:

  SOK: <printer>speeding up</printer>
 LIO̍K: <records> </records>
TSUÁN: <transfers> </transfers>
   ÌN: print xml text; print longer xml text

The XML code snippet for the phrase SOK TSUÁN ÌN:

  speeding up
  xml text

Not a Programming Paradigm

The method can be applied to existing programming paradigms, being it functional, procedural, or object-oriented. Given a code snippet, it can be parsed into 2 types of combination. One type is nested combination, and the other type is sequential combination. In the example of C language, a for-loop can enclose a couple of statements. We can say for-loop is the nesting statement and the enclosed statements are the nested statements. In the example of a function definition, the function name and its return type are the nesting statement and the function body is the nested statement. The next one is sequential combination. When 2 statements are aligned with the same indentation, we say they form a sequential combination. For example, when 2 function calls are aligned, we say they are sequential.

The method is not a new programming paradigm. In other words, a programming method is not a programming paradigm. The method can also be applied to any newly invented paradigms. The lookup table for Object-oriented paradigm:

  SOK: void speedUpPrinter() {}
 LIO̍K: void record (PrintingObject prnObj) {}
TSUÁN: void transfer (PrintingObject prnObj) {}
   ÌN: prnObj.Print(); prnObj.PrintLonger();

The Object-Oriented code snippet for the phrase SOK TSUÁN ÌN:

void speedUpPrinter(){

void transfer(PrintingObject prnObj){

The lookup table for Scripting paradigm:

  SOK: function speedUpPrinter(){}
 LIO̍K: function record(){} 
TSUÁN: function transfer(){}
   ÌN: alert('javascript code'); alert('longer javascript code')

The Scripting code snippet for the phrase SOK TSUÁN ÌN:

void speedUpPrinter(){

void transfer(){
  alert(‘javascript code); 

The lookup table for Functional paradigm:

  SOK: (defun speedupPrinter)
 LIO̍K: (defun record ()) 
TSUÁN: (defun transfer())
   ÌN: (format t "lisp code"); (format t "longer lisp code")

The Functional code snippet for the phrase SOK TSUÁN ÌN:

(defun speedupprinter)
(defun transfer()
  (format t "lisp code") 

The lookup table for Declarative paradigm:

  SOK: #speedingUpThePrinter {transition-duration: 1s;}
 LIO̍K: #records {} 
TSUÁN: #transfers {}
   ÌN: background-color: #ffffff; background-color: #000000

The Declarative code snippet for the phrase SOK TSUÁN ÌN:

#speedingUpThePrinter {
  transition-duration: 1s;

#transfers {
  background-color: #ffffff 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Tsun-Huai Soo
Taiwan Taiwan
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralNice job!!! Pin
Member 106156248-Jan-15 12:48
memberMember 106156248-Jan-15 12:48 
GeneralRe: Nice job!!! Pin
Tsun-Huai Soo8-Jan-15 15:44
memberTsun-Huai Soo8-Jan-15 15:44 
QuestionNice! Pin
Volynsky Alex30-Oct-14 10:05
professionalVolynsky Alex30-Oct-14 10:05 
AnswerRe: Nice! Pin
Tsun-Huai Soo30-Oct-14 15:58
memberTsun-Huai Soo30-Oct-14 15:58 
GeneralRe: Nice! Pin
Volynsky Alex30-Oct-14 18:23
professionalVolynsky Alex30-Oct-14 18:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 30 Oct 2014
Article Copyright 2014 by Tsun-Huai Soo
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid