Hacker News new | ask | show | jobs
by pantulis 1891 days ago
"(...) Rust feels more like Python than C. (...)"

This feels like a very powerful assertion. Does the rest of the HN audience agree with this? If this is true, how long did it take?

3 comments

For me, this feeling comes from how Rust APIs are typically built. They embed enough information about allowed usage that shooting yourself in the foot is not trivially possible (unlike C).

I guess one could say APIs expose functionality on the level somewhat similar to C++, with builtin strings, vectors, and other high level data structures that are namespaced and are also objects. Whether that is more C-like or Python-like is for the reader to answer.

I'm a bit confused by this take. With Rust you're constantly thinking low level details, like which type of reference something is. I would place it closer to C than Python, but closer to C++ than either.
I wouldn't say that thinking about ownership is "low level details". You are (or should?) always having to think about this when building APIs. The difference is that in for example Python you don't have a way to encode that information and enforce it. I would say that the "feeling" of writing on a high-level language comes from a few ergonomic features:

- Match ergonomics, so that you have to think about borrowing less in patterns

- The compiler providing suggestions for those cases where you must specify them

- Type inference

- Iterators letting you write fairly functional code

Things like having to write &*foo[..] or .as_mut_ref() are indeed "warts" when you don't care about those details, but they happen uncommonly enough that it isn't perceived as an onerous cost.

> You are (or should?) always having to think about [ownership] when building APIs.

This isn't strictly true. For instance Swift uses value semantics, which is equivalent to adding an implicit `.copy()` in rust every time most variables are passed around. It obviates a lot of the low-level details, at the cost of performance and control. This is a lot more "python-like" in my opinion, where having to hold these details in your mind is very much against the design priorities of python.

Python wants everything to be implicit, to eliminate tedium wherever possible, and for syntax to barely exist. By contrast Rust favors explicitness, demands a lot ceremony, and is very syntax-heavy. These languages are antithetical in so many ways.

It's fairly subjective, so I would not try to convince you that Rust is more similar to C than Python, but many of the points you brought up apply to virtually every modern mainstream language. It's hard to imagine why Python would come up as a comparison point for Rust unless C and Python were literally the only other languages you had ever programmed with.

It really depends on what those languages mean to you. I don't think that you can answer these sorts of questions in the general case.

You can sorta kinda compare programs though. I had a discussion about this on HN last year. Note that this is an extremely small sample size, but you know https://news.ycombinator.com/item?id=22712441

I wrote an updated version half a year ago https://news.ycombinator.com/item?id=24595081

YMMV. It depends on a lot of factors.