Nithin Bekal

Posts About Notes Slides

What's This Programming Language?

02 Jun 2012

A couple of weeks ago, I came across the site “What’s that programming language?”, in which you’re shown a snippet of code and you have to identify the programming language.

I looked around to see if there was a way to do the reverse, ie. identify the language, given a snippet of code. Since I have no idea how to actually parse code and do this, I tried doing this using the highlight.js syntax highlighting library. Highlight.js has a highlightAuto() method that can be used as a simple way of doing this.

See the demo here.

The highlightAuto() method tries to highlight the snippet using all available languages and returns the language for which it identifies most syntactic structures. Obviously, longer code snippets are more likely to be identified.

You can fork the code for the demo on Github. Feel free to send in a pull request if you’ve made improvements to the demo. :)

Hi, I’m Nithin Bekal. I work at Shopify in Ottawa, Canada. Previously, co-founder of CrowdStudio.in and WowMakers. Ruby is my preferred programming language, and the topic of most of my articles here, but I'm also a big fan of Elixir. Tweet to me at @nithinbekal.