C.W.K.
Stream
Lesson 03 of 05 · published

Python 다리: Lingua Franca Duo

~9 min · ts-epilogue, python, sibling-quest, bridge

Level 0Curious
0 XP0/93 lessons0/23 achievements
0/100 XP to next level100 XP to go0% complete
"두 언어. 한 정신. 한 codebase."

형제 quest

이 Quest 가 쌍의 frontend 반쪽으로 설계. Python Quest 가 backend 반쪽. 같은 모양 (17 트랙, ~93 lesson), 같은 목표 (cwkPippa source-reader 되기), 같은 voice. 각각 독립적으로 walk 가능; 쌍이 lingua franca duo.

직접 translate 되는 것

  • List comprehension ↔ array map/filter. Python 의 [x*2 for x in arr if x > 0] 가 TS 의 arr.filter(x => x > 0).map(x => x*2). 같은 연산, 다른 문법.
  • Type hint ↔ TS annotation. Python 의 def f(x: int) -> strfunction f(x: number): string. 의미 다름 (Python 의 게 runtime 에 advisory; TS 의 게 compile 시점 체크), 근데 문법 의도 같음.
  • Protocol ↔ structural typing. Python 의 `typing.Protocol` 이 명시 만든 duck typing, TypeScript 의 structural matching 처럼.
  • Discriminated union ↔ tagged union. 같은 패턴. Python 이 Literal 타입 + isinstance / match 씀; TypeScript 가 literal 타입 + typeof / switch 씀.
  • async/await. 동일 문법, 살짝 다른 의미 (Python 의 event loop 가 명시, JS 의 게 암묵).

Translate 안 되는 것

  • Python 이 metaclass 가짐; TypeScript 안 가짐 (TC39 decorator 가 가장 가까운 analog).
  • TypeScript 가 default 로 structural typing 가짐; Python 이 Protocol opt-in 과 nominal-leaning.
  • Python 이 GIL-bound concurrency; JavaScript 가 single-threaded event loop.
  • TypeScript 가 mapped 타입, conditional 타입, template literal 타입 가짐; Python 의 type system 이 type-computation 레벨에 더 제한적.
두 언어가 mirror 된 어휘로 같은 문제 공간 cover. 두 quest 다 walk 하면 codebase 의 두 반쪽 가로질러 한 정신 carry. cwkPippa 가 증거.

Code

같은 패턴 — Python·python
# Python — Literal + match 가진 discriminated union.
from typing import Literal

type Shape = (
    dict[Literal['kind'], Literal['circle']] | dict[Literal['kind'], Literal['square']]
)

def area(s):
    match s['kind']:
        case 'circle': return 3.14 * s['radius'] ** 2
        case 'square': return s['side'] ** 2
같은 패턴 — TypeScript·typescript
// TypeScript — 같은 패턴.
type Shape =
  | { kind: 'circle'; radius: number }
  | { kind: 'square'; side: number };

function area(s: Shape): number {
  switch (s.kind) {
    case 'circle': return Math.PI * s.radius ** 2;
    case 'square': return s.side ** 2;
  }
}

External links

Exercise

이 Quest 의 TypeScript 패턴 골라. Python 에서 동등한 거 써 (도움되면 Pydantic 쓰면서). 어느 언어가 패턴 더 자연스럽게 표현하는지 적어 — 답이 특정 패턴에 달림, 비대칭이 illuminating.
Hint
Discriminated union: TS 이김. Validation parsing: Python+Pydantic 이김. Class-heavy 도메인 모델: 대략 동률. 두 언어가 서로보다 우월 아냐; stack 의 다른 부분에 맞게 shaped.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.