3

When reading code, how do you say the following statement? (It was taken from some C# code, could be many languages, though).

List<string>

Do you say:

List of type string?

or

List of string

or

List of string type

or

Something else

6
  • 8
    I believe "list of strings" is most commonly used. But there really is no standard. Also, list is quite specific example. Other generic types and multi-type generics might be said differently.
    – Euphoric
    Oct 8, 2018 at 9:46
  • 15
    I have a tea mug with Mug<T> on it. If it isn't said as "mug of T" then my rubbish geek joke fails, so I definitely vote for saying it as "list of string".
    – David Arno
    Oct 8, 2018 at 10:09
  • 1
    String list. And @DavidArno you yourself call it a tea mug so the joke is still valid, sad, rubbish, and geeky, but valid nonetheless.
    – Bent
    Oct 8, 2018 at 10:19
  • 1
    @DavidArno That is amazing haha, where can I get one?
    – Jessica
    Oct 8, 2018 at 11:32
  • 4
    Note in VB.NET, the equivalent type is denoted as List(Of String) (which supports @Christoph's answer).
    – Doc Brown
    Oct 8, 2018 at 12:31

2 Answers 2

9

The common way is to say list of string.

It comes from the mathematical convention of pronouncing the notation of a function: f(x) is read as "f of x". The convention is as universal as mathematics, so every human language will have a local way of saying it.

Even if generics are not functions, they are a parameterized types. So instead of applying a function to an argument between (...), you apply a generic definition to a type argument between <...>. So by analogy, the same wording is used.

Sometimes, in case of ambiguity, the longer list of type string is used. But IMHO the longer form is used only if there would be a risk of confusion with a function parameter. Typically, when using C++ template function rather than template class.

2
  • 3
    "Even if generics are not functions" – Actually, they kind of are. A type constructor takes one or more types as an argument and constructs a type from those arguments, in just a same way that a function takes one or more values as an argument and constructs a value from those arguments. In fact, one of the reasons why the name "type constructor" was chosen for this, is that in some branches of mathematics, functions are called "value constructors". Oct 8, 2018 at 11:25
  • @JörgWMittag I agree. From an abstract lambda calculus perspective, it's just a function applied to types. I nevertheless preferred to use a more prudent wording, because language lawyers could contradict the claim with language specific definitions, syntax, and semantics.
    – Christophe
    Oct 8, 2018 at 11:54
2

Just as any other list of things, a list that consists of a certain type of objects, say holiday locations, is called a 'list of [object]s', e.g. a list of locations. So in your example a list of strings.

The functional perspective suggested by Christophe is possible as well, and might be more dominant around syntax/math oriented programmers. Typically the 'normal' way (list of strings) dominates when talking about actual instances, whereas the functional version (list of (type) string) might more likely dominate when strictly speaking about the type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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