Why make your own language?

At the International PHP Conference 2001, Sterling Hughes was given a lecture on PHP Internals where he mentioned that, using the new filters in Apache 2, you could run a PHP script, send the output to TCL, and finally parse the end result with Perl. One member of the audience piped up with the question, "why would you want to?", to which Sterling's answer was "because it's cool". So, in answer to the question, "why make your own language using PHP?", the obvious answer is because it's cool .

There are reasons too. Making your own language is a popular Unix pastime that fulfils one of the key tenets of Unix programming: write programs to write programs wherever possible. This is rule 14 of 18 listed in Eric Raymond's book, "The Art of Unix Programming", and it is certainly a rule worth keeping mind. You see, if you have to regularly write code to perform approximately the same task, you are better off inventing your own mini-language that lets you abstract the problem - it is faster and easier in the long term, and also less prone to error. Although the language we start to create in the following chapters is general purpose, you could write your own specific language for anything - controlling household devices, calculating pi to the n,000,000,000,000th place, or even modelling the behaviour of cats.

 

Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: The elements of a compiler >>

Previous chapter: Making your own language

Jump to:

 

Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.