News for hackers. Stuff that matters.
Re:C/C++ vs. Rust Performance by simias on Sunday November 01, 2020 @01:37PM (#24961441)
>The Rust's generics and macros are much weaker than provided by C++ templates coupled with C macros. Although, this is also not so crucial.

That's a very strange way to put it IMO, I'm not sure what is meant by "weaker" here. They are stricter and as such can require more work to use effectively, but weaker is a weird way to put it.

Re:C/C++ vs. Rust Performance by Karliss on Sunday November 01, 2020 @02:43PM (#24961932)
C++ template provides features that rust generics don't. I am not a Rust developer so correct me of some of these have been recently added. Rust generics being stricter would be something like them allowing to use only methods provided by trait, but I would call all of following design limitations making rust generics weaker.

* passing integer as template argument - from what I understand some of rust standard library functions can't handle arrays with more than 64 or 32 elements due to this or something similar. And there is active work for adding const generics to rust.

* variadic templates - there is a RFC for this

* passing template as template argument

* template specialization - C++ is somewhat moving away from this

Re:C/C++ vs. Rust Performance by steveklabnik on Sunday November 01, 2020 @02:51PM (#24961976)
The first point has had its restriction lifted as of the current version of Rust, 1.47.0. Or rather, the standard library and arrays bit is fixed; the underlying feature is not in stable Rust, and so other libraries still can't make this work properly yet.

Variadrics are desired by some folks, but aren't a particularly high priority.

Template template parameters are unlikely to land directly in Rust; GATs will be roughly equivalent. And specialization has a nightly implementation, and is highly desired, but isn't done yet.

Re:C/C++ vs. Rust Performance by fluffy87 on Sunday November 01, 2020 @02:58PM (#24962028)
C++ templates are „untyped“ or very „weakly“ typed at the kindest, while Rust generics are „strongly“ typed.

That’s the main difference in these languages features.

Saying that Rust generics are „weaker“ than C++ templates is technically incorrect, since they are actuall „stronger“.

Using these terms to mean something else is definitely „weird“.

Re:C/C++ vs. Rust Performance by yokaze on Sunday November 01, 2020 @03:59PM (#24962460)
> C++ templates are „untyped“ or very „weakly“ typed at the kindest, while Rust generics are „strongly“ typed.

Can you provide your definition of strongly typed?

According to my understanding, C++ templates are evaluated at compile time, and the resulting instance has to qualify all the static type checks of standard C++. The deduced types is always checked, and if there is no substitution fullfill the type check is found, it raises a compile error.

The errors are super ugly, as there are no type constraints for template parameters, but funnily enough the template errors in C++ reminded me of playing around with Haskell without using function declarations. I would find it odd to call Haskell though untyped or weakly typed because of that.

Re:C/C++ vs. Rust Performance by lifthrasiir on Sunday November 01, 2020 @04:13PM (#24962550)
It should be said that C++ templates are dynamically typed (not weakly) and Rust generics are statically typed. But otherwise it is correct that Rust generics give a stronger guarantee than C++ templates.

It is beneficial to view C++ as a two-stage programming language, where the first stage runs templates and emits instances and the second stage runs them in the actual target. When C++ templates are said to be "untyped", that's really about the first stage [1]. You can't be very sure that templates act as intended for all valid inputs because it can't statically determine types before the first stage. Of course you can still write almost-working templates.

[1] Specifically the template invocation. C++ templates do have types for compile-time expressions and for that reason it was a wise move to move most of them into constexpr functions.

Re:C/C++ vs. Rust Performance by gpderetta on Monday November 02, 2020 @06:49AM (#24967046)
then again, the strongly and weakly typed monikers have no defined meaning and people will argue endlessly about definitions to the point that have very little value.

edit: the static/dynamic distinction pointed out elsethread is a much better description.

Re:C/C++ vs. Rust Performance by kupopuffs on Sunday November 01, 2020 @03:19PM (#24962155)
In terms of ease of expression and using mental power, C++ templates may be a more powerful tool for some.

Like you're describing the type system, they may be talking about actual effectiveness.

Like productivity diff between python and others

Basically, I'm not smart enuf to use rust

Re:C/C++ vs. Rust Performance by TheDong on Sunday November 01, 2020 @03:38PM (#24962306)
If they meant "A more powerful tool", the right way to express that is "more powerful", not "weaker/stronger".

However, if you look at that part of the article, they justify that statement by linking to this post [0] which is explicitly about how rust actually type-checks generics more strongly. The linked post has the opposite implication of what the author took it to mean, and that link makes it clear that they were referring explicitly to how they're typed, not to "actual effectiveness".

[0]: https://users.rust-lang.org/t/generic-functions-c-vs-rust/21...

Re:C/C++ vs. Rust Performance by klyrs on Sunday November 01, 2020 @04:26PM (#24962640)
> template specialization - C++ is somewhat moving away from this

Uh oh... I love template specialization... what replaces this?

Re:C/C++ vs. Rust Performance by Karliss on Tuesday November 03, 2020 @11:36AM (#24981169)
Some of the cases can now more easily be handled using costexpr if.
Re:C/C++ vs. Rust Performance by steveklabnik on Sunday November 01, 2020 @01:47PM (#24961506)
I think that the way they mean is that there are less restrictions, which means you can do more with them, which makes them more powerful, in a sense.

Words are hard.

Re:C/C++ vs. Rust Performance by wtetzner on Sunday November 01, 2020 @01:42PM (#24961483)
I would say Rust macros are considerably stronger, given it supports procedural macros.
Re:C/C++ vs. Rust Performance by ashtonkem on Sunday November 01, 2020 @07:44PM (#24963907)
This is part of why I think we should begin to move away from “weaker” and “stronger” as adjectives for programming; these terms add a value judgement that is not properly reflective of the more nuanced trade offs involved.