Why Effect? 왜 Effect인가?
Programming is challenging. When we build libraries and apps, we look to many tools to handle the complexity and make our day-to-day more manageable. Effect presents a new way of thinking about programming in TypeScript.
프로그래밍은 어렵습니다. 라이브러리와 앱을 만들 때, 복잡성을 다루고 일상 작업을 더 관리하기 쉽게 만들기 위해 다양한 도구를 찾게 됩니다. Effect는 TypeScript에서 프로그래밍에 대한 새로운 사고방식을 제시합니다.
Effect is an ecosystem of tools that help you build better applications and libraries. As a result, you will also learn more about the TypeScript language and how to use the type system to make your programs more reliable and easier to maintain.
Effect는 더 나은 애플리케이션과 라이브러리를 구축하는 데 도움을 주는 도구들의 생태계입니다. 그 결과, TypeScript 언어에 대해 더 많이 배우고 타입 시스템을 사용하여 프로그램을 더 신뢰할 수 있고 유지 관리하기 쉽게 만드는 방법도 익히게 됩니다.
In “typical” TypeScript, without Effect, we write code that assumes that a function is either successful or throws an exception. For example:
Effect가 없는 “일반적인” TypeScript에서는 함수가 성공하거나 예외를 던진다고 가정하는 코드를 작성합니다. 예를 들어:
const divide = (a: number, b: number): number => { if (b === 0) { throw new Error("Cannot divide by zero") } return a / b}
Based on the types, we have no idea that this function can throw an exception. We can only find out by reading the code. This may not seem like much of a problem when you only have one function in your codebase, but when you have hundreds or thousands, it really starts to add up. It’s easy to forget that a function can throw an exception, and it’s easy to forget to handle that exception.
타입만으로는 이 함수가 예외를 던질 수 있다는 사실을 알 수 없습니다. 코드를 읽어봐야만 알 수 있습니다. 코드베이스에 함수가 하나뿐일 때는 큰 문제가 아닐 수 있지만, 수백 또는 수천 개가 되면 문제가 커집니다. 함수가 예외를 던질 수 있다는 사실을 잊기 쉽고, 그 예외를 처리하는 것도 잊기 쉽습니다.
Often, we will do the “easiest” thing and just wrap the function in a try/catch
block. This is a good first step to prevent your program from crashing, but it doesn’t make it any easier to manage or understand our complex application/library. We can do better.
종종 우리는 “가장 쉬운” 방법으로 함수를 try/catch
블록으로 감싸는 일을 합니다. 이것은 프로그램이 충돌하는 것을 방지하는 좋은 첫걸음이지만, 복잡한 애플리케이션이나 라이브러리를 관리하거나 이해하기 쉽게 만들지는 못합니다. 우리는 더 나은 방법을 찾을 수 있습니다.
One of the most important tools we have in TypeScript is the compiler. It is the first line of defense against bugs, domain errors, and general complexity.
TypeScript에서 가장 중요한 도구 중 하나는 컴파일러입니다. 컴파일러는 버그, 도메인 오류, 그리고 전반적인 복잡성에 맞서는 첫 번째 방어선입니다.
While Effect is a vast ecosystem of many different tools, if it had to be reduced down to just one idea, it would be the following:
Effect는 다양한 도구들의 방대한 생태계이지만, 하나의 아이디어로 축약해야 한다면 다음과 같을 것입니다:
Effect’s major unique insight is that we can use the type system to track errors and context, not only success values as shown in the divide example above.
Effect의 주요 고유 통찰은 위의 나누기 예제에서 보인 것처럼 성공 값뿐만 아니라 오류와 컨텍스트를 추적하기 위해 타입 시스템을 사용할 수 있다는 점입니다.
Here’s the same divide function from above, but with the Effect pattern:
위와 동일한 나누기 함수이지만 Effect 패턴을 적용한 버전입니다:
import { Effect } from "effect"
const divide = ( a: number, b: number): Effect.Effect<number, Error, never> => b === 0 ? Effect.fail(new Error("Cannot divide by zero")) : Effect.succeed(a / b)
With this approach, the function no longer throws exceptions. Instead, errors are handled as values, which can be passed along like success values. The type signature also makes it clear:
이 접근법에서는 함수가 더 이상 예외를 던지지 않습니다. 대신 오류가 값으로 처리되어 성공 값처럼 전달될 수 있습니다. 타입 시그니처도 이를 명확히 보여줍니다:
- What success value the function returns (
number
).
함수가 반환하는 성공 값 (number
). - What error can occur (
Error
).
어떤 오류가 발생할 수 있습니까 (Error
). - What additional context or dependencies are required (
never
indicates none).
어떤 추가 컨텍스트나 종속성이 필요한가요 (never
는 없음 을 나타냅니다).
┌─── Produces a value of type number │ ┌─── Fails with an Error │ │ ┌─── Requires no dependencies ▼ ▼ ▼Effect<number, Error, never>
Additionally, tracking context allows you to provide additional information to your functions without having to pass in everything as an argument. For example, you can swap out implementations of live external services with mocks during your tests without changing any core business logic.
또한, 컨텍스트 추적을 통해 모든 것을 인수로 전달하지 않고도 함수에 추가 정보를 제공할 수 있습니다. 예를 들어, 핵심 비즈니스 로직을 변경하지 않고 테스트 중에 라이브 외부 서비스 구현을 목(mock)으로 교체할 수 있습니다.
Application code in TypeScript often solves the same problems over and over again. Interacting with external services, filesystems, databases, etc. are common problems for all application developers. Effect provides a rich ecosystem of libraries that provide standardized solutions to many of these problems. You can use these libraries to build your application, or you can use them to build your own libraries.
TypeScript로 작성된 애플리케이션 코드는 종종 같은 문제를 반복해서 해결합니다. 외부 서비스, 파일 시스템, 데이터베이스 등과 상호작용하는 것은 모든 애플리케이션 개발자에게 공통적인 문제입니다. Effect는 이러한 문제들에 대해 표준화된 솔루션을 제공하는 풍부한 라이브러리 생태계를 제공합니다. 이 라이브러리들을 사용해 애플리케이션을 구축할 수도 있고, 직접 라이브러리를 만드는 데 활용할 수도 있습니다.
Managing challenges like error handling, debugging, tracing, async/promises, retries, streaming, concurrency, caching, resource management, and a lot more are made manageable with Effect. You don’t have to re-invent the solutions to these problems, or install tons of dependencies. Effect, under one umbrella, solves many of the problems that you would usually install many different dependencies with different APIs to solve.
오류 처리, 디버깅, 추적, 비동기/프로미스, 재시도, 스트리밍, 동시성, 캐싱, 자원 관리 등과 같은 도전 과제들을 Effect를 통해 관리할 수 있습니다. 이러한 문제들의 해결책을 다시 발명하거나 수많은 의존성을 설치할 필요가 없습니다. Effect는 하나의 통합된 환경에서 여러 API를 가진 다양한 의존성을 설치해 해결하던 문제들을 한꺼번에 해결합니다.
Effect is heavily inspired by great work done in other languages, like Scala and Haskell. However, it’s important to understand that Effect’s goal is to be a practical toolkit, and it goes to great lengths to solve real, everyday problems that developers face when building applications and libraries in TypeScript.
Effect는 Scala와 Haskell 같은 다른 언어에서 이루어진 훌륭한 작업들에 크게 영감을 받았습니다. 하지만 Effect의 목표는 실용적인 툴킷이 되는 것이며, TypeScript로 애플리케이션과 라이브러리를 개발할 때 개발자들이 매일 마주하는 실제 문제들을 해결하기 위해 많은 노력을 기울이고 있다는 점을 이해하는 것이 중요합니다.
Learning Effect is a lot of fun. Many developers in the Effect ecosystem are using Effect to solve real problems in their day-to-day work, and also experiment with cutting edge ideas for pushing TypeScript to be the most useful language it can be.
Effect를 배우는 것은 매우 재미있습니다. Effect 생태계의 많은 개발자들이 일상 업무에서 실제 문제를 해결하기 위해 Effect를 사용하고 있으며, TypeScript를 가장 유용한 언어로 만들기 위한 최첨단 아이디어를 실험하고 있습니다.
You don’t have to use all aspects of Effect at once, and can start with the pieces of the ecosystem that make the most sense for the problems you are solving. Effect is a toolkit, and you can pick and choose the pieces that make the most sense for your use case. However, as more and more of your codebase is using Effect, you will probably find yourself wanting to utilize more of the ecosystem!
Effect의 모든 측면을 한꺼번에 사용할 필요는 없으며, 해결하려는 문제에 가장 적합한 생태계의 일부부터 시작할 수 있습니다. Effect는 도구 키트이며, 사용 사례에 가장 적합한 부분을 선택하여 사용할 수 있습니다. 하지만 코드베이스에서 Effect를 점점 더 많이 사용하게 되면 생태계의 더 많은 부분을 활용하고 싶어질 것입니다!
Effect’s concepts may be new to you, and might not completely make sense at first. This is totally normal. Take your time with reading the docs and try to understand the core concepts - this will really pay off later on as you get into the more advanced tooling in the Effect ecosystem. The Effect community is always happy to help you learn and grow. Feel free to hop into our Discord or discuss on GitHub! We are open to feedback and contributions, and are always looking for ways to improve Effect.
Effect의 개념이 처음에는 낯설고 완전히 이해되지 않을 수 있습니다. 이는 매우 정상적인 일입니다. 문서를 천천히 읽으며 핵심 개념을 이해하려고 노력하세요. 이는 나중에 Effect 생태계의 고급 도구를 사용할 때 큰 도움이 될 것입니다. Effect 커뮤니티는 여러분이 배우고 성장하는 것을 항상 기쁘게 지원합니다. 언제든지 Discord에 참여하거나 GitHub에서 토론해 주세요! 우리는 피드백과 기여를 환영하며, Effect를 개선할 방법을 항상 모색하고 있습니다.