nothrow by default

SealabJaster sealabjaster at gmail.com
Thu Jan 9 16:59:31 UTC 2020


On Thursday, 9 January 2020 at 06:26:41 UTC, Walter Bright wrote:
> I expect that exceptions will soon become a legacy feature.

Honestly, to me this sounds like "I don't like/use exceptions 
therefore get rid of them (not as a feature, but just stop using 
it anywhere or make them too annoying to bother with)", which is 
understandable since you mostly seem to work on projects that 
require high-performance (like DMD), but not every project is 
unable to afford the overhead of exceptions.

In terms of making `nothrow` the default, I dread to think of how 
annoying it'd be for a commonly used function in a codebase to 
not be `nothrow`, then having to throw in the `throw` keyword 
into the ever-growing attribute soup for any function that calls 
it. While at the moment if a function is `nothrow`, then it's 
optional for a caller to be `nothrow` so it doesn't stick in my 
face as much.

I guess the same argument could be applied to @safe by default, 
but having to deal with an `@system` function is likely much 
rarer and confined than having to deal with a more widely used 
`throw` function, making it more manageable, while `@safe` also 
provide heavy benefits outside of just "performance".

I fear this will also discourage the use of exceptions, and push 
people to overuse error codes which don't have any standard 
pattern; aren't able to provide additional info beyond the actual 
error itself (e.g. can't provide certain info or values that 
caused the error); require the caller to produce any error 
messages (which might mean functions specifically designed for 
other functions' error codes); and more annoyingly either a type 
that returns both value and error (which isn't too bad, but a bit 
annoying), or requires the caller to pass an out/ref parameter(s) 
in case of an error (again, very annoying to deal with).

I don't know. It just feels like this proposal will add more 
friction with using D in the general case, as a compromise for 
giving extra performance in the niche case.

I'm a bit of a dimwit, so apologies if I've misunderstood how 
this'd end up working, but my current view is that it'd make my 
own experience with D more painful for unequal amount of benefit.


More information about the Digitalmars-d mailing list