Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

It seems like Python, PHP, and Ruby all use the name "argv" to refer to the list of command line arguments. Where does the name "argv" come from? Why not something like "args"?

My guess is that it comes from C, where the v would stand for "vector". Wikipedia has a footnote that says:

the vector term in this variable's name is used in traditional sense to refer to strings.

However, there isn't any source for this info. Really, I'm curious if it has roots that trace even farther back. Did C use it because something before that used it?

share|improve this question
1  
and I always the the "v" stood for "values" –  warren May 6 '13 at 18:25

3 Answers 3

up vote 23 down vote accepted

While the other answers note that argv comes from C, where did C get the idea to call an array a "vector"?

Directly, it came from BCPL. Though argv refers to the vector of (string) arguments, BCPL did have strings stored in vectors, but they were string literals and they worked like Pascal strings. The vector had two elements: the length at literal!0 and the characters at literal!1. According to Clive Feather, strings were manipulated by "unpacking" them into character arrays, transforming the array then "repacking" them into strings: compare this with C where strings are character arrays.

So yes, C used v for vector because something else had done so before. Now, did anything before BCPL use vector in this way? BCPL was itself a simplification of the "Cambridge[or Combined] Programming Language": this used vector as a synonym for a 1-dimensional array and matrix as a synonym for a 2-dimensional array. This is consistent with the notation in mathematics of vectors and matrices, though in CPL they're just handy mnemonics and don't have any of the properties associated with the mathematical structures.

Can we push back further in time regarding computing languages? One potential branch of our trail runs cold. CPL was heavily influenced by Algol 60 (the 1963 update). Now ALGOL 68 had types that were described as "packed vectors", such as bits and bytes: but these weren't in earlier releases of Algol which just had ARRAY referring to array. As BCPL comes from 1966, CPL must have been before that (but after 1963): ALGOL 68 (standardised in 1968 and 1973) cannot have been a direct influence.

On the other hand, Main Features of CPL also makes reference to McCarthy's LISP system. While this doesn't use vector to refer to a data structure in the system itself, those being S-expressions, M-expressions and L-expressions (L-expressions are strings, so any association between vector and string has disappeared), it does use vector in another sense to represent the "values of a number of variables" representing "the state of the machine at any time". So we have evidence for an assumption made in the comments: that use of the word 'vector' to mean 'array' in computing comes from application of the similar term in mathematics.

share|improve this answer
1  
It was also present in B, coming as it did between C & BCPL. –  Robbie Dee Apr 30 '13 at 19:18
5  
And where did BCPL get it? From mathematics, in which a "vector" is a one-dimensional list of values. –  William Shakespeare Apr 30 '13 at 20:12
2  
Representing a string of characters as a vector is way older than BCPL (see, for instance, any old book on the theory of computation). In fact, the concept is probably older than the word "string" (as a sequence of characters) itself.. –  BlueRaja - Danny Pflughoeft Apr 30 '13 at 22:22
1  
@Caleb is correct. At the time of BCPL (~1967) and APL (~1960), most programmers were educated in Mathematics departments. In those days, there were almost no undergraduate CS programs. –  Ross Patterson May 1 '13 at 0:40
2  
@RossPatterson CPL comes from Cambridge, which had a computer science degree since 1953 (albeit as a conversion course). It was likely to be one of the few places not short of CS graduates by the 1960s. –  user4051 May 1 '13 at 8:00

argv comes from C, where the main() function takes an argv parameter that represents a vector of arguments to the program. You could also say that it comes from Unix, which is nearly the same as saying that it comes from C as most Unix development happened in C, and Unix and C have a long shared history.

share|improve this answer
1  
Always thought argv means "argument values" glad I learned something new :) –  Honza Brabec Apr 30 '13 at 22:56
2  
Right and argc (argument count) was the number of items in argv, because in C, arrays don't have fixed dimensions. –  Ross Patterson May 1 '13 at 0:37

In C the main() function can take two parameters: argc, which stands for "argument count", and argv, which stands for "argument vector". In C you do not have fancy objects like vectors, which is why you have to pass in the number of items as argc. In contrast, the languages you've mentioned have things like vectors or lists which know their own size, so argc is not needed. But the name argv stuck.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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