Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the history of the import statement?

I know of two languages that use import statement: Java and Python. And we all know the import antigravity joke.

Which language really introduced this statement? Was it one of the two, or another one altogether? When?

like image 225
Maciej Ziarko Avatar asked Feb 18 '11 10:02

Maciej Ziarko


People also ask

What is an import statement?

An import statement tells the compiler the path of a class or the entire package.

What is the function of the import statement?

The import statement combines two operations; it searches for the named module, then it binds the results of that search to a name in the local scope. The search operation of the import statement is defined as a call to the __import__() function, with the appropriate arguments.

What are import statements called?

It's called a Declaration.

What is import and from import statement?

The import statement allows you to import all the functions from a module into your code. Often, though, you'll only want to import a few functions, or just one. If this is the case, you can use the from statement. This lets you import only the exact functions you are going to be using in your code.


2 Answers

import is just one way to specify dependency on some other class/module. Some way of specifying that has been present in many, many languages.

In fact import in Java and import in Python do two entirely different things:

  • In Java import only provides the ability to refer to a type (or field/method, if using import static) by its short name instead of its fully qualified name. No "module loading" of any kind happens based on an import.
  • In Python import actually loads a module and optionally provides a short name for some (or all) of its members.

Other keywords that do somewhat similar things are include in C and use in Perl. Many, many languages have some kind of way to specify this kind of dependency, but the technical details vary a lot.

One language with an IMPORT statement that predates both Java and Python is Modula-2 (1978) and its successor Modula-3.

like image 80
Joachim Sauer Avatar answered Sep 21 '22 13:09

Joachim Sauer


FWIW, in the 80ies you would first come across import statements in Extended Pascal and Ada in a somewhat different meaning than what is today's commonly accepted usage.

In ADA you would [pragma] import functions from other languages (typically C). This was similar to JNI in java or declaring a function living in a dll in VB6. The same concepts were also introduced in extended Pascal (the namespace import concept in Pascal and ADA was actually relying on a combination of the with and uses keyword).

like image 38
Alain Pannetier Avatar answered Sep 23 '22 13:09

Alain Pannetier