The December 2022 issue of IEEE Spectrum is here!

Close bar

World's First Classical Chinese Programming Language

Programs written in the language include one for fortune-telling from the I Ching

3 min read
A rendering of a program written in wenyan-lang to draw the Mandelbrot set.
A rendering of a program written in wenyan-lang to draw the Mandelbrot set.
Image: Lingdong Huang

The world's first programming language based on classical Chinese is only about a month old, and volunteers have already written dozens of programs with it, such as one based on an ancient Chinese fortune-telling algorithm.

The new language's developer, Lingdong Huang, previously designed an infinite computer-generated Chinese landscape painting. He also helped create the first and so far only AI-generated Chinese opera. He graduated with a degree in computer science and art from Carnegie Mellon University in December.

After coming up with the idea for the new language, wenyan-lang, roughly a year ago, Huang finished the core of the language during his last month at school. It includes a renderer that can display a program in a manner that resembles pages from ancient Chinese texts.

"I always put it off and tried to read more books in classical Chinese. Eventually I decided that reading more books might be just a euphemism for procrastination, and I needed to just implement it," Huang says. "It was finals week and there were no classes. So instead of studying, I used the bulk of free time to implement wenyan-lang, finishing the core functionality within three or four days."

Growing up in Shanghai, Huang learned basic classical Chinese in school. "I got quite fascinated by the language and read more books in classical Chinese on my own as a teenager," he recalls. "Currently I'm reading the Huainanzi," an ancient Chinese exploration of philosophy and statecraft compiled at the court of the king of Huainan in the 2nd century BC.

Lingdong HuangLingdong Huang

There are already dozens of programs written in wenyan-lang, about half of which others wrote, Huang says. "Many of them are implementations of mathematical algorithms found in ancient Chinese math books. For example, pi_liuhui.wy recreates how 3rd-century AD mathematician Liu Huicalculated pi. Crt.wy is the Chinese remainder theorem. Pascal_triangle.wy computes Pascal's Triangle, which was described in Chinese books prior to Pascal's discovery."

One of Huang's favorite programs in wenyan-lang, he says, "is divination.wy. It is the fortune-telling algorithm described in the I-Ching," the oldest of the Chinese classics. He adds: "I was going to implement it myself, but an enthusiastic contributor beat me to it."

Wenyan-lang uses both traditional Chinese characters and classical Chinese grammar. One challenge in developing the language was how classical Chinese does not use spaces to divide sentences into words, "so how to split a sentence is a task of the reader and not the writer," Huang says. For example, if readers literate in English saw "pancakebatter," they would have to rely on their prior knowledge to decipher that as "pancake batter" and not "pan cake batter."

A rendering of a program written in wenyan-lang for the fortune-telling algorithm in the I-Ching.A rendering of the divination.wy program written in wenyan-lang.Image: Lingdong Huang

To overcome this challenge, Huang notes that programming languages only possess a set amount of keywords. As such, wenyan-lang goes from the longest keyword to the shortest keyword in each program to decipher what the programmer wants, "and it works," Huang says.

Huang was surprised and excited by the amount of attention wenyan-lang has received. "I thought I made a lot of cool projects before, but this one somehow became especially popular in China," he says.

"Before this I largely worked on my own at my own pace, but now collaboration has become crucial," Huang says. "In addition to co-authoring code, I have to review other people's code, carefully evaluate every suggestion, and decide if they're indeed valuable features for the language, or write friendly responses to explain why I don't think so if otherwise. But I think I'm enjoying the experience, especially since I've got a gang of amazing contributors."

Wenyan-lang Programming window and corresponding JavaScriptWenyan-lang programming window and corresponding JavaScript.Image: Lingdong Huang

Currently wenyan-lang contributors are working on transpilers for Python, Ruby, JavaScript, C++, and Java, libraries for graphics and the graphical user interface (GUI), as well as a snippet site where people can author and share bits of code. "Most importantly, we're seeking ways to build a community around the language," Huang says. "I think this might be a critical moment for its survival. People have the initial enthusiasm, but to keep the language alive, there needs to be a community of users."

In addition, Huang is currently working on an introductory guide to programming in wenyan-lang that is itself written in classical Chinese. "It is about 40 percent done," he says. "The target audience of the book can be someone with no prior experience with programming at all. However I'll need to test it with the aforementioned audience to make sure, as I believe some ideas that are natural to me might not be obvious to someone new to programming."

All in all, "now I have a programming language of my own, a language that is exactly how I want it to be, and in classical Chinese, which I very much enjoy," Huang says. "I think inventing one's own programming language is an idea that pops up in the mind of every programmer. (This best explains the plethora of programming languages today.)"

The Conversation (0)

Why Functional Programming Should Be the Future of Software Development

It’s hard to learn, but your code will produce fewer nasty surprises

11 min read
Vertical
A plate of spaghetti made from code
Shira Inbar
DarkBlue1

You’d expectthe longest and most costly phase in the lifecycle of a software product to be the initial development of the system, when all those great features are first imagined and then created. In fact, the hardest part comes later, during the maintenance phase. That’s when programmers pay the price for the shortcuts they took during development.

So why did they take shortcuts? Maybe they didn’t realize that they were cutting any corners. Only when their code was deployed and exercised by a lot of users did its hidden flaws come to light. And maybe the developers were rushed. Time-to-market pressures would almost guarantee that their software will contain more bugs than it would otherwise.

Keep Reading ↓Show less
{"imageShortcodeIds":["31996907"]}