Difference between a module, library and a framework
Asked Answered
H

13

96

In popular programming speak, what is the difference between these terms and what are the overlaps?

Any related terms I'm missing out?

Hearthstone answered 4/11, 2010 at 18:32 Comment(4)
possible duplicate of Framework vs. Toolkit vs. LibraryZingg
duplicate of #13157877Mcmullan
@gavenkoa: Please check the date for question. That question is duplicate of this one.Brice
This isn't an answerable question. Those terms get used for lots of different things.Synovitis
S
146

All three of those provide functionality.

However, there are important differences.

A library is just a collection of related functionality. Nothing more, but also nothing less. The defining characteristic of a library is that you are in control, you call the library.

The defining characteristic of a framework is Inversion of Control. The framework calls you, not the other way round. (This is known as the Hollywood Principle: "Don't call us, we'll call you.") The framework is in control. The flow of control and the flow of data is managed by the framework.

You can think of it this way: in both cases, you have an application, and this application has holes in it, where code has been left out, and these holes need to be filled in. The difference between a library and a framework is

  • who writes the application,
  • what are the holes and
  • who fills in the holes.

With a library, you write the application, and you leave out the boring details, which gets filled in by a library.

With a framework, the framework writer writes the application, and leaves out the interesting details, which you fill in.

This can be a little confusing at times, because the framework itself might also contain boring details, that the framework author filled in with libraries, the parts that you write might contain boring details, that you fill in with libraries, and the framework might provide a set of bundled libraries that either work well with the framework or that are often needed in conjunction with the framework. For example, you might use an XML generator library when writing a web application using a web framework, and that XML library might have been provided by the framework or even be an integral part of it.

That doesn't mean, however, that there is no distinction between a library and a framework. The distinction is very clear: Inversion of Control is what it's all about.

The defining characteristic of a module is information hiding. A module has an interface, which explicitly, but abstractly specifies both the functionality it provides as well as the functionality it depends on. (Often called the exported and imported functionality.) This interface has an implementation (or multiple implementations, actually), which, from the user of a module are a black box.

Also, a library is a collection of related functionality, whereas a module only provides a single piece of functionality. Which means that, if you have a system with both modules and libraries, a library will typically contain multiple modules. For example, you might have a collections library which contains a List module, a Set module and a Map module.

While you can certainly write modules without a module system, ideally you want your modules to be separately compilable (for languages and execution environments where that notion even makes sense), separately deployable, and you want module composition to be safe (i.e. composing modules should either work or trigger an error before runtime, but never lead to an runtime error or unexpected behavior). For this, you need a module system, like Racket's units, Standard ML's modules and functors or Newspeak's top-level classes.

So, let's recap:

  • library: collection of related functionality
  • framework: Inversion of Control
  • module: abstract interface with explicit exports and imports, implementation and interface are separate, there may be multiple implementations and the implementation is hidden
Sweyn answered 4/11, 2010 at 20:53 Comment(6)
@gavenkoa: "Inversion of Control is a common phenomenon that you come across when extending frameworks. Indeed it's often seen as a defining characteristic of a framework." (Martin Fowler). "Frameworks contain key distinguishing features that separate them from normal libraries: inversion of control - In a framework, unlike in libraries or normal user applications, the overall program's flow of control is not dictated by the caller, but by the framework." (Wikipedia). If I had more than 30 seconds, I could probably find more sources.Chinchy
@JörgWMittag It usually based on IoC in case of wide spread Java/C# world. But in system without OOP (like DejaGnu testing famework, which help you with downloading your code to hundreds of system boards) IoC might not possible. I think about framework as system which behave as non-regular helpful library which force you follow it conventions.Mcmullan
@Mcmullan IoC is not limited to OOP; I can't fully understand your last comment (maybe because I don't know DejaGnu)Sloe
I know this is very old, but I fail to grasp how your explanation of a framework covers all frameworks. I can compile a piece of code as a library, or as a framework. Is it just a coding standard then? Does the intention of it determine the difference, instead of the file extension? Are there any differences in the machine code within a library compared to a framework?Velites
@Jörg W Mittag, can explain all this in time domain, ie.compile and run time contexts, on each?Lackaday
Yet another framework definition doesn't interest me; it's proven far too open ended a concept. But what I still don't understand however is why bother with modules when libraries can easily do everything they can, including partitioning information. In the java case, are there useful barriers present in modules that don't exist in mere jar files? Do modules somehow prevent cross-linking from one jar to another depending upon order on the command line?Crimson
C
49

You can see a module, a library and a framework this way:

  • module = your fingers
  • library = your hands
  • framework = your body

