Is there still a difference between a library and an API?

后端 未结 8 1658
清歌不尽
清歌不尽 2021-01-29 20:07

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

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-29 20:29

    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".

提交回复
热议问题