DIP 1029---Add throw as Function Attribute---Community Review Round 1
james.blachly at gmail.com
Thu Jan 16 02:27:22 UTC 2020
On 1/14/20 3:28 PM, Walter Bright wrote:
> On 1/14/2020 3:21 AM, WebFreak001 wrote:
>> 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"
> It's already a keyword so there's no problem with having it be 'throw'.
> Having 'throw', 'nothrow' and 'throws' as keywords looks excessive.
>> 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 documentation.
>> For symmetry with nothrow it might be worth looking into providing
>> nothrow as @nothrow attribute instead too.
> The @ syntax for this is simply unnecessary.
To back up WebFreak001's assertions: the seemingly random keyword
versus @attribute decorators for functions are very jarring and
disconcerting for new and even intermediate users.
This is a perfect opportunity to harmonize things that, for very little
downside, improve the apparent coherence of the language.
"throws" also sounds far more grammatical than "throw"
More information about the Digitalmars-d