# Rust처럼 Python 작성하기

> Clean Markdown view of GeekNews topic #9243. Use the original source for factual precision when an external source URL is present.

## Metadata

- GeekNews HTML: [https://news.hada.io/topic?id=9243](https://news.hada.io/topic?id=9243)
- GeekNews Markdown: [https://news.hada.io/topic/9243.md](https://news.hada.io/topic/9243.md)
- Type: news
- Author: [xguru](https://news.hada.io/@xguru)
- Published: 2023-05-23T10:46:01+09:00
- Updated: 2023-05-23T10:46:01+09:00
- Original source: [kobzol.github.io](https://kobzol.github.io/rust/python/2023/05/20/writing-python-like-its-rust.html)
- Points: 18
- Comments: 8

## Topic Body

- Rust를 사용하기 시작하면서 Python 코딩 방식에 Rust의 몇가지 개념을 채택했다고  
- Type Hint를 가능한 많이 사용하기   
- 튜플/딕셔너리 대신 Dataclasses  
- Algebraic data types(ADT)  
- newtype 패턴   
- 타입을 이용하여 invariant 인코딩   
- Strongly-typed bounding boxes

## Comments



### Comment 16221

- Author: iolothebard
- Created: 2023-05-23T16:12:32+09:00
- Points: 1

이럴거면 뭐하러 python을 쓰나...  
(feat. 이럴거면 뭐하러 nodejs를 쓰나)

### Comment 16213

- Author: kherootz
- Created: 2023-05-23T12:56:20+09:00
- Points: 1

타입 정도만 둔거같은데 러스트랑 비교 할만한가요?

### Comment 16210

- Author: jangsc0000
- Created: 2023-05-23T12:08:29+09:00
- Points: 1

Rust처럼 Python을 쓸 거라면 Rust를 쓰는 게 낫지 않을까요?..

### Comment 16236

- Author: cosine20
- Created: 2023-05-24T11:53:06+09:00
- Points: 1
- Parent comment: 16210
- Depth: 1

Rust로 Tensorflow, PyTorch를 쓸 수 있나요? 쓸 수 있다고 해도, 거기에 주렁주렁 달려있는 라이브러리들도 쓸 수 있을지 알 수 없죠. 너무 일차원적인 생각입니다.

### Comment 16214

- Author: daejin
- Created: 2023-05-23T13:01:41+09:00
- Points: 2
- Parent comment: 16210
- Depth: 1

어떤 언어의  좋은 특성(개념)을 사용하는 것이랑, 그 언어를 직접 사용하는 것은 상황에 따라 다르겠지만 다른 것이라고 생각합니다. lisp, 헤스켈 등 함수형 언어 특정을 자바스크립트에서 아주 효과적으로 사용한다고 해서, 자바스크립트를 쓰는 곳에 lisp를 사용할 수 없으니깐요.

### Comment 16206

- Author: winterjung
- Created: 2023-05-23T11:09:02+09:00
- Points: 2

상황에 따라 취사선택 해야겠지만 일반적으로 권장하고싶은 접근들이네요.

### Comment 16203

- Author: bus710
- Created: 2023-05-23T10:51:23+09:00
- Points: 1

제가 파이썬을 잘 몰라서....  
이런식으로 하면 오버헤드가 많아지지 않을까요?

### Comment 16207

- Author: lordang
- Created: 2023-05-23T11:10:13+09:00
- Points: 2
- Parent comment: 16203
- Depth: 1

내용 전반적으로 type hint 쓰겠다는 내용이 많은데, 이건 런타임에 하는 게 아니라, 성능과는 관계가 없고요. isinstance같은 타입 체크하는 부분은 없는 거보다야 더 걸리겠지만, 내부적으로 캐쉬되는 걸로 압니다. 엄청난 루프에서 하면 차이가 생기긴 하겠져.
