News for hackers. Stuff that matters.
Re:Rust: Systems Programming for Everyone by blub on Saturday August 20, 2016 @08:58AM (#12326354)
Rust is significantly more complex than C and more complex than C++.

It seems to be a multi-paradigm language like C++. I guess it's advertised for system programming because it's looking for its niche, but I don't see it replacing C for low level stuff due to the learning curve.

Re:Rust: Systems Programming for Everyone by nercury on Saturday August 20, 2016 @09:52AM (#12326597)
I guess Rust may seem more complex, if you know C++ well, but from the side it may not seem like it.

For example, C++ Core Guidelines [0] is longer than Rust Book. Core Guidelines is itself a great example of things one needs to keep in the head while writing C++ code.

Look at implementation of something as basic as optional<T> [1]. The amount of things one needs to know is so high most C++ developers would never attempt it.

[0]: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppC...

[1]: https://github.com/akrzemi1/Optional/blob/master/optional.hp...

Re:Rust: Systems Programming for Everyone by soulbadguy on Saturday August 20, 2016 @11:01AM (#12326882)
Using the size difference between the C++ code Guidelines and the Rust Book as measure of relative complexity seems misguided to me : Those two very different document, with very different purpose and target audience.
Re:Rust: Systems Programming for Everyone by girvo on Saturday August 20, 2016 @10:05AM (#12326653)
Which is interesting, because I implemented Optional<T> (well, Maybe<T>) in Nim v0.14 in 20 lines of code in a single evening, to see how difficult it would be!
Re:Rust: Systems Programming for Everyone by gpderetta on Saturday August 20, 2016 @11:29AM (#12326988)
The reason for the complexity of that implementation are compiler bugs/nonconfromance workarounds, a fully constexpr implementation and attempt to match a standard spec.
Re:Rust: Systems Programming for Everyone by girvo on Monday August 22, 2016 @10:09PM (#12340888)
> a fully constexpr implementation

That's actually simpler to do in Nim than you'd think, but I understand what you mean. I might expand my implementation to be const and see how complex it makes it!

Re:Rust: Systems Programming for Everyone by dbaupp on Saturday August 20, 2016 @12:18PM (#12327191)
I feel like this is taking a very rosy-eyed view of C++.

C++ has a massive amount of accidental complexity. To mention just two: the difference between () and {} initialisation (for some types) especially in the presence of perfect forwarding, and a set of feature/their interactions that means there's a bug in the following very reasonable looking code (can you find it?):

  std::unordered_map<T, U> map;
  // ... initialize map ...

  const U *selected = nullptr;
  for (const std::pair<T, U>& p : map) { 
    if (condition) { selected = &p.second; } 
  }
  // use selected
(Credit to Effective Modern C++.)

Rust may seem more complex because the compiler is noisier, but it is significantly simpler to write correctly: a computer is finding the weirdest bugs.

Re:Rust: Systems Programming for Everyone by blub on Monday August 22, 2016 @04:30AM (#12334871)
That's not the point I am making. I am arguing that it's more difficult to go from idea to code in Rust because there are more programming concepts that one has to keep in mind. Additionally, the syntax is not user friendly.

You are right regarding the C++ accidental complexity though. Issues like the one you highlighted tend to happen when working with pointers. They are very hard to detect during code review (I didn't see it), but I would have rejected the code at review anyway because it should be replaced by std::find. Taking raw pointers into containers is also not reasonable except for vector.

Re:Rust: Systems Programming for Everyone by dbaupp on Thursday August 25, 2016 @07:02PM (#12363158)
I disagree that there's more programming concepts to keep in mind: the core ideas between Rust and C++ are the same (especially modern C++ with move semantics), but in C++ you literally have to keep thinking about them or your program is wrong, while Rust has the compiler checking them for you.

> I would have rejected the code at review anyway because it should be replaced by std::find

That specific example, sure, but there's other ways to have escaping pointers in for loops.

> Taking raw pointers into containers is also not reasonable except for vector.

The map types are explicitly designed to allow taking pointers, e.g.

> References and pointers to either key or data stored in the container are only invalidated by erasing that element, even when the corresponding iterator is invalidated. -- http://en.cppreference.com/w/cpp/container/unordered_map

Re:Rust: Systems Programming for Everyone by blub on Thursday September 01, 2016 @03:39AM (#12403632)
I am not so sure, I've seen examples of Rust code where I had no idea what was going on, the syntax is heavy (e.g. sigils), it's encouraging functional idioms and introduces several concepts in addition to C++ besides ownership. I don't have time to list them, anyone can find what they are.

How many C or C++ programmers will understand this: (1..n + 1).fold(1, |accum, x| accum * x)?

Anyway, I am just offering my opinion as someone doing mostly C++ programming. I have no problem with a language like Swift or Go, but feel that Rust is too complicated for what it offers.

Taking a pointer into containers refers to &p.second. We now have a pointer to an iterator's member variable. That is unreasonable.

The reasonable thing would be to use an interator to keep track of the selected item, this is what they are designed for.

Re:Rust: Systems Programming for Everyone by soulbadguy on Saturday August 20, 2016 @12:43PM (#12327276)
What's the bug ? (hopefully it's not just a missing break statement.
Re:Rust: Systems Programming for Everyone by RcouF1uZ4gsC on Saturday August 20, 2016 @01:17PM (#12327441)
The problem is that the pair in the for loop should have a const T as the first parameter. Because it does not have that, you are actually getting a temporary back and storing a pointer to a temporary in selected.

The fix to avoid this is to use auto. If instead of pair, you used auto&& p: map, this would not be an issue

Re:Rust: Systems Programming for Everyone by steveklabnik on Saturday August 20, 2016 @11:39AM (#12327031)
How do you measure complexity?
Re:Rust: Systems Programming for Everyone by blub on Monday August 22, 2016 @04:51AM (#12334933)
I measured it by looking at posted Rust code/projects on HN an relating that to what I know about C and C++.
Re:Rust: Systems Programming for Everyone by steveklabnik on Monday August 22, 2016 @12:45PM (#12337568)
That doesn't say _how_ you measure it when you look at the code.