5

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?

10
  • 2
    It's not a matter of being "right" but a matter of who is in the mainstream and who is way up a narrow tributary without a paddle. It is far more common to hear or read "You'll need to write code to ..." or "....to write some code to ..." than to hear "you'll need to write a code to ...". We're talking several orders of magnitude more common.
    – TimR
    Commented Nov 22, 2014 at 12:43
  • 3
    Beta, is your professor Indian or East Asian? I find the "a code" construction common in speakers of Indian English and native Chinese speakers.
    – Dan Bron
    Commented Nov 22, 2014 at 13:22
  • 2
    @Beta, weird. I've never heard a BrE speaker use "a code" that way.
    – Dan Bron
    Commented Nov 22, 2014 at 13:51
  • 2
    "A code", in that context, would be regarded as "odd" in the US. "Code" and "some code" are pretty much interchangeable.
    – Hot Licks
    Commented Nov 22, 2014 at 14:01
  • 1
    Using code as a countable noun seems to be more common in scientific supercomputing.
    – user323578
    Commented Apr 21, 2019 at 18:28

3 Answers 3

8

"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.

2
  • I think you've misunderstood "bytecode." "Bytecode" is always an intermediary step between source code and processor instructions. As such, talking about individual instructions in bytecode is rather useless, which is probably why I've never heard it done as a programmer. I can't find it being used in the singular anywhere; I do see some usages of "bytecode instruction," which is much more in line with what I'd expect. Otherwise, +1.
    – jpmc26
    Commented Jan 3, 2015 at 1:21
  • @jpmc26 Certainly, "bytecode instruction" is better since it is not ambigous. But I can't agree that "talking about individual instructions in bytecode is rather useless". I think usage such as in JVMS §4.10.1 makes sense: "Many tools that manipulate class files may alter the bytecodes of a method in a manner that requires adjustment of the method's stack map frames.". Since it's a single method, I think by "bytecodes" (plural) they are referring to the bytecode instructions which make up the bytecode (singular). Commented Jan 3, 2015 at 11:08
2

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.

-3

"code" is short for "source code"

Your version is correct. The teacher is wrong.

In this particular usage, however, using "source code" is not really ideal at all. The right expression is,

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

You write programs, you compile source code. In proper usage the term "source code" should only be used in the context of compiling. In other words, you have "source code" which compiles into "object code" which is linked into an "executable". Talking about "writing" source code is not really a correct usage, even though many laypersons who are trying to sound technical say it.

3
  • This is not true. Your examples work in a loose context but are not fully true. I can write code without ever creating an application (= code libraries). Creating an application is the most common reason to write code but by no means the only reason. No human ever writes an application. You write code, and the compiler builds an application based on the code you provided. Also, "code" is not always short for "source code". "Source code" pertains to one application. "Code" does not. A collection of different applications (source codes) will still be called "code" as an uncountabled noun.
    – Flater
    Commented May 15, 2017 at 14:57
  • Talking about "writing" source code is not really a correct usage It is literally the only correct usage. Code is exactly what a developer writes. It is the written instructions which a compiler will use to build an application. After the source code is written, the developer's job is done. Everything that follows is done by the compiler/computer.
    – Flater
    Commented May 15, 2017 at 15:01
  • If the programmer doesn't write the source code, where does it come from?
    – user323578
    Commented Apr 21, 2019 at 18:39

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