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?
An import statement tells the compiler the path of a class or the entire package.
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.
It's called a Declaration.
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.
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:
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
.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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With