Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Lets say you got some piece of code and you have no idea which language it was written in.

What are the unique "signature" syntax constructions for each programming language that you can use to quickly determine code origin?

(PS. Mentioning only one language in an answer probably would be a good idea. Having more than one answer for the same language is fine, lets vote for the best one)

share|improve this question

closed as not constructive by ChrisF Dec 10 '11 at 16:19

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

Identify the code in this image: – OscarRyz Nov 3 '10 at 19:47
Python, Perl, Ruby, C, brainf*ck and Befunge -… – user1249 Nov 30 '10 at 15:37
This is a pretty dope question. Forensics for code! Like if code was strewn about at a crime scene or something? – Mark Canlas Nov 30 '10 at 20:21

22 Answers 22

Perl uses

  • "use" to include a module
  • $ % @ for variables.
  • "my" and "our" to declare variables
  • "sub" to define a function
share|improve this answer
Unless it doesn't and someone is golfing. ;) – Ape-inago Mar 23 '11 at 9:07

Well, LISP-flavors tend to have a lot of parentheses.

share|improve this answer
A LOT of parentheses. – Kaleb Brasee Mar 23 '11 at 3:05


The function names will be either be onecontinuousword() or separated_by_underscores(). The words within the function name will be complete_words(), abbr(), some sort of hungarian_n(), or do something unexpected given the name, six2eight_weeks().

Functions with the exact same parameters usually take care to reverse the order, just to make sure that you're giving them the proper amount of love and attention. Of course, attention and love are often needed by functions with the exact same parameters. Sibling rivalry and all that.

If those methods of identification fail, you can always look for the PHP tags: <?php ?>, echo, the $ variable, $_POST, $_GET.

If looking at the code fails, look at the application. If it's a CMS, blog, forum, shopping cart, or a Facebook, Twitter, or Digg clone, chances are good that it's PHP.

share|improve this answer
PHP has no function naming nor parameter standard. They name things whatever they want using a mix of pascal case, camel case, underscores, sentence case, and all lower all in the same function. Its ridiculous. But thats why has the fastest and easiest documentation I've seen: – TheLQ Sep 28 '10 at 2:25

Ruby uses

  • "require" to include a module
  • "def" to define functions
  • "end" to end a block
  • "nil" for null
share|improve this answer
Pascal uses nil - and has been for decades, it was also used by Algol 68, so is older than "C"s use of Null. Basically Denis Richie chose one, Wirth et al chose another – Gerry Sep 29 '10 at 2:49
@GSTo: That is the difference between actual OO languages, such as Smalltalk, Objective-C, Ruby, etc. and the rest (C++, Java, C#, etc.). You see, NULL is just a reference to nothing or a pointer to 0. nil, as available in OO languages is an object, that responds to messages. See for ruby and for Smalltalk and Objective-C – back2dos Nov 30 '10 at 12:32


Check if 50% of the characters are dollar signs.

For people doesn't know PHP: This is actually a joke. All variable names start with dollar signs in PHP.

share|improve this answer
And then run the other way screaming. – David Lively Sep 27 '10 at 22:03
Good joke but the answer could cause misconception on who doesn't know PHP. – bigown Sep 27 '10 at 22:08
if I had a dollar for every one I wrote... – WalterJ89 Sep 28 '10 at 4:05

J, K, and APL look like a stream of censored swearing. In J, +/%# actually does represent a four-letter word: mean. APL in particular can be distinguished by the high frequency of non-ASCII characters.

share|improve this answer
APL's a good one because it's characterized by a bunch of symbols you don't have keys for. – Matt Olenik Sep 28 '10 at 0:09
Unless you have an APL terminal :) – Slomojo Mar 21 '11 at 0:16


A combination of:

  • Classes will be in PascalCase, whereas all primitive types will be lower case(1)
  • Interfaces will be in PascalCase starting with a capital 'I'
  • using 'someNamespace' at the top of a class. C++ includes, Java imports

These will obviously be different if the classes/interfaces are not from the .NET/Mono as naming conventions aren't enforced by the compiler.

(1)which can let you distinguish from C++ and Java because C# uses string while C++/Java uses String (though the latter is still possible in C# as well - I've found it less common)

share|improve this answer

Being my usual argumentative self, I offer a counterpoint to the other answers:


