The point of const, scope, and other attributes

Dukc ajieskola at gmail.com
Wed May 11 07:21:02 UTC 2022


On Wednesday, 11 May 2022 at 05:02:31 UTC, Walter Bright wrote:
> [snip]

I am increasingly of the opinion that DIP1000 is too complicated 
for the average programmer to understand well. I find myself 
often stratching my head with it, it would be overwhelming for a 
beginner.

Still, I do not advocate going back to pre-DIP1000 semantics 
because those are simply unsafe when it comes to slicing static 
arrays. I think we should start teaching two rules:

1: Never, ever brute force your way through DIP1000 errors with 
`@trusted` because you do not understand `return`, `scope` and 
`ref`.
2: If you're having trouble, GC-allocate the variables you're 
trying to use.

The nice thing about DIP1000 is that one can't accidently 
introduce bugs as long as s/he follows rule 1.

Regarding other attributes, I think it's good that our 
const/immutable/shared are transitive. Otherwise the attribute 
soup problem we have would be even worse.


More information about the Digitalmars-d mailing list