Take the 2-minute tour ×
English Language & Usage Stack Exchange is a question and answer site for linguists, etymologists, and serious English language enthusiasts. It's 100% free, no registration required.

In programming books, I noticed that "a variable of type int," and "a variable of an int type" are often used interchangeably. Which one is the correct one?

share|improve this question
    
Which book have you encountered a variable of an int type in? –  Armen Ծիրունյան Feb 7 '12 at 15:38
    
@ArmenTsirunyan: I forgot the books. –  In PSTricks we trust Feb 7 '12 at 15:46

6 Answers 6

up vote 2 down vote accepted

As "int" is not a normal English word, it is difficult to say exactly how to use it correctly in a sentence.

So short answer: Both are readily understood and arguably valid.

Longer answer:

I think most programming books say "of type int".

If you try to parse it, I think "type" is the noun and "int" is an adjective specifying what kind of type. So given the rule that in English adjectives normally precede the noun they modify, the "correct" version would be "of int type".

On the other hand, the writer may be thinking of "int" as a noun. In that case we have a construction like, "She went by the name 'Sally'". I'm not sure what the rule is there, but you wouldn't say, "She went by the 'Sally' name".

It would also be legal and conventional to say "The variable has a type of int".

share|improve this answer

int is not an English word. int is a type name in many programming languages derived from the word integer. So you can't say a variable of int type. But you can say

A variable of integral type

But this could mean int, long, short etc.

Similarly, you can say, a variable of type bool, or you can say a variable of boolean type.

share|improve this answer
    
+1 for the fitting example. –  Kris Feb 7 '12 at 15:16
    
I am still wondering why type int can be used and int type cannot. In my understanding, the noun phrase int type stands for a type of int where int becomes the modifier. –  In PSTricks we trust Feb 7 '12 at 15:48
    
@CounterTerrorist: I'm not sure about the theory, but Ngrams clearly shows that of int type is extremely rare. –  Armen Ծիրունյան Feb 7 '12 at 15:55
    
But the "not English" terms int (and bool and long) are used within the text precisely to distinguish them from the generic integer and boolean and such, so I don't think your suggested answer is very helpful. –  Paul Richter Feb 7 '12 at 17:00
    
@Paul: I like the example of Jay's answer, which was basically my point. "She went by the name Sally" rather than "She went by the Sally name", right? Similarly, since int is simply the name of the type, "this variable is of type int" sounds more natural than "this variable is of int type". Where am I wrong? –  Armen Ծիրունյան Feb 7 '12 at 17:03

This is not standard English, but rather technical computer science speech.

Many programming languages have variable types organized into several classes. For instance, there may be types short int, long int, double int, all different from the compiler's point of view, but with similar properties that allow them to be referred to as int types. Analogous situations obtain at least for types real, complex, and char.

share|improve this answer
    
double int sounds like an oxymoron to me :) –  Armen Ծիրունյան Feb 7 '12 at 19:50
    
Depends on the implementation, nu? double int might be just the right type for Unicode Chinese characters, in some cases. The point is, it varies. –  John Lawler Feb 7 '12 at 21:43
    
Well, double usually refers to the type for double-precision floating point numbers rather than integers. At least in all the programming languages that I know, but I don't know that many of them :) –  Armen Ծիրունյան Feb 7 '12 at 21:54

As a professional programmer, I would expect people to say "a variable of type int" or, more commonly, simply "an int".

If I heard someone say "a variable of an int type," I would think that person or book was not actually a programmer themselves, but merely a tech writer not "fluent" in talking about programming details.

FWIW, Google Ngram Viewer agrees that "an int" is the way to go:

enter image description here

share|improve this answer

Without the context the answers will be speculative or just a "guessing game". Anyway, int is the abbreviated form of noun "integer", which means "whole number" as such 1,2,3, -4,-5.

Having said that, the "type" in "a variable of type int" has nothing to do with "int". Check the excerpt below:

"These are two valid declarations of variables. The first one declares a variable of type int with the identifier a. The second one declares a variable of type float with the identifier mynumber".

The writer wants to say "declare variable type as integer and variable type as float"

On the other hand, as John Lawler points out, in some programming languages these variable/data types may be subtyped into more categories according to their properties - as such "small int", "signed int", "unsigned int", "tiny int" e.t.c, which are integer types

share|improve this answer

Some computer programming languages have a whole family of int types: bare int, unsigned short int, long int, and so on. I would interpret "a variable of type int" as meaning the unadorned int, and "a variable of an int type" as meaning any member of the family of int types.

share|improve this answer
    
Wouldn't that be the family of integer (or integral) types rather than the family of int types? –  Armen Ծիրունյան Feb 8 '12 at 12:04
    
@ArmenTsirunyan No, it wouldn't. int, integral and integer are all different things. An integer is a mathematical ideal. A computer can never truly represent an integer because memory is finite, but it can approximate it. These approximations are called integrals. ints are typically a family of integrals that all use the same two schemes (one for signed and one for unsigned) to represent an integer with fixed bounds in a fixed block of memory. There are plenty of other schemes for representing integrals, most notably the variable sized integers. –  Pitarou Feb 9 '12 at 4:59

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.