|
|
Subscribe / Log in / New account

Recent improvements in GCC diagnostics

Recent improvements in GCC diagnostics

Posted Oct 15, 2023 11:03 UTC (Sun) by dvdeug (guest, #10998)
In reply to: Recent improvements in GCC diagnostics by khim
Parent article: Recent improvements in GCC diagnostics

>Just, please, don't compare generics in Rust with C++ templates. They may be similar syntactically, but on semantic level C++ templates have to be compared with Rust's proc macro system, not with generics.

That's like saying 2+2 in Python is equivalent to BigInteger(2).plus(BigInteger(2)) in Java. I mean, in some sense it is (actually, something more powerful), but 99% of the time you don't need more than 2+2 in Java. Rust generics are designed to cover most of the cases that C++ templates are; if you're talking about those cases, templates and generics are the right comparison.


to post comments

Recent improvements in GCC diagnostics

Posted Oct 15, 2023 14:08 UTC (Sun) by khim (subscriber, #9252) [Link]

> Rust generics are designed to cover most of the cases that C++ templates are; if you're talking about those cases, templates and generics are the right comparison.

The problem is that “crazy and impenetrable error messages” that C++ is so famous for are not from these cases. And they can be covered by concepts just fine.

It's heavy and convoluted TMP that is intrinsically linked with these. Where you can use std::is_same_v, std::enable_if_t, if constexpr and other such things. And Rust generics are completely unsuitable for these usecases, only macros can do that something similar.

> That's like saying 2+2 in Python is equivalent to BigInteger(2).plus(BigInteger(2)) in Java. I mean, in some sense it is (actually, something more powerful), but 99% of the time you don't need more than 2+2 in Java.

Very good example. Yes, 99% of time you don't care about limitations of Java integers. But when you start, specifically, talking about how convoluted and awkward syntax of Java is for user-defined types then the fact that you can use overloaded operators to mix integers with bignums and user-defined types is Python, but not in Java that difference becomes important.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds