库和 API 之间还有区别吗?

发布于 2024-09-18 07:10:03 字数 454 浏览 8 评论 0原文

每当我询问人们 API 和库之间的区别时,我都会得到不同的意见。有些人给出了这种的定义,说API是一个规范和库是一种实现...

有些人会告诉您这种类型的定义, API 是一堆映射出来的函数,而库只是编译形式的分发。

所有这些让我想知道,在网络代码、框架和开源的世界中​​,真的还有实际的区别吗?像 jQuery 或 cURL 这样的库可以交叉到 API 的定义中吗?

另外,框架是否会跨入这一类别? Rails 或 Zend 是否有部分可以更像“API 式”或“库式”?

真的很期待一些有启发性的想法:)

Whenever I ask people about the difference between an API and a library, I get different opinions. Some give this kind of definition, saying that an API is a spec and a library is an implementation...

Some will tell you this type of definition, that an API is a bunch of mapped out functions, and a Library is just the distribution in compiled form.

All this makes me wonder, in a world of web code, frameworks and open-source, is there really a practical difference anymore? Could a library like jQuery or cURL crossover into the definition of an API?

Also, do frameworks cross over into this category at all? Is there part of Rails or Zend that could be more "API-like," or "libraryesque"?

Really looking forward to some enlightening thoughts :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

风流物 2024-09-25 07:10:03

我的观点是,当我谈到 API 时,它仅指暴露给程序员的部分。如果我说“图书馆”,那么我也指的是“在幕后”工作的一切,尽管它们仍然是图书馆的一部分。

My view is that when I speak of an API, it means only the parts that are exposed to the programmer. If I speak of a 'library' then I also mean everything that is working "under the hood", though part of the library nevertheless.

独自←快乐 2024-09-25 07:10:03

包含可重用的代码块(软件程序)。

这些可重用的库代码通过API链接到您的程序
(应用程序编程接口)。也就是说,此 API 是一个库接口,通过它可将可重用代码链接到您的应用程序。
简单来说,API 是一种促进两个软件程序之间交互的软件接口。

在此处输入图像描述

例如,在 C 等过程语言中,库 math.c 包含数学函数的实现,如sqrtexplog等。它包含所有这些函数的定义。

这些函数可以通过使用 API math.h 来引用,其中 描述并规定预期行为

话虽这么说,API 是一种规范math.h 解释了它提供的所有函数、它们的参数和它们返回的数据等)和一个库是一个实现(math.c 包含这些函数的所有定义)。

A library contains re-usable chunks of code (a software program).

These re-usable codes of library is linked to your program through APIs
(Application Programming Interfaces). That is, this API is an interface to library through which re-usable codes are linked to your application program.
In simple term it can be said that An API is a software interface that facilitates the interaction between two software programs..

enter image description here

For example, in procedural languages like C, the library math.c contains the implementations of mathematical function, such as sqrt, exp, log etc. It contains the definition of all these functions.

These function can be referenced by using the API math.h which describes and prescribes the expected behavior.

That being said, an API is a specification (math.h explains about all the functions it provides, their arguments and data they return etc.) and a library is an implementation (math.c contains all the definitions of these functions).

甚是思念 2024-09-25 07:10:03

API 是库的一部分,定义了它如何与外部代码交互。每个库都有 API,API 是所有公共/导出内容的总和。如今API的含义已经扩大。我们也可以将网站/服务与代码交互的方式称为 API。您还可以知道某些设备具有 API - 您可以调用的命令集。

有时这些术语可以混合在一起。例如,您有一些服务器应用程序(例如 TFS)。它带有 API,并且该 API 是作为库实现的。但这个库只是你和执行你的调用的人之间的中间层。但如果库本身包含所有操作代码,那么我们就不能说这个库 API。

API is part of library that defines how it will interact with external code. Every library has API, API is sum of all public/exported stuff. Nowadays meaning of API is widened. we might call the way web site/service interact with code as API also. You can also tell that some device has API - the set of commands you can call.

