Live data from Hacker News

Announcing Rust 1.24.1

blog.rust-lang.org

31–40 of 66 posts

Re: Announcing Rust 1.24.1

#31

Rust gives me a headache. I want to like it, but it just seems so... overengineered https://doc.rust-lang.org/std/str/struct.SplitWhitespace.htm... Why would you create a special data type to represent a string split by Whitespace? Lunacy

> Why would you create a special data type to represent a string split by Whitespace? Lunacy Because it's an iterator. A bespoke iterator type is also created behind the scenes in many other languages. How else would you do it?

> How else would you do it?

There is a `splitWhitespace` iterator[1] in the Nim programming language as well and doesn't require a separate type. In Nim, the iterator is inlined.

1 - https://nim-lang.org/docs/strutils.html#splitWhitespace.i,st...

Re: Announcing Rust 1.24.1

#32
post #28
post #26

Earlier quoted context omitted.

Firstly, manual memory management is what happens when a C programmer must manually place malloc/free calls within her program. Rust doesn't require any of that; the compiler determines the right times to allocate and free memory, while requiring the programmer to follow certain design rules in exchange for the convenience. Second, you're making it sound as if the position Rust (and those who program in it) is someho…

Interesting; I certainly wouldn't consider C++ constructor/destructor like semantics and manual tracking of object ownership in the code as automatic memory management. But regardless, the point stands. And yes it's a consequence of a design goal, I said as much. The outcome however isn't beautiful enough to feel smug about the rest of programming languages.

Do you consider C++ RAII as manual memory management?

Re: Announcing Rust 1.24.1

#34
post #29

Rust gives me a headache. I want to like it, but it just seems so... overengineered https://doc.rust-lang.org/std/str/struct.SplitWhitespace.htm... Why would you create a special data type to represent a string split by Whitespace? Lunacy

I would call that underengineered. This could be more generic, both in what it operates on (why only strings and not any sequence of value items?) and what it separates on (why only Unicode whitespace? It could be used as return value from a call that iterates over CSV fields in a line or that finds regex matches in a string).

SplitWhitespace is a convenience. Its underlying internal type is actually:

    Filter, IsNotEmpty>
The split[1] method is generic, and for example, one can indeed use a regex for it. (I wouldn't use it for CSV though, since it would almost certainly be wrong.)

[1] - https://doc.rust-lang.org/std/primitive.str.html#method.spli...

Re: Announcing Rust 1.24.1

#35
post #22
post #16

Earlier quoted context omitted.

Because unlike most other programming languages, Rust is well-engineered and seeks to both provide the most general abstractions possible and to make the code generated by them as efficient as possible. In particular, for this task, this requires to: 1. Return references to subranges of the original string, rather than copying them, so that no copy happens if you only need to examine the component instead of storing…

The better half of those points are directly and indirectly caused by insistence on manual memory management. Yes, it was a major design point of Rust, but it doesn't make it better engineered than "most other languages". It's just the corner it painted itself to.

Rust doesn't have manual memory management. It does have deterministic memory management as opposed to garbage collected language. Which means you can use it it in domains where garbage collected languages cannot be used - e.g. for a OS ...or for implementing a garbage collector.

Re: Announcing Rust 1.24.1

#36
post #10

Earlier quoted context omitted.

That’s not a datatype... That’s an iterater returned by calling .split_whitespace() on a string. Basically the same as calling .split(‘ ‘) on a string in JavaScript You can find a list of Rusts primitive types here: https://doc.rust-lang.org/std/#primitives

> That’s not a datatype It's a named struct. That's pretty datatype-y. I don't agree with the GP that this is an example of overengineering. If anything it's an example of current Rust being slightly underengineered. Presumably a lot of these temporary types can be killed off once `impl Trait` goes mainstream?

It's a datatype, but it's an implementation detail - str::split_whitespace has to return something that implements the Iterator trait, so it return this. You as a programmer should never need to name it explicitly.

When "impl Trait" lands, it will be possible to hide details like this.

Re: Announcing Rust 1.24.1

#37
post #35
post #22

Earlier quoted context omitted.

The better half of those points are directly and indirectly caused by insistence on manual memory management. Yes, it was a major design point of Rust, but it doesn't make it better engineered than "most other languages". It's just the corner it painted itself to.

Rust doesn't have manual memory management. It does have deterministic memory management as opposed to garbage collected language. Which means you can use it it in domains where garbage collected languages cannot be used - e.g. for a OS ...or for implementing a garbage collector.

You absolutely can implement an OS or a garbage collector in a GC-enabled language.

Re: Announcing Rust 1.24.1

#38
post #31

Earlier quoted context omitted.

> Why would you create a special data type to represent a string split by Whitespace? Lunacy Because it's an iterator. A bespoke iterator type is also created behind the scenes in many other languages. How else would you do it?

> How else would you do it? There is a `splitWhitespace` iterator[1] in the Nim programming language as well and doesn't require a separate type. In Nim, the iterator is inlined. 1 - https://nim-lang.org/docs/strutils.html#splitWhitespace.i,st...

It's inlined in rust, too

Re: Announcing Rust 1.24.1

#39

Rust gives me a headache. I want to like it, but it just seems so... overengineered https://doc.rust-lang.org/std/str/struct.SplitWhitespace.htm... Why would you create a special data type to represent a string split by Whitespace? Lunacy

It depends on what software world you come from. In many places "stringly typed" code is frowned upon: http://wiki.c2.com/?StringlyTyped

Yes, it's convenient, but using data types can help with many things, from implicit documentation, to optimizations to enforcing a code contract/interface.

Re: Announcing Rust 1.24.1

#40
post #28
post #26

Earlier quoted context omitted.

Firstly, manual memory management is what happens when a C programmer must manually place malloc/free calls within her program. Rust doesn't require any of that; the compiler determines the right times to allocate and free memory, while requiring the programmer to follow certain design rules in exchange for the convenience. Second, you're making it sound as if the position Rust (and those who program in it) is someho…

Interesting; I certainly wouldn't consider C++ constructor/destructor like semantics and manual tracking of object ownership in the code as automatic memory management. But regardless, the point stands. And yes it's a consequence of a design goal, I said as much. The outcome however isn't beautiful enough to feel smug about the rest of programming languages.

Rust doesn't have C++ constructor/destructor semantics. It doesn't require manual tracking of object ownership. You just have to say when you're passing ownership and when you aren't, and the compiler takes care of the rest.

It's automatic memory management without runtime accounting or a garbage collector, which means Rust doesn't need a runtime at all.

Post reply on HN