Your fingers / Module:
You can move them, touch things, you have 5 in a hand so you can use them to hold things in an easier way, those are not the biggest parts of the body but are one of the most useful parts, without them you couldnt hack!... modules are part of a program, you can use them, expand code to other files (not a large file with a lot of code in it), they make the reading easier.

Your hands / Library:
Hands are a set of 5 fingers each one, you can hold things, move things, interact with them, etc... libraries are part of a program too! and they can be seen like a set of modules, you can use them to interact with other programs or make relevant things with your program.

Your body / Framework:
Your body is a complete system, you can do with your body whatever you want (even fly, just walk into a plane and there you go, a plane is another system), you are unique... a framework is your body, a complete system, it doesnt work for itself (you need to code herpderp) but you can make a complete program with some hacking runs...

just my interpretation... if im wrong please fix ME.

Combes answered 4/11, 2010 at 19:29 Comment(0)
S
15

My ASCII art interpretation of what I understood from other answers:

+-----------------------------------------------+
|  ...........................  ..............  |
|  : f1() f2()  :  f3()      :  : f4() f5()  :  |
|  :            :            :  :            :  |
|  : l1_module1 : l1_module2 :  : l2_module3 :  |
|  :            :            :  :            :  |
|  --library1-----------------  --library2----  |
|                                               |
|   application.c                               |
|                                               |
|       #include l1_module2                     |
|       #include l2_module3                     |
|                                               |
|       int main() {                            |
|           # case 'reload'                     |
|           f5();                               |
|           # case 'start'                      |
|           f1();                               |
|           # case 'stop'                       |
|           f4();                               |
|       }                                       |
|                                               |
+-----------------------------------------------+

.................................................
: FRAMEWORK_X                                   :
:                                               :
:     application start                         :
:     ...                                       :
:     application reload                        :
:     application stop                          :
:     ...                                       :
:...............................................:

What happens:

  1. Developer installs library1 and library2 so that they can use functions provided inside modules of these.

  2. They then include l1_module1 and l2_module3. (They do not need l1_module2 for now).

  3. Now they can use the functionality of f1, f2, f4 and f5, So they write their application.

  4. Now, since they want to use the application inside some FRAMEWORK_X, they must implement the interface that this framework needs: so that the framework can call the application.

Some notes:

  • In practice, there is always some framework. For example, the OS is framework for your application (which is why you define main())! Or you could say that the bootloader is framework for your OS and the BIOS is framework for your bootloader etc.
Sloe answered 5/5, 2015 at 22:58 Comment(3)
Yeah, and your BIOS also has a framework: hardware, which also has a framework: the power network, which also has a framework: the power industry, which also has a framework: the Earth, which also has a framework: the space... and I'll just stop right here before going into religious matters.Sloe
What did you use to crate the ASCII ?Uitlander
@KorayTugay What do you mean? I don't cheat on ASCII art... Just Vim!Sloe
L
11

Package vs Module vs Library vs Framework:

  1. Package - Collection of classes/files of similar functionality.

  2. Module -It is the smallest piece of software. It is set of methods/functions ready to be used somewhere else.

  3. Library - It is a collections of packages. It offer a set of functionalities ready to use without worrying about the how it has been written. All we bother about is input/output.

  4. Framework - It's a set of libraries. along with functionalities, it also provides an architecture design or wire frame. It offers well designed patterns to your project. we don't include a framework. we integrate our code into it.

Liber answered 2/1, 2021 at 14:2 Comment(0)
J
2

Roughly, I'd consider it this way: a module is an importable "atom" of functionality; it defines the smallest subset of grouped functionality that can be used (note that it's not the smallest unit of functionality; that would be a class (or function, depending)). A library would be, in this approach, a set of modules; you can use a library without using all of the modules that are part of that library. A framework is the environment upon which the library (likely) depends; it makes up the baseline environment within which all of the above work.

Note that these terms are somewhat fungible, and these definitions will not always be solid in every situation; this is just my interpretation of some of the common usages I've come across.

Juncaceous answered 4/11, 2010 at 18:42 Comment(0)
S
2

From my point of view a framework contains libraries and both are modules.

E.g. In Swift a module is a single unit of code distribution — a framework or application that is built and shipped as a single unit.

Stahl answered 1/1, 2017 at 22:7 Comment(0)
P
1

In my opinion a module could be a subset of a library, which in turn could be a subset of a framework. But I'm sure there are exceptions to this and various interpretations based on the context -- especially for the term module.

Portingale answered 4/11, 2010 at 18:34 Comment(0)
R
1

I believe frameworks and libraries are modules. Since modules are codes imported or exported from your code. As they say, Frameworks calls your code, your code calls libraries. Either way, a module is involved

Ridings answered 10/4, 2014 at 14:3 Comment(0)
P
1

Module