Sometimes this terms can be mixed together. For example you have some server app (like TFS for example). It has API with it, and this API is implemented as a library. But this library is just a middle layer between you and not the one who executes your calls. But if library itself contains all action code then we can't say that this library is API.

静若繁花 2024-09-25 07:10:03

我认为 Library 是一组所有类和函数,可以从我们的代码中使用它们来轻松完成我们的任务。但是该库可以包含一些它不想公开的私有函数供其使用。

API 是向用户公开的库的一部分。因此,无论我们有关于库的任何文档,我们都将其称为 API 文档,因为它只包含我们有权访问的那些类和函数。

I think that Library is a set of all classes and functions that can be used from our code to do our task easily. But the library can contain some of its private functions for its usage which it does not want to expose.

API is a part of library which is exposed to the user. So whatever documentation we have regarding a library, we call it an API Documentation because it contains only those classes and functions to which we have access.

抚笙 2024-09-25 07:10:03

我们首先要定义一个接口...

接口:是两个“事物”相互交谈并交换信息的方式。 “事物”可以是 (1) 人类或 (2) 任何类型的运行代码(例如库、桌面应用程序、操作系统、Web 服务...等)。

如果人类想要与程序对话,他需要图形用户界面(GUI)或命令行界面(CLI)。两者都是人类(但不是程序)想要使用的界面类型。

然而,如果一个正在运行的代码(任何类型)想要与另一个正在运行的代码(任何类型)对话,它不需要或不需要 GUI 或 CLI,而是需要一个应用程序编程接口(API )。

所以回答最初的发帖者问题:库是一种运行代码,API 是该运行代码与其他运行代码对话的方式。

we have first to define an interface ...

Interface :is the means by which 2 "things" talk to each other and exchange information. "things" could be a (1) human or (2) a running code of any sort (e.g. library ,desktop application , OS , web service ... etc).

if a human want to talks to a program he need Graphical user interface (GUI) or command line interface (CLI). both are types of interfaces that humans (but not programs) would like to use.

if however a running code (of any sort) want to talk to another running code (of any sort) it doesn't need or want a GUI or CLI ,it rather need an Application Programming Interface (API).

so to answer the original poster question : library is a type of running code and the API is the means by which this running code talk to other running codes.

错々过的事 2024-09-25 07:10:03

清晰简洁的语言

库:为可重用性而存储的所有类和方法的集合

API:用户可以在他/她的代码中使用的类和方法的一部分。

In Clear and concise language

Library: Collection of all classes and methods stored for re-usability

API: Part of library classes and methods which can be used by a user in his/her code.

—━☆沉默づ 2024-09-25 07:10:03

根据我的观点,无论调用者可以访问什么函数,我们都可以在库文件中调用 api,库文件具有一些私有函数,我们无法访问它们。

According to my perspective, whatever the functions are accessible to invoker , we can called as api in library file, library file having some of the functions which is private , we cannot access them ..

故人爱我别走 2024-09-25 07:10:03

时,有两种情况,

  1. 的 API计算机程序
  2. 当我们谈论或想到使用库其他(更广泛的含义)

我认为,在第一种情况下,从 API 角度思考是令人困惑的。这是因为我们总是使用图书馆。只有图书馆。没有库的 API 是不存在的,但人们倾向于这样思考。

C++ 中的标准模板库 (STL) 怎么样?这是一个软件库。

您可以拥有不同的库相同的 API,这意味着一组可用的类、对象、方法、函数、过程或您在某种编程语言中喜欢的任何术语。但可以说,我们对一些“标准”库有不同的实现。

可以打个比方:SQL 是一个标准,但可以有不同的实现。你使用的总是一些实现 SQL 的 SQL 引擎。您可以仅遵循标准功能集,也可以使用一些特定于该实现的扩展功能。

除了此类库的不同实现的效率差异之外,库中的“幕后”内容不是您所关心的。

当然我知道,这种思维方式并不是什么“普遍约束力的标准”。只是创建了很多新术语,这些术语并不总是清晰、精确、直观,这带来了一些混乱。当 Oracle 谈论集合时。它不是库,也不是 API,它是一个“集合框架”。

