working with attributes

Walter Bright newshound2 at digitalmars.com
Thu Jan 11 22:41:30 UTC 2024


This is a reasonable argument. I've often suggested that people just write code 
and don't use attributes. The code will still work just fine.

Where attributes make sense is when you want a rigorous check on something. For 
example, to share a data structure among threads, making it `immutable` will 
ensure that no synchronization is necessary.

The beauty of pure functions is you can reason about them, knowing that there is 
no "side loading" hanky panky going on. It can be verified by the compiler. This 
is highly useful for doing parallel execution of things.

`scope` is handy for verifing the lifetime of a pointer, which is essential if 
you need to pinch off all memory leaks.

Another way to deal with attributes is to use templates, as the compiler will 
infer attributes for template functions.

Any piece of code that accepts lambdas, callbacks, etc., should be very clear 
about attribute use and how that will apply to the lambdas, etc.


More information about the Digitalmars-d mailing list