A module is the output of modular design, a component with various granularity.

In context of modular programming, a module is an entity expressible by the coding language introducing the programmability (typically, a programming language or a hardware description language) to the solution.

Some languages explicitly support the concept of module and provide it as a language feature. A notable early instance is Modular-2. Despite the feature, users can still specify other kinds of modules by conventions with different granularity in software design and project management, like a source file and a directory of source files. The built-in language feature does not eliminate the need of modules of different granularity, but people may use different terminology to avoid possible ambiguity with the language feature.

Some other languages do not provide specific feature named module, but users can make choices to specify parts of program as modules. For example, the C language does not have modules, but users can specify a function, a source file, a translation unit (a source file with the headers it includes) or even bunch of files as a module on demand. A module in such case can be with different forms of code: source, binary code from source or provided elsewhere with linkage compatibility guarantees, or even mixed.

The only real restriction of "module", if any, is that it should reflect to the result of some modular design, so components in a module should share some similarities to make the boundary clear. A module should usually provide some kinds of exported interface to users; it may optionally import dependencies from external program components. Some of modules can be a submodule of others.

Code management tools may utilizes the concepts related to module. For example, Git has the concept of submodule, which is essentially a versioned subdirectory of code in the repository.

Library

A library is a specialized kind of program module containing (more specifically, owning) a collection of (sub)modules to be used in some encapsulated (that is, not allowed being modified directly in later use) manner. Usually a library is designed to be reused and deployed within non-volatile storage. Typically, a library is provided as one or several on-disk files in some steady persistent formats. Such libraries are called archives, dynamic objects, packages, etc. With support of external program databases, libraries can also be identified by means other than filenames or other file-based properties. For example, CLI provides library assemblies with aid of GAC.

Framework

A framework is another specialized kind of program module which contains various pre-desinged functionality of code. A framework can be deployed in a form of one or several libraries. The difference between a framework and other kinds of modules in a program is that the former emphasizes a mostly complete, freezed but adaptive and extensible solution of some common work, so the user of the framework can focus on the domain-specific and project-specific problems instead of writing glue code to put different libraries together and to make them work fluently. However, this has a cost of design complexity throughout the whole project. Notably, many (but not all) frameworks would enforce users' code following an IoC style. As a result, it is almost impossible to put same kind but different frameworks together smoothly in an idiomatic and natural way. Using language with first-class control effects, IoC is not explicitly required in a framework. However this implies that combination of normal libraries to having functionality of a framework is easier to achieve, so there is less need to organize program modules like traditional frameworks which often undermine flexibility easily.

Pediform answered 12/8, 2018 at 11:4 Comment(0)
D
1

Library: A collection of namespaced/modularized code.

Framework: A framework is some piece of code (wheter it’s a compiler, a design pattern or something else) that is reusable and thereby makes life easier for developers so that they do not have to reinvent the wheel.

Module: In JavaScript for example a module is just an object with public properties. I'm not sure, but I think there is no generic answer for the term Module.

Dmso answered 14/9, 2018 at 16:16 Comment(0)
M
0

HERE IS A SHORT DESCRIPTION

What is a Module?

This could be different based on context, but I believe a module is generally just a part of a library, as it contains many tools that are equally useful for the developer (see library explanation below).

What is a Library?

A library is a collection of code blocks (could be in the form of variables, functions, classes, interfaces etc.) that are built by developers to ease the process of software development for other developers that find its relevance.

What is a Framework?

With reference to the definition of a library, we could define a framework as a tool that helps a developer solve a large range of domain-specific problems by providing the developer with necessary libraries in a controlled development environment.

Murielmurielle answered 28/12, 2021 at 17:57 Comment(0)
G
0

A library is a bunch of text files containing code, that you can download to include in your own project.

A framework is a type of library. They are libraries that implement Inversion of control, which other answers have explained very well.

Note that this is a spectrum, libraries can be more or less "frameworky", without a precise boundary.

Sometimes, when people say "library" they are actually meaning to say "non-frameworky library", but I think that is poor terminology that shouldn't be used.

A module is a separate concept. It is in reference to modular programming, where one tries to break down one's code into well separated, callable sections, each having a precise functionally, called "modules".

A function or a class could be a module. But in general, people call modules to a group of code elements with strongly related functionally, all contained in an individual text file. In this sense, a module is synonym with "text file containing code".


Note that there's another definition of framework, one that is super vague and simply means "a set of rules to guide your developing". This can refer to anything, a language, a combo of language+libraries+compiler, a workstyle like Agile, etc.

Gormandize answered 6/1 at 19:30 Comment(0)
R
0

module is collection of functions,

package is collection of modules,

library is collection of packages,

framework is collection of library

Requiem answered 9/2 at 13:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.