πŸ’» Programming

Library

Library

A collection of reusable code. Unlike a framework, it does not dictate the control flow.

πŸ“– Detailed Explanation

A library is a collection of reusable code that performs a specific function. It is a collection of code in which functions developers frequently use are implemented in advance, and which can be called and used when needed. Using a library allows you to reuse verified code without implementing complex functionality yourself, which can greatly shorten development time and improve code quality.

The history of libraries begins in the early days of programming. The mathematical function libraries of FORTRAN in the 1950s were an early form, and the concept of code reuse was established with the emergence of the C standard library (libc). Class libraries appeared along with the development of object-oriented programming in the 1990s, and since the 2000s the library ecosystem has grown explosively with the open-source movement and the development of package managers.

The key difference between a library and a framework is Inversion of Control (IoC). A library is a tool that the developer calls when needed, whereas a framework controls the flow of the entire application and calls the developer's code. For example, React is a library for building UI components, while Next.js and Angular are frameworks that define the structure and flow of an application. The Hollywood principle, "Don't call us, we'll call you," explains this difference well.

In modern development, libraries are managed through a package manager. npm (Node Package Manager) in the JavaScript ecosystem provides more than 1 million packages, and Python's pip and PyPI, as well as Java's Maven Central, also host hundreds of thousands of libraries. These tools automate dependency resolution, version management, and security vulnerability scanning, helping developers use libraries efficiently.

πŸ’» Code Example

Python - requests library
# pip install requests 둜 μ„€μΉ˜
import requests

# GET μš”μ²­ - APIμ—μ„œ 데이터 κ°€μ Έμ˜€κΈ°
response = requests.get('https://api.github.com/users/octocat')

# 응닡 μƒνƒœ 확인
if response.status_code == 200:
    data = response.json()
    print(f"μ‚¬μš©μž: {data['login']}")
    print(f"νŒ”λ‘œμ›Œ: {data['followers']}")

# POST μš”μ²­ - 데이터 μ „μ†‘ν•˜κΈ°
payload = {'title': 'μƒˆ κΈ€', 'body': 'λ‚΄μš©μž…λ‹ˆλ‹€'}
response = requests.post(
    'https://jsonplaceholder.typicode.com/posts',
    json=payload,
    headers={'Content-Type': 'application/json'}
)
JavaScript - lodash library
// npm install lodash 둜 μ„€μΉ˜
import _ from 'lodash';

// λ°°μ—΄ μž‘μ—… μœ ν‹Έλ¦¬ν‹°
const users = [
  { 'name': 'κΉ€μ² μˆ˜', 'age': 30, 'active': true },
  { 'name': '이영희', 'age': 25, 'active': false },
  { 'name': 'λ°•λ―Όμˆ˜', 'age': 35, 'active': true }
];

// 쑰건에 λ§žλŠ” μš”μ†Œ μ°ΎκΈ°
const activeUsers = _.filter(users, { 'active': true });
// κ²°κ³Ό: [{ name: 'κΉ€μ² μˆ˜', ... }, { name: 'λ°•λ―Όμˆ˜', ... }]

// λ°°μ—΄ κ·Έλ£Ήν™”
const grouped = _.groupBy(users, 'active');

// κΉŠμ€ 볡사 (Deep Clone)
const clonedUsers = _.cloneDeep(users);

// λ””λ°”μš΄μŠ€ - 연속 호좜 λ°©μ§€
const debouncedSearch = _.debounce((query) => {
  console.log(`검색: ${query}`);
}, 300);

πŸ—£οΈ Example Conversations in Practice

πŸ’Ό Technical Meeting - Criteria for Choosing a Library
PM: We need an HTTP client library for this project. Which one should we use?
Senior: I recommend axios. It has over 20 million weekly downloads, and interceptors and timeout settings are convenient. There's also the fetch API, but its error handling is a bit inconvenient.
Junior: What's the most important criterion when choosing a library?
Senior: First is maintenance status. Check when the last update was and whether issues are handled well. Second is the size of the community, and third is bundle size. For the frontend, whether it supports tree-shaking is also important.
🎯 Technical Interview - Library vs. Framework
Interviewer: Could you explain the difference between a library and a framework?
Candidate: The key difference is Inversion of Control (IoC). A library is a tool that I call when I need it, but a framework controls the flow of the entire application and calls my code.
Interviewer: Could you give a specific example?
Candidate: lodash is a library where I call _.filter(). On the other hand, with Express.js, when I register a route handler, the framework calls my handler when a request comes in. That's the "Don't call us, we'll call you" principle.
πŸ” Code Review - Dependency Management
Reviewer: You've newly added moment.js. Its bundle size is about 300KB, so if you only need date formatting, wouldn't date-fns or dayjs be better?
Developer: Oh, dayjs is only 2KB! And its API is similar to moment's. I'll make the change.
Reviewer: Also, please commit package-lock.json too, so that team members can use the same versions of dependencies. It would also be good to run npm audit once.

Take a mock interview on this topic β†’ WIA SOOM AI Interview Β· Start for free

⚠️ Cautions

πŸ“œ

License Check Required

Each license, such as MIT, Apache 2.0, and GPL, has different terms of use. Using a GPL library in a commercial project may create an obligation to disclose the source code, so be sure to check the license before adopting it in your project.

πŸ›‘οΈ

Monitoring Security Vulnerabilities

External libraries are a major pathway for security vulnerabilities. Use npm audit, pip-audit, Dependabot, Snyk, and similar tools to check for vulnerabilities regularly, and update promptly when security patches are released.

πŸ”„

Managing Version Compatibility

Major version upgrades may include breaking changes. Pin versions with package-lock.json, requirements.txt, and similar files, and update safely by understanding Semantic Versioning (SemVer).

πŸ”— Related Terms

πŸ“š Learn More