News for hackers. Stuff that matters.
Re:Tour of Rust by blondin on Sunday July 12, 2020 @05:25AM (#23810095)
rust doesn't look like it has a steep learning curve. not to me at least. the discouraging thing is the "weird" syntax. i feel like rust is the result of diverging ways of looking at things.

not saying it's a bad. just wish some effort were put into making a consistent syntax.

seems weird to me that whoever decided on the function keyword "fn" would write the "Option" type. they would have written "Opt". but no, it's "Option".

consistency is very underrated. and these things just look odd to me but the rust community think it's okay, so, oh well...

Re:Tour of Rust by kibwen on Sunday July 12, 2020 @05:40AM (#23810157)
The general wisdom of language/library design is that abbreviations should be used only for very common things, and only when those abbreviations are unambiguous in context. Prehistoric Rust had a rule that all keywords could be no longer than five characters (in defiance of Javascript's `function`), but forums (including HN) endlessly complained about `ret`, hence today it's `return`. :P (I admit that I wanted to Rust to change its `fn` to `func` once Swift showed its hand, but such is life.)

Meanwhile, in 2020 `Option` might be on its way to becoming a widely-accepted concept in language design, but back in 2011 it was still a radical idea that Rust was trying to smuggle over the border from functional languages, against the will of people used to languages with pervasive nullity. The language that eventually supplants Rust someday might call it `Opt` (in the same way that Rust turned C++'s `vector` into `Vec`), but back then `Option` needed all the lubrication it could get without having to get bogged down in the abbreviation bikeshedding.

Re:Tour of Rust by zozbot234 on Sunday July 12, 2020 @06:29AM (#23810353)
The thing is that 'return' is not very common either, because Rust has shorthand for returning at the end of a function :-P

I think the standard library ought to use slightly longer names since it's far less strictly bounded than the set of language keywords, so I'm fine with 'Option'. 'Vec' is a bit awkward from that POV, but then again 'Vector' would be a lot worse. 'Box' is also awkward in the same way but thinking about it, it's not easy to convey the notion "this value is behind a pointer" so you might as well use a conventional name and get it over with.

Re:Tour of Rust by thomasahle on Sunday July 12, 2020 @07:56AM (#23810686)
Why not call it Pointer or Point?
Re:Tour of Rust by wwright on Sunday July 12, 2020 @08:27AM (#23810831)
A Box is not a pointer. It is an object with regular one-owner, no copies semantics. Semantically, it just breaks the object out so that it isn’t “internal” to whatever contains it (useful for keeping individual objects small or working around the requirement that a type have a known, finite size).

A pointer and a heap allocation are the obvious choice for implementing this, but the semantics are notably different than just being a pointer. Rust also does have pointer types which represent true pointers.

Re:Tour of Rust by umanwizard on Sunday July 12, 2020 @09:01AM (#23811004)
AFAICT, Box has exactly the same semantics as C++‘s unique_ptr.
Re:Tour of Rust by temac on Sunday July 12, 2020 @09:39AM (#23811206)
Where it can have the same semantics, yes. But if you look at the details, not exactly. For example Box is not nullable, but a not-nullable C++ equivalent is hard to do given the rest of the language.
Re:Tour of Rust by umanwizard on Sunday July 12, 2020 @11:26AM (#23812043)
Good point on the nullability; yes, that is indeed different from std::unique_ptr.
Re:Tour of Rust by otachack on Sunday July 12, 2020 @08:04AM (#23810721)
In game or graphical development a Point struct/object is usually reserved for Cartesian coordinates. Pointer seems too long. C's use of "*" and "&" remain my favorite though beginners may have more difficulty understanding it, similarly to Rust's Box.
Re:Tour of Rust by twic on Sunday July 12, 2020 @10:46AM (#23811726)
> 'Vec' is a bit awkward from that POV, but then again 'Vector' would be a lot worse

They should just have called it a List, and stopped the propagation of the erroneous belief that a variable-length sequence of things is a vector.

Re:Tour of Rust by remram on Sunday July 12, 2020 @10:56AM (#23811826)
`List` usually refers to a linked list or similar. Vec has the important feature that it encapsulate a contiguous array, which matters in a languages like Rust.
Re:Tour of Rust by xscott on Sunday July 12, 2020 @01:24PM (#23812995)
Python is a very popular language where the list type is implemented as an array, and named a list. Calling these things vectors (C++, Rust) is unfortunate because you eventually want real vectors for working with matrices, and the behavior is different in that context.

As for linked lists, given modern processors and cache behavior, there are very few places where you ever want to chase pointers for a 1D data structure. It seems like a shame to lose a good name to a data structure that should now be avoided most of the time.

Re:Tour of Rust by remram on Friday July 17, 2020 @01:01PM (#23872708)
An array of references. Plus, Python has no way to consume a contiguous array directly.

If you do interoperate through FFI with code in C or similar, you will have to reach for numpy arrays, which are the typed, contiguous arrays of Python.

Re:Tour of Rust by twic on Sunday July 12, 2020 @01:31PM (#23813057)
> `List` usually refers to a linked list or similar.

No, it doesn't. There are a handful of languages where this is true, and no reason other than language-specific practice to think that a list is implicitly a linked list. People always make this objection and it's honestly just bizarre.

Re:Tour of Rust by ImprobableTruth on Sunday July 12, 2020 @10:55AM (#23811824)
Or - since lists call to mind a very specific data structure (linked lists) - they could have just called it Sequence.
Re:Tour of Rust by FnuGk on Sunday July 12, 2020 @12:19PM (#23812421)
A sequence does not contain duplicates. A vector can
Re:Tour of Rust by detaro on Sunday July 12, 2020 @12:21PM (#23812440)
Mathematical sequences totally can have duplicates. E.g. to take a popular example, the Fibonacci sequence starts: 0, 1, 1, ...
Re:Tour of Rust by jcelerier on Sunday July 12, 2020 @09:54AM (#23811298)
> but back in 2011 it was still a radical idea

boost.optional was introduced in 2003

Re:Tour of Rust by qznc on Sunday July 12, 2020 @07:27AM (#23810569)
Why not `fun` as a pun?
Re:Tour of Rust by zozbot234 on Sunday July 12, 2020 @07:30AM (#23810576)
Because ML and Ocaml are already putting the `fun` in function. It would look way too derivative.
Re:Tour of Rust by techolic on Sunday July 12, 2020 @11:28AM (#23812056)
> It would look way too derivative.

Is that considered a bad thing in the Rust community?

Re:Tour of Rust by steveklabnik on Sunday July 12, 2020 @12:24PM (#23812476)
No, it is not. In fact, it is often seen as a good thing: https://steveklabnik.com/writing/the-language-strangeness-bu...
Re:Tour of Rust by timClicks on Sunday July 12, 2020 @06:33AM (#23810360)
FWIW, I really like fn.
Re:Tour of Rust by yodelshady on Sunday July 12, 2020 @07:05AM (#23810494)
You want to see sadness, from a learning curve point of view?

How to read from stdin on Rust.

https://stackoverflow.com/questions/30186037/how-can-i-read-...

Naturally, `read_line` returns the number of bytes read, rather than... the line. If you want a function or macro that does simply return a string, the best way is to... download an external crate? Because nothing says "security" more than third-party dependencies for basic tasks.

Incidentally, use of said crates is different dependent on Rust 2015/2018. Half of the internet resources you will see are wrong. If you already understand the differences, you'll know which is which.

Oh, and if you see "type" unaware in a Rust codebase, you know the one thing it isn't... is a type. Generics are sometimes elided, sometimes not, and sometimes live in a separate namespace.

Oh, and if you test code on a static array of length < 32, and a similar array of length > 32, you will see completely different behaviour.

Oh, and no REPL. This has got to be my single favourite thing about Python - I am literally never surprised. Because any, single, line of code I'm not 100% on is tested in seconds. A browser-based substitute is just that, a very poor substitute.

Rust has good points, but some huge ergonomic difficulties for a beginner, that are nothing to do with "the core difficulty of programming" - you'll note I've not even mentioned how a reader is supposed to comprehend what a <&'a T> is. The best I can say is that it's good gatekeeping.

Re:Tour of Rust by zozbot234 on Sunday July 12, 2020 @07:21AM (#23810546)
> Naturally, `read_line` returns the number of bytes read, rather than... the line.

That decouples the concern of allocating the buffer from reading the actual line. It should be possible to write a wrapper that does "return the line" (in an owned buffer), and that might be a bit cleaner in simple cases. But the stdlib should focus on providing essential functionality first.

> Oh, and if you test code on a static array of length < 32, and a similar array of length > 32, you will see completely different behaviour.

This will most likely change after const generics get fully stabilized. The current code is already using them under the hood, but the separate behavior for size>32 is being kept for forward compatibility in case const generics need to change.

> you'll note I've not even mentioned how a reader is supposed to comprehend what a <&'a T> is.

That comes up almost exclusively when working with references that have different lifetimes. Rust tries to deduce lifetimes whenever possible so that writing them out isn't necessary most of the time, but sometimes the programmer has to resolve ambiguity. The whole system is still quite intuitive.

Re:Tour of Rust by yodelshady on Sunday July 12, 2020 @09:00AM (#23810992)
>It should be possible to write a wrapper that does "return the line" (in an owned buffer), and that might be a bit cleaner in simple cases.

So put it in std lib. The point of computers is to not force humans to duplicate identical, basic tasks millions of times, and a major selling point of Rust is zero cost abstractions.

Stdlib Rust has everything necessary to write a read_line that returns a good abstraction - Result<&str, Err> - and instead provides a leaky one. I shouldn't be giving a pigs' ear about the buffer length. And come on, a language with vec.windows() in the std library is not minimal. It's just inconsistent.

Re:Tour of Rust by Misdicorl on Sunday July 12, 2020 @09:22AM (#23811127)
Well actually you couldn't return an &str, because it would be dropped at the end of the read.

You'd need to return either a String (and that would be a big mistake) or a Vec of u8. Which I'm sure you'd also be unhappy with

Re:Tour of Rust by yodelshady on Sunday July 12, 2020 @12:13PM (#23812372)
>It should be possible to write a wrapper that does "return the line"

Is it, or not? What's the point of lifetimes if you can't manage that trivial outlives-the-creator task in literally every other language ever with them? Why would a String be a big mistake?

You STILL think Rust is easy to learn?

Re:Tour of Rust by estebank on Sunday July 12, 2020 @12:18PM (#23812415)
It is. The reason it is not in the stdlib is because it is a foot-gun. Quoting myself from elsewhere in this thread[1]:

> Other languages aimed at ease of use will just allocate for you and give you the fully baked contents in a single fn call, but when you're writing code that 1) has to be called often enough where allocations can show up in your flame graphs or 2) the input is big enough that you can't realistically keep the entire thing in memory at once, you suddenly have to care about what the fn is doing internally. Making the default API for file interaction require you pass in your own buffer makes this explicit at the cost of some ease of use.

[1]: https://news.ycombinator.com/item?id=23811980

Re:Tour of Rust by jfkebwjsbx on Sunday July 12, 2020 @12:57PM (#23812754)
It is not. A very useful function does not mean you have to use it in the hot path or for huge inputs.
Re:Tour of Rust by estebank on Sunday July 12, 2020 @01:13PM (#23812909)
>>>>It should be possible to write a wrapper that does "return the line"

>>> Is it, or not?

>> It is.

> It is not.

I'm arguing that you can write that function. What Misdicorl is saying is that it would be

    fn read_line_alloc(&self) -> Result<String>
and not

    fn read_line_alloc(&self) -> Result<&str>
because the &str would be an "use-after-free" situation, and Rust won't let you compile it. You need to allocate if you are reading from a file in order to be able to close (or seek) that file.

yodelshady seems to be under the impression that this means the functionality they want (single method call that doesn't require passing in a buffer) can't be implemented. It can, it just needs to allocate, the same way that you need to explicitly allocate the buffer you pass into read_line.

> A very useful function does not mean you have to use it in the hot path or for huge inputs.

I'm also arguing against it being provided in the stdlib because Rust is big in avoiding "you're holding it wrong" kind of answers, by removing the possibility to hold it wrong. Reasonable people can disagree :)

I've also found it annoying in the past. If Rust didn't have a design goal of giving programmers full control over the behavior of their code, there are several ergonomics changes that we could make to make it much easier to use, but alas, that is not the language we have and we work with what we can make ergonomic and easy to use.

Re:Tour of Rust by steveklabnik on Sunday July 12, 2020 @01:16PM (#23812935)
I will say that I agree with almost everything you’ve said on this thread, but we did add std::fs::{read,read_to_string} for files to have this convenience. Adding something for stdin would bring that up to parity.
Re:Tour of Rust by estebank on Sunday July 12, 2020 @01:21PM (#23812968)
Somehow I missed/forgot about that addition to the stdlib. I understand why (as evidenced by the requests in this same thread), but it I'm sad it's another thing I have to look for in code reviews ^_^'
Re:Tour of Rust by e12e on Sunday July 12, 2020 @03:00PM (#23813801)
Would that work with /dev/stdin on Linux ?
Re:Tour of Rust by steveklabnik on Sunday July 12, 2020 @03:59PM (#23814282)
I’d imagine so.
Re:Tour of Rust by jfkebwjsbx on Tuesday July 14, 2020 @01:01AM (#23828691)
> I'm also arguing against it being provided in the stdlib because Rust is big in avoiding "you're holding it wrong" kind of answers

Even if it was true that Rust is big on that, such a function is not "holding it wrong", it is just a matter of convenience and development speed vs. performance.

For the vast majority of code it does not matter whether you allocate a few times or not. The timing difference is in the noise.

Let Rust be a convenient language rather than a PITA.

Re:Tour of Rust by Misdicorl on Sunday July 12, 2020 @01:38PM (#23813112)
Re: lifetimes question.

You can solve this in rust just like you can in every other language. By allocating memory in the function and returning the allocation. String, not &str, is what represents that behavior.

&str is kind of a rust wart that only exists because it's so damn useful to provide static text strings in a binary. Every other usage is pretty questionable and should basically be ignored/changed imo

Re:Tour of Rust by zozbot234 on Sunday July 12, 2020 @01:46PM (#23813172)
&str is hardly a 'wart'. It's basically a safe version of C++ string_view, and it (together with array slices, which &str is essentially a special case of) is a very good example of the sorts of features that are enabled by Rust's focus on memory safety and close-to-the-metal efficiency.
Re:Tour of Rust by Misdicorl on Sunday July 12, 2020 @02:13PM (#23813387)
Those &str use cases are just as easily handled by &String. Perhaps with some extra sugar to slice at a requested boundary.
Re:Tour of Rust by dbaupp on Sunday July 12, 2020 @05:23PM (#23814869)
&String cannot, by itself, handle a substring because it has to point to an (immutable) whole String struct in memory. Any extra syntax or types to package up subslice boundaries would almost certainly end up as something similar to &str, just with potentially different syntax and likely slower.
Re:Tour of Rust by Misdicorl on Sunday July 12, 2020 @06:38PM (#23815358)
I think you are incorrect. Exposing a slice of a String as an &String should have no performance impact (pointer and length just like &str). The only thing that becomes interesting is whether you can expose a mutable string slice
Re:Tour of Rust by dbaupp on Monday July 13, 2020 @12:31AM (#23817186)
At the very least, retrieving data from a &String will involve two pointer lookups (one for the &, one for the internal pointer in the String) whereas plain String and &str involve just one.

In addition, since the String object itself cannot be mutated, a slice like s[10:20] as a &String requires storing the 10 and 20 outside the String and then doing pointer offsets when reading the data. A &str does not need to do this, because the pointer offset happens on creation. Because of this, the &str is also smaller (and this is more efficient because of caches), because it only needs to store a pointer and length (16 bytes, on typical machines), while a &String needs to store at least a pointer to the String and the start/end indices (24 bytes).

One could have various special cases to make &String “work” but it likely ends up being equivalent to &str. The key piece in mind: if one retains the &String name, it makes the language less orthogonal, with more special cases, because taking a reference to a string variable like &s to get a value of type &String behaves very differently to taking a reference to any others like &some_int (of type &i32), which will cause problems in generic code.

Re:Tour of Rust by Misdicorl on Monday July 13, 2020 @09:52AM (#23820737)
What issues arise by aliasing &str and &String to the same (&str) implementation? Does any code actually rely on &String pointing at the String itself rather than the bytes of the string?

Perhaps its more strange/broken to special case &String that it is to have the (imo) warty &str.

Re:Tour of Rust by dbaupp on Monday July 13, 2020 @08:09PM (#23827149)
Unsafe generic code likely cares, where it is coercing a &T to a *const T and then relying on pointer stability/consistency. It will also cause difficulties with methods like ‘.capacity()’, because that info is lost with &str.
Re:Tour of Rust by Misdicorl on Sunday July 12, 2020 @01:30PM (#23813043)
Making it return a string would be a mistake for the space rust wants to (first) play in: low level system development. Returning a String requires figuring out what encoding the string has and parsing the contents in that encoding. That's not trivial or cheap or sometimes even possible (not all byte combinations are valid in all encodings) compared to filling a vec of bytes.

That said, it's probably worthwhile to expose the functionality since people would find it useful in a lot of cases

Re:Tour of Rust by zozbot234 on Sunday July 12, 2020 @01:50PM (#23813194)
Returning a String is not necessarily a mistake; you could check for UTF-8 validity and error out if the line is not valid UTF-8 - and if you're providing a wrapper for "simple" uses, this might even be the right call. You're right that the general case involves outputing raw bytes, of course.
Re:Tour of Rust by andrewflnr on Sunday July 12, 2020 @01:57PM (#23813259)
I don't think anyone is saying Rust is easy to learn. They're saying the complexity is justified (mostly).
Re:Tour of Rust by yodelshady on Sunday July 12, 2020 @05:36PM (#23814962)
On looking at my code that does file reads, and steveklabnik's suggestion - Vec<u8> makes reasonable sense. At least that way, if you want nice encodings you've got the same problem agnostic of where the "string" came from.

Aka... a nice abstraction.

Re:Tour of Rust by jki275 on Sunday July 12, 2020 @10:18AM (#23811439)
read_line returning the number of bytes read instead of the bytes is a C thing. That's just how you do things in C.

Not arguing it's the best way -- and I far prefer the C++ way of returning a string or a buffer -- but it's the C way.

Re:Tour of Rust by estebank on Sunday July 12, 2020 @11:16AM (#23811980)
As the sibling comment said it's not a C thing. It is done that way in C because you have to babysit allocations. Other languages aimed at ease of use will just allocate for you and give you the fully baked contents in a single fn call, but when you're writing code that 1) has to be called often enough where allocations can show up in your flame graphs or 2) the input is big enough that you can't realistically keep the entire thing in memory at once, you suddenly have to care about what the fn is doing internally. Making the default API for file interaction require you pass in your own buffer makes this explicit at the cost of some ease of use. Seeing this will also serve as a teachable moment, when the dev looks at the docs trying to understand why it has such an obtuse API, hopefully coming away with this comment's explanation. This might seem to be a pedantic distinction but I've seen Java codebases where buffer reuse was mandatory in the hot path and Rust is all about removing foot guns.
Re:Tour of Rust by jki275 on Sunday July 12, 2020 @02:42PM (#23813661)
I agree with you on why it’s done that way in C, and certainly it can be in other languages. No argument there.

But it really is a C thing, because that’s just “how you do it” in C.

Re:Tour of Rust by twic on Sunday July 12, 2020 @10:51AM (#23811784)
It's how Java's InputStream and Reader work, too. In any language, requiring the caller to supply the buffer is a prerequisite for efficiency.
Re:Tour of Rust by c0rax on Sunday July 12, 2020 @07:41AM (#23810613)
Not to take away from your opinion (and I appreciate what you're saying) but it does bother me a bit when people who are not too familiar with Rust express their qualms with the syntax as rhetorical questions, rather than actually asking why things are the way they are. It's not arbitrary.

"fn" is pervasive, and a fundamental keyword embedded into the language. A tradeoff was made in expresiveness VS frequency of use, since it gets typed so frequently that a quick shorthand is warranted. That's the reason why "return" is not "ret", because idiomatic Rust barely uses that keyword.

Option is not even part of the language itself, it's a normal enum type in the std lib imported by the prelude.

I often have a similar dicussion around "let". Many of my C++ programmer colleagues seem to think that "let" is an arbitrary name to differentiate itself for the sake of it where "auto" would suffice. But what they don't see is that let is an entirely different thing (bindings, pattern matching, etc) that would be misleading to present with "auto", let alone C/C++'s type-name-value syntax.

Re:Tour of Rust by wtetzner on Sunday July 12, 2020 @10:38AM (#23811650)
> I often have a similar dicussion around "let". Many of my C++ programmer colleagues seem to think that "let" is an arbitrary name to differentiate itself for the sake of it where "auto" would suffice. But what they don't see is that let is an entirely different thing (bindings, pattern matching, etc) that would be misleading to present with "auto", let alone C/C++'s type-name-value syntax.

Not to mention that "let" came from ML. The idea that they "deviated" from C++ syntax is wrong, because they didn't take the feature from C++ at all.

Re:Tour of Rust by willtim on Sunday July 12, 2020 @06:13AM (#23810285)
I don't like many of the syntax choices either (e.g. the function return type syntax borrows from, but is not consistent with ML/Haskell). However, the language and tooling is already a huge improvement over C and there is already a significant community and lots of momentum. I wouldn't let a few syntactic warts put me off what could be a major improvement in the standard of systems programming.
Re:Tour of Rust by justaj on Sunday July 12, 2020 @05:47AM (#23810182)
> rust doesn't look like it has a steep learning curve

I'll have to strongly disagree. I tried learning it as my first language and was blown away by the prerequisite knowledge I had to have in order to understand even the basic concepts.

Added to the fact that currently there aren't even learning resources available for people like me, makes this language mostly suitable for people already familiar with other languages.

Re:Tour of Rust by baq on Sunday July 12, 2020 @06:07AM (#23810265)
The other side of the coin is that programming, software development and software engineering are really really difficult and Rust simply exposes you to a much larger subset than most other languages in order for your code to execute. Note that those things that Rust forces you to think about exist in all these other languages, they’re just hidden, for good reason, but also for a price.
Re:Tour of Rust by brabel on Sunday July 12, 2020 @10:29AM (#23811560)
> rust doesn't look like it has a steep learning curve

> I'll have to strongly disagree.

You're not alone... It's the first time I hear anyone saying Rust does NOT have a steep learning curve. It's widely considered as one of the most difficult languages out there (the fact it's also one of the most loved seems to not be a coincidence: only if you actually like it do you manage to get past the initial difficulty).

Even very experienced programmers find it difficult because you just can't write code the way you're used to when not having the borrow check limitations.

Re:Tour of Rust by estebank on Sunday July 12, 2020 @11:22AM (#23812016)
I have the unsubstantiated theory that experienced developers have a harder time than less experienced developers when learning Rust. You need to forget a lot of constructs that work well enough in the languages you already know because they introduce things that go counter the single owner enforcement that Rust has, whereas somebody with less experience will simultaneously accept restrictions as "just the way it is" and not seek out more performant constructs that are much harder to understand.
Re:Tour of Rust by brabel on Monday July 13, 2020 @05:02AM (#23818703)
The parent commenter is an example of a beginner programmer who found it very hard to start with Rust as a first language. I believe he's typical because as he said, you need to know A LOT of things in Rust to get even very simple things done, unlike "easier" languages like Python and JavaScript.
Re:Tour of Rust by ghosty141 on Sunday July 12, 2020 @06:55AM (#23810449)
Not having a steep learning curve does not imply it‘s a good first language. I‘d recommend python to get started and then switching to a staticly typed lang. Rust requires you to have quite some experience to know when to use what.
Re:Tour of Rust by IshKebab on Sunday July 12, 2020 @06:33AM (#23810364)
It doesn't look like that because all the examples you see are working code. Try actually writing some and you will find it is quite difficult.

I would say it has a less steep learning curve than Haskell. But definitely steeper than most languages - C, C++, Go, Python, JavaScript, etc.

Re:Tour of Rust by wtetzner on Sunday July 12, 2020 @10:41AM (#23811689)
Of course, it all depends on your background. For me, the only part that took getting used to was the borrow checker.

However, I'm not really sure the learning curve for C++ is lower. There's a lot more to learn, and there's a good chance that you're just writing incorrect programs if you haven't gone through the effort of learning about ownership semantics anyway. Does that mean you've learned the language, or just that the compiler doesn't care?

Re:Tour of Rust by nilkn on Sunday July 12, 2020 @12:27PM (#23812494)
I'm always extremely skeptical when I see people claim C++ is easier than Rust. Rust essentially just makes you default to good practices in modern C++ and forces you to be explicit about things like copying data, allocating on the heap, etc. If C++ feels easier, it's because you either already know it and you're comparing it to something you don't know, or it's because your C++ code is actually very different than your Rust code (lots of heap allocations and copies vs. lots of stack allocations and moves), or it's because your C++ code has a lot of bugs that you haven't encountered yet.
Re:Tour of Rust by zozbot234 on Sunday July 12, 2020 @12:45PM (#23812649)
C++ feels easier because we have 30 years' experience with teaching it to novices as a first programming language. That counts for a lot. We still don't quite know how to do this with Rust.
Re:Tour of Rust by orthoxerox on Sunday July 12, 2020 @10:24AM (#23811507)
Writing the application logic in Rust isn't different from doing it in any other Algol-like procedural language. You even get nice functional abstractions.

The learning cliff is in the memory management. Rust combines no GC with no memory leaks by forcing you to prove to it that your algorithm doesn't leak anything. And you have to do this every time you want your code to compile.

There's no way in Rust to write your business logic first and plug the memory leaks later. And it's not just the compiler issue, the whole ecosystem expects you to think about the right abstraction for managing memory from step zero.

This means that when you're writing Rust as a novice or a journeyman you have to simultaneously think about the correctness of your algorithm and about its memory safety.

Re:Tour of Rust by hu3 on Sunday July 12, 2020 @11:10AM (#23811942)
Rust doesn't prevent memory leaks. I thought I'd chime in since I see this claim often around these parts. See:

https://doc.rust-lang.org/book/ch15-06-reference-cycles.html

> Rust combines no GC with no memory leaks by forcing you to prove to it that your algorithm doesn't leak anything. And you have to do this every time you want your code to compile.

Re:Tour of Rust by pkolaczk on Sunday July 12, 2020 @12:40PM (#23812605)
While Rust may not guarantee freedom from memory leaks (probably no Turing complete language can), I find it makes a much better job on resource management than many other GCed languages. I find it is much easier to leak a file descriptor in Java than in Rust.
Re:Tour of Rust by orthoxerox on Sunday July 12, 2020 @12:57PM (#23812756)
It doesn't prevent all memory leaks, but its goal is the prevention of most memory leaks/buffer overruns and other memory management errors with zero runtime overhead.
Re:Tour of Rust by swsieber on Sunday July 12, 2020 @11:01AM (#23811865)
Safe rust actually let's you leak memory if you want. It tends not happen unless you try (in my limited experience).

What it does prevent is memory unsafely: read after free, double free, buffer overflows, etc.