[OT] - C++ exceptions are becoming more and more problematic
bauss
jj_1337 at live.dk
Wed Mar 2 07:04:22 UTC 2022
On Wednesday, 2 March 2022 at 00:03:48 UTC, IGotD- wrote:
> On Thursday, 24 February 2022 at 19:14:39 UTC, Walter Bright
> wrote:
>>
>> I agree, which makes this a challenge.
>>
>> One solution is to design the return value so that failure is
>> a valid part of the type. For example, searching for X can
>> return an empty result, rather than a special "not found"
>> error.
>>
>> Another solution is to redesign the problem. For example,
>> currently Phobos throws on an invalid Unicode character. A
>> better way is to treat such as a "replacement character".
>
> Since you want to go that route and it might be applicable and
> convenient for some interfaces, you should consider adding a
> nullable type i D, and a language native nullable not only a
> library template type. You cannot find a "magic value" for all
> interfaces and a nullable type would solve that.
>
> I would like that D outright copies the C# syntax for the
> nullable type (because I like it). The '?' makes it easy to
> implement and encourage people to use it.
>
> https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/nullable-value-types
>
> D has so many similarities with C# by now, adding a C# nullable
> syntax wouldn't hurt. D could even win over some C# people when
> they need compiled code or for whatever reason. When they see
> that D looks almost like C#, they rather stick with D than
> "modern C++".
Yeah, I got to D from C#, granted it was like a decade ago, so C#
was still missing a lot of the modern features like built-in
tuples, method shortened syntax, async/await was barely a thing
(I believe it was started to be introduced.) and so on. However I
still program in C# and once in a while there are some features I
miss when I go back to D, it used to be the other way around.
More information about the Digitalmars-d
mailing list