Live data from Hacker News

Thoughts on Rust, a few thousand lines in

rcoh.me

111–120 of 183 posts

Re: Thoughts on Rust, a few thousand lines in

#111
post #105

Earlier quoted context omitted.

Could you site this? I've looked at ilovecaching's comment history (at least up to ~60 days ago) and they seem consistent on being a networking programmer who uses C++. Was there a particular comment you found which would indicate this isn't the truth?

nb: you mean "cite". why would you make me do this? you can doxx people on your own dime... still, for posterity: https://news.ycombinator.com/item?id=18328964 "...now I am working full time as a Rust developer" https://news.ycombinator.com/item?id=18310666 "As a long time Erlang developer..." https://news.ycombinator.com/item?id=18265199 "As someone who has worked two jobs now writing, deploying, and operating Erlan…

You have a point, but he never said he programmed exclusively in C++, so I don’t really see the issue here...

Re: Thoughts on Rust, a few thousand lines in

#112
post #105

Earlier quoted context omitted.

Could you site this? I've looked at ilovecaching's comment history (at least up to ~60 days ago) and they seem consistent on being a networking programmer who uses C++. Was there a particular comment you found which would indicate this isn't the truth?

nb: you mean "cite". why would you make me do this? you can doxx people on your own dime... still, for posterity: https://news.ycombinator.com/item?id=18328964 "...now I am working full time as a Rust developer" https://news.ycombinator.com/item?id=18310666 "As a long time Erlang developer..." https://news.ycombinator.com/item?id=18265199 "As someone who has worked two jobs now writing, deploying, and operating Erlan…

A couple languages doesn't seem beyond the realm of possibility for one engineer to be familiar with, though?

Re: Thoughts on Rust, a few thousand lines in

#113
post #105

Earlier quoted context omitted.

Could you site this? I've looked at ilovecaching's comment history (at least up to ~60 days ago) and they seem consistent on being a networking programmer who uses C++. Was there a particular comment you found which would indicate this isn't the truth?

nb: you mean "cite". why would you make me do this? you can doxx people on your own dime... still, for posterity: https://news.ycombinator.com/item?id=18328964 "...now I am working full time as a Rust developer" https://news.ycombinator.com/item?id=18310666 "As a long time Erlang developer..." https://news.ycombinator.com/item?id=18265199 "As someone who has worked two jobs now writing, deploying, and operating Erlan…

It really isn't that ridiculous that someone who has worked as a network engineer for a decade would use Erlang, C++, and Go. Even Haskell isn't too much of a stretch, considering the user's company has functional programming expertise in Erlang. Rust is a neat language that, depending on their workload, could replace all of those languages. Why the presumption of bad faith?

Re: Thoughts on Rust, a few thousand lines in

#114

Earlier quoted context omitted.

In Rust, you're supposed to use `unicode-segmentation`[1] if you need to split on logical character (grapheme cluster in the Unicode standard). Otherwise, the iterators `.bytes` emits raw bytes, and `.chars` emits UTF-8 codepoints. Basically, string indexing is a lot harder than it seems at first glance, depending on what you want.

One nitpick: `.chars`[1] gives you an iterable[2] of `char`s[3], each of which is always a 4 byte representation of a valid unicode character. This means that `"asdf".chars().collect()` will have a different size to `"asdf"` and `"asdf".chars().as_str()`. `.chars()` will never give you an incomplete codepoint, but it will give you incomplete characters, as you could have many c̶̼̟̏ó̷̘̉n̴̖̞̏̇t̸̡̃ĭ̸̻̬n̴̯͉̂͑ṵ̴̑a̷̛̫̳t…

> visually are a single char

IIRC that's what grapheme clusters are for.

Re: Thoughts on Rust, a few thousand lines in

#115

> Unlike nearly every language I’ve ever used, Rust actually encourages variable shadowing. Haskell does it too, for the same reason/purpose / with the same effect.

F# supports it, too, although it doesn't seem very popular. Personally, I'm still on the fence and usually avoid it in practice.

It's idiomatic in all ML-family languages, and generally in languages that are functional first and foremost.

Re: Thoughts on Rust, a few thousand lines in

#116

I've not done any rust dev before but the whole variable shadowing thing really scares me, in that it makes it not obvious where the initial declaration comes from. This seems difficult to reason about.

IMO, it should scare you less than mutating the variable, which is the equivalent pattern in most other languages.

Re: Thoughts on Rust, a few thousand lines in

#117
post #105

Earlier quoted context omitted.

Could you site this? I've looked at ilovecaching's comment history (at least up to ~60 days ago) and they seem consistent on being a networking programmer who uses C++. Was there a particular comment you found which would indicate this isn't the truth?

nb: you mean "cite". why would you make me do this? you can doxx people on your own dime... still, for posterity: https://news.ycombinator.com/item?id=18328964 "...now I am working full time as a Rust developer" https://news.ycombinator.com/item?id=18310666 "As a long time Erlang developer..." https://news.ycombinator.com/item?id=18265199 "As someone who has worked two jobs now writing, deploying, and operating Erlan…

Not seeing any major inconsistencies. Three months ago they exclusively used Go and Rust, at some point before that they used Erlang and Haskell and they used C++ for a total of over 10 years.

Re: Thoughts on Rust, a few thousand lines in

#118

let foo = "..."; let foo = parse(foo); let foo = escaped(foo); Is it really shadowing or mutation of foo? I would consider this shadowing (something you can do in OcaML): let foo = "..." in let foo = parse(foo) in let foo = escaped(foo) in dosomething(foo);;

Look at it closely - it's exactly the same as your OCaml example, except it uses ";" instead of "in", and indentation is adjusted accordingly.

Although in practice I found that it's common to not indent adjacent nested let..in blocks in OCaml, either, so you'd often see something like:

  let foo = "..." in
  let foo = parse(foo) in
  let foo = escaped(foo) in
  ...
And the rules are really simple - "let" always introduces a new binding.

Re: Thoughts on Rust, a few thousand lines in

#119
post #13

Earlier quoted context omitted.

You can't mutate variables in rust without declaring mut

But how do you know just by reading that code? It would not be obvious to me at all.

`let` rebinds. If there isn't a `let`, it's mutation.

Re: Thoughts on Rust, a few thousand lines in

#120

Earlier quoted context omitted.

> How often comparatively do you want the nth byte compared to the nth character? I would suspect that's pretty rare. It's exactly the opposite of what you expect. Getting the nth codepoint is often (not always) semantically incorrect since a codepoint isn't necessarily one character. Multiple codepoints might combine to form one character. (In Unicode, these are called grapheme clusters.) Byte offsets are used a ton…

I still think that using the common [] operator for this is a mistake. Strings shouldn't offer [] at all, and instead should provide methods like codepoints(), bytes(), grapheme_clusters() etc for indexing, slicing, and iterating. The reason being that the behavior of [] for string varies widely in different languages, and so this is something that's best made explicit, both to force the author of the code to conside…

I'm quite thankful that Rust has succinct notation for slicing strings. Do note that `string[n]` is not supported, so you'll stumble over an inconsistency in your mental model quite quickly if you think slicing is by codepoint.
Post reply on HN