Earlier quoted context omitted.
Now there is also std::from_chars function
std::from_chars will still accept "123abc". You have to manually check if all parts of the string have been consumed. On the other hand, " 123" is not accepted, because it starts with an invalid character, so the behaviour isn't "take the first acceptable number and parse that" either. To get the equivalent of Rust's if let Ok(x) = input.parse:: () { println!("You entered {x}"); } else { eprintln!("You did not enter…
Matt Godbolt sold me on Rust by showing me C++
421–430 of 675 posts
Re: Matt Godbolt sold me on Rust by showing me C++
#422Earlier quoted context omitted.
That is easy to say today, but I guarantee in 30 year Rust will have rough edges too. People always want some new feature and eventually one comes in that cannot be accommodated nicely. Of course it will probably not be as bad as C++, but still it will be complex and people will be looking for a simpler language.
How many rough edges will C++ have in another 30 years?
There will always remain two types of languages: those that nobody uses and those that everybody complains about.
Re: Matt Godbolt sold me on Rust by showing me C++
#423Earlier quoted context omitted.
Result type still requires quite a few lines of boilerplate if one needs to add custom data to it. And as a replacement of exceptions with automatic stack trace attachment it is relatively poor. In any case I will take Rust Result over C++ mess at any time especially given that we have two C++, one with exception support and one without making code incompatible between two.
FWIW, stack traces are part of C++ now and you can construct custom error types that automagically attach them if desired. Result types largely already exist in recent C++ editions if you want them. I use completely custom error handling stacks in C++ and they are quite slick these days, thanks to improvements in the language.
With Rust Result and powerful macros it easier to implement.
Re: Matt Godbolt sold me on Rust by showing me C++
#424Earlier quoted context omitted.
That is easy to say today, but I guarantee in 30 year Rust will have rough edges too. People always want some new feature and eventually one comes in that cannot be accommodated nicely. Of course it will probably not be as bad as C++, but still it will be complex and people will be looking for a simpler language.
Rust has rough edges today. The field of programming is still only a few decades old, and there's no doubt that something even shinier will come along, we just don't know yet what that looks like. That's not a good reason to stick with inferior tools now, though.
Rust is inferior to C++ for my needs. This is just a reflection on we started a large project in C++ before rust existed, and now have millions of lines. Getting Rust to work with our existing C++ is hard enough as to not be worth it. Rewriting in Rust would cost 1 billion dollars. Thus despite all the problems we have with C++ that Rust would solve, rust is inferior.
(Rust is working on their C++ interoperability story and we are making changes that will allow using Rust in the future so I reserve the right to change this story in a few years, but only time will tell)
Re: Matt Godbolt sold me on Rust by showing me C++
#425Earlier quoted context omitted.
Sure, but it is pragmatic in other ways as well :) It takes ADT, but not function currying, and so on.
I don't think currying is that big a deal, it's just syntactic sugar that might or might not make things easier to read, unlike ADTs or closures which are important core concepts. I'd love to have a syntax like { foo(%1, bar) } standing for |x| { foo(x, bar) } though. I'm not aware of any language that has this!
Re: Matt Godbolt sold me on Rust by showing me C++
#426Earlier quoted context omitted.
C++ editions are -std=something, people keep forgeting Rust editions are quite limited in what they actually allow in grammar and semantic changes across versions, and they don't cover standard library changes. IDEs are wonderful tooling, maybe people should get their heads outside UNIX CLIs and MS-DOS like TUIs. Then there is the whole ecosystem of libraries, books, SDKs and industry standards.
I'm not sure who in your mind is forgetting that, or what the rest of your comment means to communicate. Who are you speaking to who hasn't explored all those things in depth? I see Rust's restrictions as a huge advantage over C++ here. Even with respect to editions. Rust has always given me the impression of a language designed from the start to be approximately what C++ is today, without the cruft, in which safety…
I agree that Rust is designed to be like C++ is today, without the cruft, except all languages if they survive long enough in the market, beyond the adoption curve, they will eventually get their own cruft.
Not realizing this, will only make that 30 years from now, if current languages haven't yet been fully replaced by AI based tools, there will be that language designed to be like Rust is in 30 years, but without the cruft.
The strength of C++ code today is on the ecosystem, that is why we reach for it, having to write CUDA, DirectX, maybe dive into the innards of Java, CLR, V8, GCC, LLVM, doing HPC with OpenAAC, OpenMP, MPI, Metal, Unreal, Godot, Unity.
Likewise I don't reach for C for fun, the less the merrier, rather POSIX, OpenGL, Vulkan,....
Re: Matt Godbolt sold me on Rust by showing me C++
#427Earlier quoted context omitted.
Sure, but it is pragmatic in other ways as well :) It takes ADT, but not function currying, and so on.
I don't think currying is that big a deal, it's just syntactic sugar that might or might not make things easier to read, unlike ADTs or closures which are important core concepts. I'd love to have a syntax like { foo(%1, bar) } standing for |x| { foo(x, bar) } though. I'm not aware of any language that has this!
In[1]: Map((1 + #1)&, {a, b, c})
Out[1]: {a + 1, b + 1, c + 1}
See https://reference.wolfram.com/language/ref/Function.html.en for the full story.Re: Matt Godbolt sold me on Rust by showing me C++
#428Earlier quoted context omitted.
This seems like such an obvious thing to have - where is it? Zig, Odin, etc. all seem much more ambitious.
There have been attempts over the years. See here, a decade ago: https://blog.regehr.org/archives/1287 > eventually I came to the depressing conclusion that there’s no way to get a group of C experts — even if they are knowledgable, intelligent, and otherwise reasonable — to agree on the Friendly C dialect. There are just too many variations, each with its own set of performance tradeoffs, for consensus to be possibl…
Re: Matt Godbolt sold me on Rust by showing me C++
#429Earlier quoted context omitted.
> I just almost never have problems with this sort accidental conversion in practice. 95% of C++ programmers claim this, but C++ programs continue to be full of bugs, and they're usually exactly this kind of dumb bug. > will be noticed by literally just running the code once. Maybe. If what you're doing is "tricky mathematical algorithms", how would you even know if you were making these mistakes and not noticing the…
It’s the sociology of software development. The guild of software developers has no real standards, no certification, no proven practices outside and while continuing to depend on the whims of project managers, POs and so-caled technical leaders and others which can’t tell quality code from their own ass. There’s usually no money in writing high-quality software and almost everything in a software development project…
Re: Matt Godbolt sold me on Rust by showing me C++
#430Earlier quoted context omitted.
Assertions are debug-only. Exceptions are usually not guaranteed to be available and much of the standard library doesn't require them. You could std::abort, and that's about it. I think the issue is that this just isn't particularly good either. If you do that, then you can't catch it like an exception, but you also can't statically verify that it won't happen. C++ needs less of both undefined behavior and runtime e…
I agree these things would be better, but I don’t understand how anyone can think UB is better than abort. (Going to moan for a bit, and I realise you aren’t responsible for the C++ standards mess!) I have been hearing for about… 20 years now that UB gives compilers and tools the freedom to produce any error catching they like, but all it seems to have done in the main is give them the freedom to produce hard to debu…
I don’t think people want that as standard. The whole point of using C++ tends to be because you can do whatever you need to for the sake of performance. The language is also heavily driven by firms that need extreme performance (because otherwise why not use a higher level language)
There are knobs like stdlib assertions and ubsan, but that’s opt-in because there’s a cost to it. Part of it is also the commitment to backwards compatibility and code that compiled before should generally compile now (though there are exceptions to that unofficial rule).