February 26, 2022
On Friday, 25 February 2022 at 21:03:21 UTC, forkit wrote:
>
> The 'real' motivation is simple -> an increased awareness of the benefits of Rust within the C++ community.

It seems to be some kind false narrative that Rust is savior of all and will create a new world. The more I learn Rust, the more I realize that's not the case.

If you look at Rust error handling (the proposed std::Result) it is less powerful than exceptions in D (or C++, C# and several others). D can even handle multiple exceptions, even if that is seldom used. Basically you can catch any exception up the call chain and polymorphism really makes this possible. It is easy to add new exceptions as well as reusing existing ones thanks to this.

If you look at Rust Result<T, E>, it is basically a wrapped return value and the type in E must be known to the caller so cannot easily pass it up the chain. Type E can be anything but adding your own error types becomes cumbersome. Rust might also provide an Error trait (Rust way of structs with virtual methods) which is more generic so that you can add your own custom error type. However, this Error trait is in general allocated on the heap so not even Rust is immune to heap allocated error handling.

For simpler error handling Result<T, E> is a better match as E is in general an immutable string, an integer or nothing.



February 26, 2022
On Saturday, 26 February 2022 at 20:59:53 UTC, IGotD- wrote:
> On Friday, 25 February 2022 at 21:03:21 UTC, forkit wrote:
>> [...]
>
> It seems to be some kind false narrative that Rust is savior of all and will create a new world. The more I learn Rust, the more I realize that's not the case.
>
> [...]

Case in point,

https://nnethercote.github.io/2022/02/25/how-to-speed-up-the-rust-compiler-in-2022.html

>  Decoder trait used for metadata decoding was fallible, using Result throughout. But decoding failures should only happen if something highly unexpected happens (e.g. metadata is corrupted) and on failure the calling code would just abort. This PR changed Decoder to be infallible throughout—panicking immediately instead of panicking slightly later—thus avoiding lots of pointless Result propagation, for wins across many benchmarks of up to 2%.

Beware of always copying other language designs.
February 26, 2022

On Saturday, 26 February 2022 at 20:47:27 UTC, forkit wrote:

>

On Saturday, 26 February 2022 at 13:48:52 UTC, Ola Fosheim Grøstad wrote:

>

Maybe, but how many committed C++ programmers have switched to Rust?

so you don't compete in the market, by waiting till your competitor has taken your customers ;-)

Or you don't fall into the trap of trying to be everything for everybody and ending up with a design that doesn't satisfy anyone.

>

D seems to becoming more of a development environment for C code.

Seriously. If I want C, I can just use C.

Yes, that does not work. The only thing C has going for it is critical mass. Nobody can compete with C, as the selling point of C is its history. So, that would be a loose-loose strategy.

>

So just where D is going to stand out (in relation to it's competitors) in this new world of 'more secure code', is not at all clear to me, and it's vision is even more obscure to me.

The vision has not been elaborated in way that is meaningful, I agree.

In my view the vision ought to be to switch to local GC for non-shared and ARC for shared objects, and gear the eco system towards an actor model that make good use of a wide range of CPU configurations (e.g. run equally well on 2 cores, 32 cores, and so on). But that is not the current vision, that is just what I personally think would make sense for the current user base.

>

This would be sign of impending doom for C++. i.e. It also needs to focus heavily on competing for new customers, now that many people and corporations see Rust as serious contender.

I don't think so. C++ can afford to loose some customers in some application domains and strengthen its positions in areas where it is most suitable. Changing the core language would be a mistake for C++ because it has critical mass, way more so than any other competitor.

That "critical mass" is the key issue, so what is good for C++ does not translate to other languages.

February 26, 2022
On Sat, Feb 26, 2022 at 08:59:53PM +0000, IGotD- via Digitalmars-d wrote: [...]
> It seems to be some kind false narrative that Rust is savior of all and will create a new world. The more I learn Rust, the more I realize that's not the case.

Exactly.  The Rust hype these days are reminiscient of the Java hype back in the 90's.  Java was touted as the be-all and end-all of programming that will solve all of your programming problems and present none of its own. Well, 30 years later we have learned some good things from Java, but we have also realized its shortcomings, and that it's really NOT what it was originally hyped to be.


> If you look at Rust error handling (the proposed std::Result) it is
> less powerful than exceptions in D (or C++, C# and several others).
[...]
> If you look at Rust Result<T, E>, it is basically a wrapped return value and the type in E must be known to the caller so cannot easily pass it up the chain. Type E can be anything but adding your own error types becomes cumbersome.
[...]

Thanks, that's exactly what I've been trying to say, except you said it better. :-D

Error handling using sum types, etc., are at the core just a cosmetic makeover of C's return codes.  It puts the onus on the caller to check for every return code and take appropriate action. AND it's not easily propagated up the call chain, because the error type E returned by func1 may not be the same type E returned by its caller, so you cannot simply pass it along; you *have* to manually map it to your own error return type.

In theory, your own error return type would be a sum type of all error returns of the functions you call plus your own error codes. In practice, I honestly doubt if anyone would bother doing this; I expect the tendency would be to simply map every error from dependent functions to the equivalent of INTERNAL_ERROR, i.e., a generic, non-descript, unhelpful code that tells the caller nothing about what the actual error is.

Basically, it would be identical to how you use error codes in C, except dressed in prettier syntax.  The fundamental problems with C error code handling remain unchanged.

For example, it does not address the issue that often, the information required to decide how to handle an error is not readily available in the caller, but can only be found higher up the call chain. The Rust way is just glorified C return codes that doesn't solve this problem in any way.


T

-- 
People demand freedom of speech to make up for the freedom of thought which they avoid. -- Soren Aabye Kierkegaard (1813-1855)
February 27, 2022
On Saturday, 26 February 2022 at 23:00:24 UTC, Ola Fosheim Grøstad wrote:
>
> That "critical mass" is the key issue, so what is good for C++ does not translate to other languages.

c++'s critical mass is more of happy accident, than anything (i.e. there were no serious contenders for that same market at the time, or for a very long time since).

Same is true for C.

Same is true for Java.

Then C# came along...

There are plenty eager to see a better c++.

I personally do not think Rust is that alternative. Why? Because they used computer science alone to create a new language for 'modern times'.

Instead, they should have combined computer science with psychological science, and they would have come up with a better syntax that is less cognitively challenging (something C++ is working hard towards.. well..in part).

February 27, 2022

On Saturday, 26 February 2022 at 23:56:31 UTC, H. S. Teoh wrote:

>

In theory, your own error return type would be a sum type of all error returns of the functions you call plus your own error codes. In practice, I honestly doubt if anyone would bother doing this

I tried to help alleviate this pain by creating a template that pipes a given sequence of functions, consolidating all possible types into a new result type.

// Very contrived example
//          int, Outcome!(int, IsNegativeError), Outcome!(int, IsOddError)
chain!(() => -1,                     isPositive, isEven)()
    .handle!(
        num => text(num, " is an even, positive integer"),
        (IsNegativeError err) => text(err.num, " is a negative integer"),
        (IsOddError err) => text(err.num, " is an odd integer")
    ) // Outcome!(int, IsNegativeError, IsOddError)
    .writeln; // -1 is a negative integer
February 27, 2022
On Sunday, 27 February 2022 at 04:57:28 UTC, __StarCanopy wrote:
>     ) // Outcome!(int, IsNegativeError, IsOddError)

My apologies, the places of IsOddError and IsNegativeError should be reversed.
February 27, 2022

On Sunday, 27 February 2022 at 01:29:58 UTC, forkit wrote:

>

Instead, they should have combined computer science with psychological science, and they would have come up with a better syntax that is less cognitively challenging (something C++ is working hard towards.. well..in part).

Yes, they have looked at bloat and come up with simple solutions that work well, such as replacing "function objects" with lambdas.

However, usability in 2022 means IDE-friendly. C++ and D are not particularly friendly to people creating advanced IDEs.

C++ will probably be replaced with a language that allows new and better ways to express programming ideas in the form of IDEs (with graphical modelling support etc). Let's hope it is something far better than the current challengers.

February 27, 2022

On Sunday, 27 February 2022 at 08:07:01 UTC, Ola Fosheim Grøstad wrote:

>

On Sunday, 27 February 2022 at 01:29:58 UTC, forkit wrote:

>

Instead, they should have combined computer science with psychological science, and they would have come up with a better syntax that is less cognitively challenging (something C++ is working hard towards.. well..in part).

Yes, they have looked at bloat and come up with simple solutions that work well, such as replacing "function objects" with lambdas.

However, usability in 2022 means IDE-friendly. C++ and D are not particularly friendly to people creating advanced IDEs.

C++ will probably be replaced with a language that allows new and better ways to express programming ideas in the form of IDEs (with graphical modelling support etc). Let's hope it is something far better than the current challengers.

Qt, Clion and Visual Studio are doing just fine for C++, by adopting the ideas that were already being explored a couple of decades ago, via language servers.

In fact, during the early 90's two companies companies already went down this path, Lucid and IBM.

Lucid with Energize (1993 Demo: https://www.youtube.com/watch?v=pQQTScuApWk), using a DB for the C++ AST (https://dreamsongs.com/Cadillac.html).

IBM with the release of Visual Age for C++ v4.0, which used a Smalltalk like image for C++ code, http://www.edm2.com/index.php/VisualAge_C%2B%2B_4.0_Review

Both failed in the market, because they required quite expensive workstations to be usable, however their requirements are a joke now when compared with what most people phones are running.

So naturally, all major C++ IDEs are now adding back those features.

Visual Studio 2022 allows me to use C++ almost like .NET, easily hot reloading modified code, and it isn't the only C++ environment offering such kind of goodies.

https://www.youtube.com/watch?v=x_gr6DNrJuM

https://liveplusplus.tech/

By the way, NVidia now has a A Team collection of C++ people, it is quite clear that C++ has won the wars of programming GPU hardware and SYSCL will cement the same for FPGA design.

February 27, 2022
On Sunday, 27 February 2022 at 01:29:58 UTC, forkit wrote:
> On Saturday, 26 February 2022 at 23:00:24 UTC, Ola Fosheim Grøstad wrote:
>>
>> That "critical mass" is the key issue, so what is good for C++ does not translate to other languages.
>
> c++'s critical mass is more of happy accident, than anything (i.e. there were no serious contenders for that same market at the time, or for a very long time since).
>
> Same is true for C.
>
> Same is true for Java.
>
> Then C# came along...
>
> There are plenty eager to see a better c++.
>
> I personally do not think Rust is that alternative. Why? Because they used computer science alone to create a new language for 'modern times'.
>
> Instead, they should have combined computer science with psychological science, and they would have come up with a better syntax that is less cognitively challenging (something C++ is working hard towards.. well..in part).

Why do I still bother with C++, when my work languages are Java and .NET languages?

While they stole C++'s thunder on GUI and distributed computing, their runtimes, or native bindings to the host platforms, or GPGPU programming bindings, require dealing with C++ in one way or the other.

Using D instead, would be great, but in those scenarios it would be adding just another layer to debug between the work that has to be delivered in Java/.NET anyway, and the SDKs that are C++ only, so why bother.

Same applies to any language pretending to take away C++'s throne in such domains.

What D needs is focus on being great at a specific domain, as most IT departments pick languages based on platforms, not the other way around.