Cu  #%* )pop mark/CuG 4 def/# 2 def%%%%@@P[TX---P\P_SXPY!Ex(mx2ex("SX!Ex4P)Ex=
CuG #%*                                                                  *+Ex=
CuG #%*------------------------------------------------------------------*+Ex=
CuG #%*   POLYGLOT - a program in seven languages      15 February 1991  *+Ex=
CuG #%*                                                                  *+Ex=
CuG #%*   Written by Kevin Bungard, Peter Lisle, and Chris Tham          *+Ex=
CuG #%*                                                                  *+Ex=
CuG #%*   We have successfully run this program using the following:     *+Ex=
CuG #%*     ANSI COBOL:            MicroFocus COBOL85 (not COBOL74)      *+Ex=
CuG #%*     ISO  Pascal:           Turbo Pascal (DOS & Mac), Unix PC,    *+Ex=
CuG #%*                            AIX VS Pascal                         *+Ex=
CuG #%*     ANSI Fortran:          Unix f77, AIX VS Fortran              *+Ex=
CuG #%*     ANSI C (lint free):    Microsoft C, Unix CC, GCC, Turbo C++, *+Ex=
CuG #%*                            Think C (Mac)                         *+Ex=
CuG #%*     PostScript:            GoScript, HP/Adobe cartridge,         *+Ex=
CuG #%*                            Apple LaserWriter                     *+Ex=
CuG #%*     Shell script:          gnu bash, sh (SysV, BSD, MKS), ksh    *+Ex=
CuG #%*     8086 machine language: MS-DOS 2.00, 3.03, 4.01, 5.00 beta    *+Ex=
CuG #%*                            VPix & DOS Merge (under unix)         *+Ex=
CuG #%*                            SoftPC (on a Mac), MKS shell          *+Ex=
CuG #%*                                                                  *+Ex=
CuG #%*   Usage:                                                         *+Ex=
CuG #%*     1. Rename this file to polyglot.[cob|pas|f77|c|ps|sh|com]    *+Ex=
CuG #%*     2. Compile and/or run with appropriate compiler and          *+Ex=
CuG #%*        operating system                                          *+Ex=
CuG #%*                                                                  *+Ex=
CuG #%*   Notes:                                                         *+Ex=
CuG #%*     1. We have attempted to use only standard language features. *+Ex=
CuG #%*        Without the -traditional flag gcc will issue a warning.   *+Ex=
CuG #%*                                                                  *+Ex=
CuG #%*     2. This text is a comment block in all seven languages.      *+Ex=
CuG #%*                                                                  *+Ex=
CuG #%*     3. When run as a .COM file with MS-DOS it makes certain      *+Ex=
CuG #%*        (not unreasonable) assumptions about the contents of      *+Ex=
CuG #%*        the registers.                                            *+Ex=
CuG #%*                                                                  *+Ex=
CuG #%*     4. When transfering from Unix to DOS make sure that a LF     *+Ex=
CuG #%*        is correctly translated into a CR/LF.                     *+Ex=
CuG #%*                                                                  *+Ex=
CuG #%*   Please mail any comments, corrections or additions to          *+Ex=
CuG #%*                                       *+Ex=
CuG #%*                                                                  *+Ex=
CuG #%*------------------------------------------------------------------*QuZ=
CuG #%*                                                                  *+Ex=
CuG #(*                                                                  *(
C   # */);                                                              /*(
C   # *)  program        polyglot (output);                             (*+
C   #     identification division.
C   #     program-id.    polyglot.
C   #
C   #     data           division.
C   #     procedure      division.
C   #
C   # * ))cleartomark   /Bookman-Demi findfont 36 scalefont setfont     (
C   # *                                                                 (
C   #
C   # *                  hello polyglots$
C   #     main.
C   #         perform
C     * ) 2>_$$; echo   "hello polyglots"; rm _$$; exit
C             stop run.
     -*,                'hello polyglots'
