Choosing indentation as a life style of programming

Cirru: the indentation based grammar

JiyinYiyong
Cirru Project
4 min readMay 28, 2014

--

Back in 2009 when I went to university and learn bady steps on programming. I was suggested the languages HTML/C/Python in a guide called “How to become a Hacker”. Later I chose to learn Python, but it didn’t until I learnt CoffeeScript that I found myself capable of programming.

That “How to…” article influenced me a lot. Years after that I still benefit from the notions it expressed. One of them is: “Don’t repeat yourself”. And another one is “Be creative”. I read the Chinese translation, I’m not that sure the what the original words are. But it works, and that’s how I got this far by self-teaching.

OK, let’s got the point: indentation based programming. To me, syntaxes with lots of brackets are just weird. Just think about it, I talking to someone and say “sentence end” each time I finish speaking a sentence. That’s weird. People don’t talk in that way. That’s how old machine works. By learning programming, we are trying to create great works that floating in our minds and even dreams. Why we spend so much time learning the accent of machines.

That’s why Python is nice. Python says, life is short. Yeah, comparing with the dreams, time of a life seems to be so insignificant. Here comes the indentation based syntax from Python. It somehow opened my mind that programming could also be like acient Chinese literature, which advocates conveying as much as possible emotions and details in limited words. That’s what I’m thinking about chosing writing things for my life.

In the mean time, languages that with a lot brackets tends to be less friendly on how programmers(I would say “users”) think, they just want to solve problems or just fit into the machine. These languages, like Java, use a huge IDE in developing programmes. Think about it, I chosing a life style of programming, but only few people would enjoy the heavy work like debugging Java. What we want is just a light and nice editor, just writing code and colorize our lives. That’s it, why such clumsy language?

In popular indentation-based langauges, like Python, CoffeeScript, Haskell, (somehow Ruby, Lua).. I like CoffeeScript and Haskell best. They aretrying to teach me think in a high-level but more compact way of programming. Whereas languages like C, JavaScript just try to focus the problem without caring about how much code or how it looks. In JavaScript, people use JSLint to validate the coding style. And for C-like syntaxes, there’s quite often acode formatter to make code tiye. Why not design a better syntax instead?

There was a time when I said “indentation-based syntax is superior than that with lots of brackets”, since C-like syntax exposes too much low-level details of the machine and slows down people thinking in higher levels. And my time spent on manipulating the code could have be reduced by cutting off so many characters. I thought it would be very normal to say, better languages are the ones designed with more friendly syntax and most the time it’s based on indentations. But some people laughed at me. One reason really hurts me, that I’m not a language developer and I don’t know the pros and cons. They declared that syntax is not even a key part of programming.

In some way, I think that right. Abstractions are very very important in programming. People may also writing brilliant code without introduing indentations. However, the indentations truly brought me efficiency and a better view of programming. The structure of my code in a indented tree looks cleaner, and edting code is muching easier. I don’t have to learn using IDEs and I already play well with so much code.

It has been long so far, so I’m trying to jump out and leave out more details. Just, I want to prove that indentation-based syntax is great, I have to show it. That’s why I wrote Cirru, a indentation-based grammar. People who have read my code may know I’m not good at “Fundamentals of Compiling” since I didn’t learn that in school(my friend made up me some lessons, though). So I chose a uncommon solution to parse the indentations by hand. Fortunately it works well. Projects around Cirru Grammar has grow into quite nice situation, related projects can be found on GitHub.

So far, besides the parser, I got some highlighting tool and editor plugins of Cirru. In my projects, I use Cirru to generate HTML. Also some projects are just trying to be fun and creation. One nice thing is GitHub recognizes .cirru files, though it syntax highlighting would not work before the next Pygments release.

It took me a long time, I tried hard to prove that those people are wrong about sticking to brackets. While me, I’m trying to embrace the future of programming. In the future, coding would be less about typing characters but more about editing the relationships of elements in GUIs. We still need some code, but the way preparing lots of brackets to satisfy the machine would be buried the countless creation of time and history. I’m looking forward.

--

--