When talking about the source code of a program, my Computer Science teacher sometimes refers to single pieces of code as 'a code'. For example:

For today's task, you need to write a code which outputs "Hello World".

I feel that this is terribly wrong as I would say 'some code' or 'a piece of code'. E.g.:

For today's task, you need to write some code which outputs "Hello World".

Who is right, me, my teacher or both of us?


"Code" as usually used in the field of IT refers to source code of computer programs. My own intuition is that this is clearly uncountable, so you can speak of "some code" but not "a code". You can also speak of "the source code of a program", which means "the [representation of the program] as source code". However, "code" alone remains uncountable. You could speak of "a code" when used in a different meaning, such as: "he gave me a code with which I could open the locked door" (here "code" is a "hard-to-guess combination of letters/digits").

While Merriam Webster doesn't state anything about the countability of "code" used as shorthand for "source code", Wiktionary gives one of the meanings as synonymous with source code, machine code or bytecode, and these are described as uncountable.

Bytecode is described as countable and uncountable, and while it is not explicitly stated, it seems logical for bytecode (the byte representing a single instruction) to be countable and bytecode (a series of instructions represented as bytecodes) to be uncountable. I wouldn't object to using "a bytecode" in context such as: "this function consistes of a single bytecode", but "bytecode" in the latter meaning would behave like "source code" or "machine code" and be uncountable.


In American or British English, using "code" as a countable noun to refer to source code is wrong.

For an American source, see Merriam Webster's entry for the word "code", which gives the following definition...

instructions for a computer (as within a piece of software)

... with the following example usage, as a mass noun:

writing code for a new app

For a British source, see the entry in Collins which says:

uncountable noun
Computer code is a system or language for expressing information and instructions in a form which can be understood by a computer.

However, in Indian English, "code" is typically used as a countable noun. I have observed this usage from reading posts by Indians on Stack Overflow, from teaching in India, from being offered programming jobs by Indian companies, and from working with Indian colleagues. Indians will talk about writing "codes" (incorrect in British or American English) or even writing "a code", as in the example in the question here. For an example in the wild, see this page on an outsourcing website called Outsource2india which uses the word "codes" in this way five times.

This is one of the many ways that Indian English differs from the English that Americans or Brits like me are used to. Of course, whether Indian English is proper English in the first place is subjective; attitudes vary, among both Indians and non-Indians, on the question of whether Indian English is a legitimate dialect in its own right like British and American English are, or merely a collection of erroneous (and perhaps even mildly embarrassing) deviations from correct English, as spoken by the Queen. As such, I leave the judgement of whether this usage is "wrong" as a matter for you to decide according to your own beliefs.