C         print.
C             display   "hello polyglots".                              (
C     */  int i;                                                        /*
C     */  main () {                                                     /*
C     */      i=printf ("hello polyglots\n"); O= &i; return *O;         /*
C     *)                                                                (*
C     *)  begin                                                         (*
C     *)      writeln  ('hello polyglots');                             (*
C     *)                                                                (* )
C     * ) pop 60 360                                                    (
C     * ) pop moveto    (hello polyglots) show                          (
C     * ) pop showpage                                                  ((
C     *)
           end                                                          .(* )
C)pop%     program       polyglot.                                      *){*/}

--------------------End snip---------------------------

share|improve this answer
-1: This isn't a counterpoint to anything... – Steve Evers Sep 28 '10 at 15:15
What? That's not madness, actually that's how I make ALL my programs, just to keep compatibility... – user1827 Sep 28 '10 at 23:09
I'm sure that by carefully crafting spacing between statements we could make it compile in Whitespace as well ( – Newtopian Mar 23 '11 at 3:34

Python: lots of lines end with a colon, and the subsequent line has greater indentation.

share|improve this answer


  • Usually 2-space indent
  • end finishes a block
  • require at top
  • < means extends in class definitions
  • 50.times loops
  • def ... end for functions
  • nil is null

Ruby vs. Python

  • 2-space vs 4-space (or 4-space tab) indent, by coding conventions
  • : begins a block
  • no end in Python
  • true false nil vs. True False None
  • list.each do |x| vs. for x in list:
  • require vs. import


  • 5 + (6 * 5), which has parens, unlike in other languages
share|improve this answer

I think the approach with one-language per post makes it difficult to provide a coherent way to distinguish languages, so I'm putting this into one post:

How to separate brace-and-semicolon languages (i.e. C, C++, C#, Java, Javascript):

  • if it has class or new keyword it's NOT C
  • if it has struct keyword it's NOT Java
  • if it has var keyword it's Javascript or C#
  • if it has template keyword (not just <>s) it's C++
  • if it has function keyword it's Javascript/Actionscript
  • if it has the main function inside a class, and it's written as public static void main(String[] args) it's Java; otherwise if it has static void Main(string[] args) it's C#
  • if it has *p (pointers) it's neither Java nor Javascript/Actionscript

How to separate def-languages (i.e. Python and Ruby):

  • if it has end keyword it's ruby
  • if it has colons at the end of the def it's Python.

How to separate line-noise language (e.g. perl, APL, J, K):

  • if it has non-ascii letters, it's APL
  • if it's still barely readable, it's perl
share|improve this answer
var is also used for implicit typing in C# – Daniel Joseph Sep 28 '10 at 13:20
@Ape-inago: Scala runs on Java Virtual Machine, but the Scala Language has no relationship whatsoever to the Java Language. They are technically, fundamentally, and conceptually two separate languages that happens to compile to the same (virtual) machine language and standard library. The claim that Scala Language is related to Java Language is as good as claiming that C is related to VB since both compiles to x86 machine code and shares same libraries (or at least Microsoft's implementations of both languages do). – Lie Ryan Mar 23 '11 at 14:20
How to ensure whether it is a keyword in a context? If you know this, you are almost sure about the language. Same thing applies to others (end, template, public, static...) – mmdemirbas Jul 10 '12 at 13:13
var and function are also Pascal keywords – Matteo Jul 10 '12 at 13:53
"if it's still barely readable, it's perl" ... +1 – svidgen Aug 7 '13 at 23:53


  • begin end marking a block of code
  • := assignment operator
  • = comparison operator
share|improve this answer

Use the unix file command. It does this for you.

share|improve this answer

VB.NET declares its return type after the function parameters.

But then again, VB.NET is pretty easy to discern no matter what =/

share|improve this answer

Objective-C is an easy one. If there are a lot of square brackets, it's Objective-C

[[[[[MyClass alloc] init] autorelease] retain] release];
share|improve this answer
guh, that's a horrible code example. Use something compilable instead: [[MyClass alloc] initWithString: [NSString stringWithFormat: @"Bob %@ %f", myStr, myFloat]]; – Stephen Furlani Nov 30 '10 at 14:37
While it may not be the best example of good code, it is indeed compilable. – Jasarien Nov 30 '10 at 14:49

If you see this:

It could be Whitespace

programming language developed by Edwin Brady and Chris Morris at the University of Durham (also developers of the Kaya and Idris programming language). It was released on 1 April 2003 (April Fool's Day). Its name is a reference to whitespace characters. Unlike most programming languages, which ignore or assign little meaning to most whitespace characters, the Whitespace interpreter ignores any non-whitespace characters. Only spaces, tabs and linefeeds have meaning. An interesting consequence of this property is that a Whitespace program can easily be contained within the whitespace characters of a program written in another language, except possibly in languages which depend on spaces for syntax validity such as Python, making the text a polyglot.

The language itself is an imperative stack-based language. The virtual machine on which the programs run has a stack and a heap. The programmer is free to push arbitrary-width integers onto the stack (currently there is no implementation of floating point numbers) and can also access the heap as a permanent store for variables and data structures...

share|improve this answer
I don't see it. – Alan Pearce Nov 30 '10 at 15:04

Forth: Lots of lines of the form : ... ;, with the ... being strings of more or less comprehensible symbols.

share|improve this answer

If it's all in uppercase, it's probably one of:

  • BASIC (if variables are declared with the DIM keyword)
  • COBOL (if every line ends with a period)
  • FORTRAN (if every statement starts in column 6)
  • PL/I (if variables are declared with 'DECLARE' [or 'DCL']) or
  • (PL/)SQL (if you see keywords like 'TRIGGER' or 'SELECT')
share|improve this answer


(function(...) {...})(...);
share|improve this answer

If you could've typed the entire program using just three fingers of your right hand and your left pinky, it's probably Brainfuck.

share|improve this answer

Bash: Look for those silly "fi" and "esac" statements at the closing of if and case/switches

VB.Net: Does it look like bad broken english, probably VB.Net, because everyone knows VB actually stands for VerBose.

Ook Ook: Ook? Ook. Ook! Ook! Ook. Ook!

share|improve this answer
0100 LET A1 = 1
0110 ON A1 GOTO 300, 400, 500
0120 GOTO 600
0320 GOTO 600
0430 GOTO 600
0600 END
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.