14

A similar example is field of carrots or carrot field.

The latter feels better to me, especially in the carrot example, but when asking colleagues they preferred 'array of ints'.

I'm not a professional writer, so I don't know if there is a clear winner, or what the answer should depend on.

9
  • 5
    google ngrams seems to be fairly on the fence about "array of integers" vs "integer array", but favors both over the "int/ints" variant. I'd say, flip a coin.
    – user54131
    Commented Jun 28, 2022 at 13:17
  • 2
    Not a writer but a developer. In prose I would definitely say "array of ints". If you say "int array" I'm thinking maybe you mean an array that holds a maximum of 2^32 (a typical int has 32 bits) elements or something like that.
    – AndreKR
    Commented Jun 29, 2022 at 0:57
  • 2
    @AndreKR: What languages do you develop in? As a C / C++ / assembly guy, I didn't even consider the index-range being that of int. (And int is a signed type, so at most 2^31 elements for non-negative indices). I don't think that's a sensible reading of "int array", so I'm curious what mental context would lead to someone else finding that sensible. (Genuine question, not saying you're wrong.) Commented Jun 29, 2022 at 1:54
  • 1
    @PeterCordes Since it obviously doesn't mean "array of ints" (because then the author would have written that) my brain was searching for alternative interpretations. I'm not saying that the "maximum number of elements" is something that would normally be on my mind. Languages would be mainly C, Go and Rust.
    – AndreKR
    Commented Jun 29, 2022 at 2:44
  • 2
    @AndreKR: Ok, I can see that reasoning I guess, if you for some reason thought an author wouldn't write "int array" for this case. But I think it's somewhat common to say "int array" for this, especially given the way C type declarations work. e.g. int a, arr[8] is list of declarations where the base type is int, declaring a as a scalar int, and arr as an array of 8 int elements. Since the element type comes first in C-like languages, it's pretty natural to end up with the English phrase "int array". Commented Jun 29, 2022 at 2:48

8 Answers 8

24

They both have subtly different connotations. An array of integers gives the connotation of an array filled with or containing integers. An integer array gives the connotation of an array that is for integers.

So the difference is that one describes the contents of the array (array of ints) and the other describes the array itself (int array). So while in general that difference is subtle enough to not matter too much I would say that you can use that difference to decide which is better in your use case.

As for which is more readable I would say they are evenly matched except in the case where the array's ints are "of" something else. Ex: "Int array of heights" is more readable than "array of ints of heights".

Bonus Notes About the Carrots Example:

A carrot field is a field that is meant for carrots (or used for carrots) while a field of carrots can be a field of planted carrots or a field covered in carrots or a field constructed out of carrots, etc. Again there is overlap in the connotations but there are also differences that might matter depending on the circumstances.

9
  • 2
    For your last example, "array of integer heights" scans pretty well to me.
    – Barmar
    Commented Jun 29, 2022 at 14:37
  • 3
    In programming languages that require type declarations, the distinction you make in the first paragraph almost doesn't exist. An integer array is by definition an array of integers. Different wording can be used to express intent or emphasis.
    – Barmar
    Commented Jun 29, 2022 at 14:41
  • 2
    @Barmar its true that if one meaning is true then so is the other. However there is a difference in what I want to say about it. Ie the difference between 'this gun killed him' vs 'he was shot by this gun" Commented Jun 29, 2022 at 14:46
  • 5
    @Barmar unless the array is empty. I can create an integer array that does not actually have any integers in it. Depending on the context, that can be a very important distinction.
    – Seth R
    Commented Jun 29, 2022 at 15:08
  • 1
    Illustration of some differences highlighted by this answer... "due to mixing up the seeds, I ended up with a field of parsnips in my carrot field", or "due to using the wrong conversions, I ended up with an array of bytes in my int array"
    – Steve
    Commented Jun 30, 2022 at 6:16
6

When it comes to readability, I think the only true test is to survey humans. Algorithms and rules will always fall short. Readability is by definition how readable something actually is for general humans, not how readable it "should" be.

So just listen to the consensus you've gotten. If you haven't surveyed a large number of colleagues, then maybe put out a larger survey to get more data.

2
  • Are you saying you are a robot? Asking on Stackexchange is nominally surveying humans. Commented Jun 30, 2022 at 21:46
  • 1
    @user2617804 survey-type questions are off-topic on any stack exchange site.
    – levininja
    Commented Jul 1, 2022 at 1:16
2

In my subjective opinion as a software engineer, you should consider a wider set of options. Here are some examples:

  • A file descriptor array (abbrev. "fd array") is an array containing file descriptors, which are integers, but the fact that those integers identify open files is important context which should not be ignored (because we must not forget to close them).
  • A size array is an array containing sizes (which are probably size_t or ssize_t, but those are integer types). Again, the meaning or context of the integers is important information which we prefer to remember. Similarly, an offset array contains offsets (which probably should be off_t or ptrdiff_t, but might be ssize_t in practice).
  • Technically, char is an integer type too, so an array of char could be called an "integer array," but that would be very confusing. Prefer buffer or byte array, or a more specific term depending on the purpose and structure of the buffer (e.g. a "ring buffer" is a buffer that wraps around when you reach the end, a "string" contains textual data, etc.).
  • If the array is "just" an opaque input to an algorithm, and the algorithm "doesn't care" what the integers represent, then you could call it either an integer array or an array of integers. I don't think the average developer will care much either way, as both are readily understood.
2
  • 1
    An "integer array" could describe a signed char vals[1024] if you're actually using char as a narrow integer type, i.e. in its int_least8_t role, rather than its other usage in C as a raw byte. (Most uses of char as an integer type should be signed char or unsigned char, though, rather than raw char leaving the signedness up to the implementation. But if you only ever have 7-bit integers, you could use plain char and it will always be non-negative if signed.) But yes, agreed, don't call it an "integer array" if you're holding text or file data or whatever. Commented Jun 29, 2022 at 2:00
  • here i just meant to say it's an array of integers. your right that this documentation is a bit redundant when im writing in a structured language. Commented Jun 29, 2022 at 14:42
1

Consider the context in which you'll use the phrase.

An advantage of "int array":

As a noun modified by a noun, it is slightly shorter (no "of"). It can be used as a noun phrase to modify yet another noun, e.g. "int array sorting", "int array sorting algorithm".

An advantage of "array of ints":

You can use an adjective to describe either the array or the ints, and the adjective's position clearly indicates which you've done. In "an array of big ints" the individual ints are big; in "a big array of ints" the array is a big one.

1

Which is more readable - array of ints or int array?

In C,"int array" has an advantage. Type names are not well suited for pluralization.

int is a type, ints may be a user defined type. Best to express type names exactly and not pluralize them or otherwise append prefixes and suffixes.

When describing programming language type code, consider using typography to clarify. "int array" instead of "int array", "array of ints" vs. "array of ints"

1

Firstly, if int is a particular datatype, you should make sure it's formatted differently to other text to signify that you are talking about a specific datatype rather than integers in general. That's far more important than whether you use "array of ints" or "int array".

Personally I would argue in favour of "array of ints" (or in the general case "array of integers"), because it's more formal and less ambiguous, both of which are reasonably important in technical writing. (As an added bonus, array of int is actually valid syntax in certain programming languages.)

If you can't decide, one option is to introduce them as synonyms for each other - to explicitly tell the reader that "int array" means the same as "array of ints", after which you would be free to use either, as appropriate, without confusing the reader (because both terms have been explained).

In general, you're best off introducing the terminology that you're going to use before you use it just to make completely sure that your audience understands what you're talking about (people who are used to different languages may have different expectations). This has the added benefit of potentially making your document more accessible to people who are less familiar with the terminology, e.g. novice programmers.

1

Just from the standpoint of a c# developer, reading left to right (natural for dare I say it most languages), then int[] is better enunciated as int array, rather than array of ints.

As someone, who though native English speaker is also fluent in German. I still find enunciating 21 as one and twenty (einundzwanzig) remarkably confusing (and the bigger the number, the worse it gets). It is the same principle. Stick to left to right.

0

If you are really not forced to use just the "natural language", I think that the most understandable is the good old

int[]

:)

Whenever it does not collide with the context, I would use this notation.

Examples:

You may store the results to int[], or you may use another data structure.
The fastest way to iterate over int[] is with a pointer.

If you really have to stick to natural language, I would vote for "array of ints" over "int array" with the following arguments:

  1. It's more in harmony with "array of elements" or "array of items", which sounds much more natural than "element array" or "item array".
  2. Your example with carrots also support this: int[] is much more analogous to "array of carrots" (array containing carrots/integers) than to "carrot array" (= a type of array).

"int array" would make sense only in the context of programming languages where there are several different types of arrays and "int array" is one of the types. (I am not aware of any language like this, but who knows.)

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.