There are two cases when we speak or think of API

  1. Computer program using library
  2. Everything else (wider meaning)

I think, that in the first case, thinking in terms of API is confusing. It's because we always use a library. There are only libraries. API without library doesn't exist, while there's a tendency to think in such terms.

How about The Standard Template Library (STL) in C++? It's a software library.

You can have different libraries with the same API, meaning set of available classes, objects, methods, functions, procedures or whatever terms you like in some programming language. But it can be said, that we have different implementation of some "standard" library.

Some analogy may be that: SQL is a standard but can have different implementations. What you use is always some SQL engine which implements SQL. You may follow only standard set of features or use some extended, specific to that implementation.

And what "under the hood" in library is not your concern, except in terms of differences in efficiency by different implementations of such library.

Of course I'm aware, that this way of thinking is not what is a "generally binding standard". Just a lot of new terms have been created, that are not always clear, precise, intuitive, that brings some confusion. When Oracle speaks about Collections. It's not library, it's not API, it's a "Collections Framework".

帝王念 2024-09-25 07:10:03
  • :将其视为一个工具箱。它具有所有这些预先编写的代码(例如函数、方法、类等等),您可以在自己的代码中使用它们。您可以在需要时调用这些函数。库安装在您的系统上,您可以在自己的代码中使用它的函数、类、接口(如 Set、List 等)。这些构成了库的 API。
  • API(应用程序编程接口):这就像软件组件如何交互的规则手册。它规定了如何使用服务的法律,无论该服务是由图书馆、服务器还是其他组件提供的。该服务的具体细节通常对用户隐藏。虽然库的 API 允许您在自己的程序中使用库的代码,但其他类型的 API 允许您的程序与其他地方运行的代码进行交互。例如,Web API 允许您的程序通过互联网与服务交互。 API 定义了您的程序可以发送哪些请求以及可以接收哪些响应。但实现此功能的实际代码不是程序的一部分 - 它运行在其他地方的服务器上。
  • Library: Think of it as a toolbox. It’s got all these pre-written codes (like functions, methods, classes, and whatnot) that you can use in your own code. You call these functions whenever you need 'em. Libraries are installed on your system, and you can use its functions, classes, interfaces (like Set, List, etc.) in your own code. These form the library’s API.
  • API (Application Programming Interface): This is like the rulebook for how software components should interact. It lays down the law on how to use a service, whether that service is provided by a library, a server, or some other component. The nitty-gritty details of that service are usually hidden from the user. While a library’s API lets you use the library’s code in your own program, other types of APIs let your program interact with code running elsewhere. For example, a web API lets your program interact with a service over the internet. The API defines what requests your program can send and what responses it can expect to receive. But the actual code that implements this functionality isn’t part of your program - it’s running on a server somewhere else.
没有伤那来痛 2024-09-25 07:10:03

在不使用技术术语的情况下,我想分享我对 API 和库的理解。

我区分“图书馆”和“API”的方式是想象我去图书馆的情况。当我去那里时,我向“图书馆员”索取一本我需要的书,而不知道整个图书馆是如何管理的。

我像这样在他们之间建立了一个简单的关系。

  • 图书馆=一个图书图书馆,有完整的系统和人员来管理图书。
  • API = 图书管理员,为我提供对我需要的书籍的简单访问。

Without using technical terms I would like to share my understanding regarding API and library.

The way I distinguish 'library' and 'API' is imagining a situation where I go to a book library. When I go there, I request a book which I need to a 'librarian' without knowing how a entire library is managed.

I make a simple relation between them like this.

  • Library = A book library which has a whole system and staffs to manage books.
  • API = A librarian who provides me a simple access to a book which I need.
随风而去 2024-09-25 07:10:03

它们是完全不相关的概念。

库是一组可重用的代码。

API 是程序或库的一部分,允许外部代理与其交互。

They are completely unrelated concepts.

A library is a set of resuable code.

An API is the part of a program or library that lets external agents interact with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文