DIP 1029---Add throw as Function Attribute---Community Review Round 1

WebFreak001 d.forum at webfreak.org
Tue Jan 14 11:21:05 UTC 2020

On Tuesday, 14 January 2020 at 10:44:17 UTC, Mike Parker wrote:
> This is the feedback thread for the first round of Community 
> Review for DIP 1029, "Add throw as Function Attribute":
> https://github.com/dlang/DIPs/blob/8c48c98a0495f73db9a2d5c4aef502b9febe9673/DIPs/DIP1029.md
> All review-related feedback on and discussion of the DIP should 
> occur in this thread. The review period will end at 11:59 PM ET 
> on January 28, or when I make a post declaring it complete.
> At the end of Round 1, if further review is deemed necessary, 
> the DIP will be scheduled for another round of Community 
> Review. Otherwise, it will be queued for the Final Review and 
> Formal Assessment.
> Anyone intending to post feedback in this thread is expected to 
> be familiar with the reviewer guidelines:
> https://github.com/dlang/DIPs/blob/master/docs/guidelines-reviewers.md
> *Please stay on topic!*
> Thanks in advance to all who participate.
> #DIP1029
> #throw

The idea is great, inverse attributes are very powerful in 
practice and are definitely very good in usability for a lot of 
code for example applying attributes to the entire D source file.

I don't think making the attribute "throw" is the best way to go 
though. Currently most attributes use the at-attribute syntax 
which makes them very unambiguous and easier to (visually) parse. 
I would suggest instead of having throw as attribute, the new 
attribute should be @throws instead. `throws` can also be argued 
for that it is "better" to read like: "function foo throws" than 
"function foo throw"

Additionally if we make this an at-attribute, it can very easily 
be extended in the future to have arguments what kind of 
exceptions are being thrown by this function, for example using 
template argument syntax to be the easiest and most consistent to 
parse. This also exists in other languages like Java and helps 
both with linting for try-catch, but also extremely helps with 

For symmetry with nothrow it might be worth looking into 
providing nothrow as @nothrow attribute instead too.

More information about the Digitalmars-d mailing list