Comparison of Programming Languages (syntax) - Libraries

Libraries

To import a library is a way to read external, possibly compiled, routines, programs or packages. Imports can be classified by level (module, package, class, procedure,...) and by syntax (directive name, attributes,...)

File import

  • ASP: #include file="filename"
  • AutoIt, C, C++: #include "filename", #include <filename>
  • Falcon: load "filename"
  • Fortran: include 'filename'
  • Lua: require("filename")
  • MATLAB: addpath(directory)
  • Perl: require "filename";
  • PHP: include "filename";, require "filename";

Package import

  • Ada: with package
  • C, C++: #include filename
  • Cobra: use Package.Name
  • D: import package.module;, import altname = package.module;
  • Falcon: load module, load module.submodule
  • Fortran 90+: use module, use module, only : identifier
  • Go: import altname "package/name"
  • Haskell: import Module, import qualified Module as M
  • Java, MATLAB: import package.*
  • Lua: require("modname")
  • Mathematica: <<name
  • Oberon: IMPORT module
  • Pascal: uses unit
  • Perl: use Module;
  • Python: import module, from module import *
  • Scala: import package._, import package

Class import

  • Falcon: import class
  • Java, MATLAB: import package.class
  • Python: from module import class
  • Scala: import package.class, import package.{ class1 => alternativeName, 'class2 }, import package._

Procedure/function import

  • D: import package.module : symbol;, import package.module : altsymbolname = symbol;
  • Haskell: import Module (function)
  • MATLAB: import package.function
  • Perl: use Module ('symbol');
  • Python: from module import function
  • Scala: import package.class.function, import package.class.{ function => alternativeName, otherFunction }

The above statements can also be classified by whether they are a syntactic convenience (allowing things to be referred to by a shorter name, but they can still be referred to by some fully qualified name without import), or whether they are actually required to access the code (without which it is impossible to access the code, even with fully qualified names).

Syntactic convenience

  • Java: import package.*, import package.class
  • OCaml: open module

Required to access code

  • Go: import altname "package/name"
  • Python: import module

Read more about this topic:  Comparison Of Programming Languages (syntax)

Famous quotes containing the word libraries:

    To me, nothing can be more important than giving children books, It’s better to be giving books to children than drug treatment to them when they’re 15 years old. Did it ever occur to anyone that if you put nice libraries in public schools you wouldn’t have to put them in prisons?
    Fran Lebowitz (20th century)

    riding flatcars to Fresno,
    Across the whole country
    Steep towns, flat towns, even New York,
    And oceans and Europe & libraries & galleries
    And the factories they make rubbers in
    Gary Snyder (b. 1930)