`const ref T` or `ref const T`?
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Thu Aug 15 10:34:49 UTC 2024
On 15/08/2024 9:05 PM, IchorDev wrote:
> Yeah, I feel you. When I first started writing in D I’d also use `const
> ref`, but I agree that interleaving the storage class and the type is
> not right. I’m not alone in having started with `const ref`, and then
> having moved to using `ref const` as I understood the language better.
> I think part of the reason some gravitate to `const ref` because of
> ignorance when coming from C++, but I never used C++ because I was aware
> of its reputation. Instead, I found the ordering to violate English
> adjective ordering. `ref const T` sounds wrong in the same way as ‘red
> big balloon’. In English you can have a ‘constant reference integer’ but
> not a ‘reference constant integer’; it sounds like an imperative
> instruction.
+1
Perhaps not an error in practice, but a warning is certainly warranted
as it shows a lack of understanding in the language.
More information about the Digitalmars-d
mailing list