[Fortran] Naming conventions for integers

In summary, the convention of assigning letters starting with I to N to represent integer values originated in order to make it easier for scientists and engineers to use common math formulas and procedures.
  • #1
anorlunda
Staff Emeritus
Insights Author
11,308
8,733
Long ago I learned Programming in FORTRAN. I got used to the convention that names starting with I,J,K,L,M,N were INTEGER while all other letters were REAL. I thought it was a convention of FORTRAN only. Since then, I came to realize that the same convention is widely used in science and math independent of computer programming. But I do not recall ever being explicitly taught any such convention.

My question: what is the origin of this convention?

I'm posting it here under math as a guess as to the right forum.

P.s Wikipedia mentions this convention under "naming conventions (programming)", but it does not mention the origin.
 
Technology news on Phys.org
  • #2
In Fortran you don't necessarily have to declare variables. Just use them and voila! they exist. The default convention is that variables that start with I to N are integers. A variable whose initial character is A to H or O to Z means the variable is real by default.

Note: IMPLICIT NONE turns off this default convention and forces a programmer to declare all variables. That's the recommended practice for new Fortran code. There's a lot of very old Fortran code still in use. Getting rid of the default convention would mean that a lot of this old code would have to be rewritten.
 
  • #3
Why do you think such a convention was established for FORTRAN in the first place?

The letters I-N have commonly been used in matrix notation and elsewhere to represent index variables, dummy variables, exponents, etc. Since FORTRAN was designed to be a FORmula TRANslator, making the letters I-N represent integer values, I think, was seen as a convenience to induce scientists and engineers to write programs in FORTRAN by making for less fussing with variable types when using common math formulas and procedures.
 
  • #4
I am not a mathematician or a historian and, yes, the first time I ever heard that variables representing integers start with the letters I though N was when I learned Fortran...whether I might have used those letter for integers before I had learned Fortran is possible, then again, I started to go to school quite a few years AFTER Fortran had been invented.

Needless to say, such I-N convention was just a convenience for implicit variables.

At the top of many old Fortran programs, there is an implicit statement at the top when they declare which initial variables are going to be used for what types of variables...I-N for integers, C for complex, everything else for reals or something like that.

By the way, nobody has explicitly mentioned it, what I learned in Fortran is that the reason why the set of letters from I to N had been chosen to represent integers is because such (inclusive) I-N range can be represented just so using the first two letters of the word INteger itself.
 
  • #5
anorlunda said:
Long ago I learned Programming in FORTRAN. I got used to the convention that names starting with I,J,K,L,M,N were INTEGER while all other letters were REAL. I thought it was a convention of FORTRAN only. Since then, I came to realize that the same convention is widely used in science and math independent of computer programming. But I do not recall ever being explicitly taught any such convention.

My question: what is the origin of this convention?

I'm posting it here under math as a guess as to the right forum.

P.s Wikipedia mentions this convention under "naming conventions (programming)", but it does not mention the origin.

Today, the convention is to give variables meaningful names. The only exception to the rule is with indexes in loops.

For example...
Code:
area = height * width;

instead of

Code:
a = h * w;
 
  • #7
Sure, but it does not say anything about the I-N convention, which is what the OP was wondering about.
 
  • #8
I think the convention started with FORTRAN. Coming from a pure math background, I vaguely remember having a hard time with that convention at first. Before that, i and j meant the imaginary part of complex numbers to me. The m and n were more commonly used for integers. n was a natural number.
 
  • #9
... convention of using i through n for integers ...
FactChecker said:
I think the convention started with FORTRAN.
It predates Fortran. For example, summation or products series often use i, j, k for the iterating values and n (plus m and sometimes l) for the limiting values. i, j, k, ... are also used as an index / suffix when using a generic naming convention for terms in a polynomial, matrix, set, ... .
 
Last edited:

Related to [Fortran] Naming conventions for integers

What is the purpose of naming conventions for integers in Fortran?

The purpose of naming conventions for integers in Fortran is to provide a standardized way of naming variables, constants, and other elements in a program. This helps to improve code readability and organization, making it easier for other programmers to understand and modify the code.

What are the basic rules for naming integers in Fortran?

The basic rules for naming integers in Fortran include using only letters, numbers, and underscores, starting with a letter, and avoiding reserved words. The name should also not exceed 31 characters and should be meaningful and descriptive.

Do I have to follow the naming conventions for integers in Fortran?

No, following the naming conventions for integers in Fortran is not mandatory. However, it is highly recommended as it can improve the readability and maintainability of your code.

What are some common naming conventions for integers in Fortran?

Some common naming conventions for integers in Fortran include using lowercase letters for variable names, uppercase letters for constants, and mixed case for functions and subroutines. Additionally, using meaningful prefixes such as "i" for integers and "n" for natural numbers can also improve code organization.

Are there any resources available for learning more about naming conventions for integers in Fortran?

Yes, there are many resources available online for learning more about naming conventions for integers in Fortran. Some good starting points include the Fortran language reference manual and various programming forums and communities where experienced Fortran programmers can offer advice and tips.

Similar threads

  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
9
Views
3K
  • Programming and Computer Science
Replies
12
Views
3K
  • Programming and Computer Science
Replies
9
Views
11K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
24
Views
15K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Programming and Computer Science
Replies
25
Views
10K
Back
Top