[OT] - C++ exceptions are becoming more and more problematic

meta meta at gmail.com
Wed Mar 2 09:02:33 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++".

That's indeed a nice way to represent nullable/optional, I 
personally prefer calling such feature as "optional", null is 
already a thing when playing with pointers, that'd cause 
confusion to call it nullable imo


More information about the Digitalmars-d mailing list