HackerTrans
TopNewTrendsCommentsPastAskShowJobs

p7g

no profile record

Submissions

Show HN: Patina – Python adaptations of Rust's Option, Result, and HashMap

github.com
3 points·by p7g·5 ปีที่แล้ว·1 comments

comments

p7g
·5 ปีที่แล้ว·discuss
This discussion is about the standard library, not the language runtime. Decent performance here is meant relative to the performance of the language. In this case it could mean algorithmic complexity, for example.
p7g
·5 ปีที่แล้ว·discuss
> It's primarily a testament to how simply mind bogglingly slow Python is outside of its optimised numerical science ecosystem.

CPython's slowness doesn't boggle my mind at all. It's a bytecode interpreter for an incredibly dynamic language that states simplicity of implementation as a goal. I would say performance is actually pretty impressive considering all that. What _does_ boggle my mind is the performance of cutting-edge optimizing compilers like LLVM and V8!

At least there is a benefit to a simple implementation: Someone like me can dive into CPython's source and find out how things work.
p7g
·5 ปีที่แล้ว·discuss
I've been writing a library that implements some of Rust's types in Python. At this point it's got Option, Result, and HashMap. It tries to match Rust's API exactly where possible, while also supporting the things you would expect in Python like __len__, __iter__, etc.

I ported the Rust documentation as well, using docstrings. The examples in the docstrings are run as tests, and each doctest must be well-typed (according to mypy) for CI to pass.

There are a few reasons why I made this:

- mypy with typing.Optional can enforce checking for None, but it makes me miss Rust APIs like Option.map.

- Python will have pattern matching in 3.10, which will make this library more ergonomically feasible.

- It seemed like a fun and straightforward project.

I'm happy to answer any questions, and would love to hear your constructive criticism.
p7g
·6 ปีที่แล้ว·discuss
Do you have any examples in mind?